Skip to content

Commit cbff92d

Browse files
committed
Updates based on PR review and reword messaging for amount minimum
1 parent d49e7bc commit cbff92d

6 files changed

Lines changed: 18 additions & 24 deletions

File tree

src/_locales/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"message": "Please enter a valid number for the amount."
170170
},
171171
"connectWallet_error_amountMinimum": {
172-
"message": "An amount greater than $AMOUNT$ is required.",
172+
"message": "An amount at least $AMOUNT$ is required.",
173173
"placeholders": {
174174
"AMOUNT": { "content": "$1", "example": "$2.05" }
175175
}

src/background/services/monetization.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,22 +434,19 @@ 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-
}
437+
const minSendAmount = tab.id
438+
? (this.tabState.paymentManagers.get(tab.id)?.minSendAmount?.toString() ??
439+
'0')
440+
: '0';
446441

447442
return {
448443
...dataFromStorage,
449444
balance: balance.total.toString(),
450-
tab: this.tabState.getPopupTabData(tab),
445+
tab: {
446+
...this.tabState.getPopupTabData(tab),
447+
minSendAmount,
448+
},
451449
transientState: this.storage.getPopupTransientState(),
452-
minSendAmount,
453450
grants: {
454451
oneTime: oneTimeGrant?.amount,
455452
recurring: recurringGrant?.amount,

src/background/services/paymentManager.ts

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

153-
// bugfix #1071
154153
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?
159154
return this.payableSessions.reduce(
160-
(max, session) => session.minSendAmount > max ? session.minSendAmount : max,
161-
0n
155+
(highestMin, session) =>
156+
session.minSendAmount > highestMin ? session.minSendAmount : highestMin,
157+
0n,
162158
);
163159
}
164160

src/background/services/tabState.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export class TabState {
122122
status = 'monetized';
123123
}
124124

125-
return { tabId: tab.id, url, status };
125+
const minSendAmount = '0';
126+
127+
return { tabId: tab.id, url, status, minSendAmount };
126128
}
127129

128130
getIcon(tabId: TabId) {

src/pages/popup/components/PayWebsiteForm.tsx

Lines changed: 2 additions & 3 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, minSendAmount } = usePopupState();
17+
const { walletAddress, tab } = usePopupState();
1818

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

src/shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export type PopupTabInfo = {
119119
*/
120120
| 'all_sessions_invalid'
121121
| never; // just added for code formatting
122+
minSendAmount: string;
122123
};
123124

124125
export type PopupTransientState = Partial<{
@@ -140,7 +141,6 @@ export type PopupStore = Omit<
140141
balance: AmountValue;
141142
tab: PopupTabInfo;
142143
transientState: PopupTransientState;
143-
minSendAmount: string; // # 1071
144144
grants?: Partial<{
145145
oneTime: OneTimeGrant['amount'];
146146
recurring: RecurringGrant['amount'];

0 commit comments

Comments
 (0)