Skip to content

Commit fe341f8

Browse files
committed
Inital fix for showing min send amount based on currency
1 parent f878af1 commit fe341f8

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/background/services/monetization.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,22 @@ export class MonetizationService {
434434

435435
const { oneTimeGrant, recurringGrant, ...dataFromStorage } = storedData;
436436

437+
// #1071
438+
let minSendAmount = '0';
439+
if (tab.id) {
440+
// If we have a payment manager for this tab, get the min send amount
441+
const paymentManager = this.tabState.paymentManagers.get(tab.id);
442+
if (paymentManager) {
443+
minSendAmount = paymentManager.minSendAmount.toString();
444+
}
445+
}
446+
437447
return {
438448
...dataFromStorage,
439449
balance: balance.total.toString(),
440450
tab: this.tabState.getPopupTabData(tab),
441451
transientState: this.storage.getPopupTransientState(),
452+
minSendAmount,
442453
grants: {
443454
oneTime: oneTimeGrant?.amount,
444455
recurring: recurringGrant?.amount,

src/background/services/paymentManager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ export class PaymentManager {
150150
return this.sessions.filter((s) => s.isUsable);
151151
}
152152

153+
// bugfix #1071
154+
get minSendAmount(): bigint {
155+
// Check to see if there are any payable sessions
156+
if (!this.payableSessions.length) return 0n;
157+
158+
// NOTE: How is a payable session defined, i.e. are could the minSendAmount be different currencies?
159+
return this.payableSessions.reduce(
160+
(max, session) => session.minSendAmount > max ? session.minSendAmount : max,
161+
0n
162+
);
163+
}
164+
153165
private createStreamIfNotExists(frameId: FrameId) {
154166
let stream = this.streams.get(frameId);
155167
if (!stream) {

src/pages/popup/components/PayWebsiteForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Errors = Record<ErrorsParams, ErrorInfo | null>;
1414
export const PayWebsiteForm = () => {
1515
const t = useTranslation();
1616
const message = useMessage();
17-
const { walletAddress, tab } = usePopupState();
17+
const { walletAddress, tab, minSendAmount } = usePopupState();
1818

1919
const toErrorInfo = React.useCallback(
2020
(err?: string | ErrorWithKeyLike | null): ErrorInfo | null => {
@@ -100,8 +100,9 @@ export const PayWebsiteForm = () => {
100100
walletAddress={walletAddress}
101101
amount={amount}
102102
placeholder="0.00"
103+
// #1071
103104
min={roundWithPrecision(
104-
2 / 10 ** walletAddress.assetScale,
105+
Number(minSendAmount) / 10 ** walletAddress.assetScale,
105106
walletAddress.assetScale,
106107
)}
107108
errorMessage={errors.amount?.message}

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export type PopupStore = Omit<
140140
balance: AmountValue;
141141
tab: PopupTabInfo;
142142
transientState: PopupTransientState;
143+
minSendAmount: string; // # 1071
143144
grants?: Partial<{
144145
oneTime: OneTimeGrant['amount'];
145146
recurring: RecurringGrant['amount'];

0 commit comments

Comments
 (0)