feat!: overhaul continuous payments logic#1066
Merged
Merged
Conversation
Contributor
Extension builds preview
|
4ee1d6a to
8941964
Compare
27c0b0e to
b19d17d
Compare
b19d17d to
0d6624d
Compare
sidvishnoi
commented
Jun 9, 2025
This was referenced Jun 9, 2025
DarianM
approved these changes
Jun 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Closes #976
Changes proposed in this pull request
Overview
Major change: This affects our handling of continuous payments when there are more than 1 monetization link tags on page.
PaymentSessions in a staggered manner while making continuous payments.MonetizationEventis fired more often than earlier, giving more continuous payments feel.PaymentSession.minSendAmount, making payments fairer to sender and ASEs (no rounding loss/gains due to currency conversion).MIN_PAYMENT_WAITof 2s, to reduce load of OP servers.Changes
PaymentManager(per tab).PaymentSession.start(),PaymentSession.stop()etc. anymorePaymentManager.pendingAmountwhich increments as per units-duration defined by user's rate of pay.pendingAmountreaches next payable session'sminSendAmount(or higher), pay appropriate amount to that session and subtract paid amount frompendingAmount, and move onto next payable session.pendingAmountis like a bucket, and there's a FIFO queue of sessions waiting to empty it as per their needs.PaymentSession.pay(amount)toPaymentSession.payOneTime(amount)for clarity.PaymentSession.payContinuous()public (and renamed to.pay(amount), and added a helper (payWithRetry(amount)) that retries this payment on certain errors.Follow-up
Payment streams looping flow and demo
In this demo, there are 2 iframes. Each frame (including main site) has 2 link tags in same order: MXN and then ZAR.
Most importantly, payment rate is now respected! As an example, our rate of pay says 1c every 2s.
Earlier: when we had 6 link tags, we’d emit 6 monetization events on page load. Spending 6c on page load. Then we’d wait 12s for next payment, and pay 6c again.
Now: We’d emit one monetization event every 2s!
Of course, this is the case when sending wallet and receiving wallet have 1c = 1c exchange rate. When sending from MXN to USD, even though sender’s rate is 0.01MXN every 2s, USD wallet cannot receive an amount this small. It needs at least 0.20MXN to receive 0.01USD. So, we’ll wait 40s (such that amount is now 0.20MXN) for the next payment!
Video: https://drive.google.com/file/d/1LtcdAJmMnYuT6wCNCFLp4aGkJY9U5g9j/view?usp=sharing