Skip to content

Commit 826cbb8

Browse files
authored
fix: remove minRateOfPay, make WalletInfo.url required (#1085)
1 parent a911b66 commit 826cbb8

7 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/background/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export const DEFAULT_SCALE = 2;
22
export const DEFAULT_INTERVAL_MS = 3_600_000;
33

44
export const DEFAULT_RATE_OF_PAY = '60';
5-
export const MIN_RATE_OF_PAY = '1';
65
export const MAX_RATE_OF_PAY = '100';
76

87
/** Minimum wait time between two consecutive continuous payments */

src/background/services/monetization.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ export class MonetizationService {
418418
'connected',
419419
'state',
420420
'rateOfPay',
421-
'minRateOfPay',
422421
'maxRateOfPay',
423422
'walletAddress',
424423
'oneTimeGrant',

src/background/services/storage.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const defaultStorage = {
1919
* structural changes would need migrations for keeping compatibility with
2020
* existing installations.
2121
*/
22-
version: 4,
22+
version: 5,
2323
state: {},
2424
connected: false,
2525
enabled: true,
@@ -31,7 +31,6 @@ const defaultStorage = {
3131
oneTimeGrant: null,
3232
oneTimeGrantSpentAmount: '0',
3333
rateOfPay: null,
34-
minRateOfPay: null,
3534
maxRateOfPay: null,
3635
} satisfies Omit<Storage, 'publicKey' | 'privateKey' | 'keyId'>;
3736

@@ -287,4 +286,10 @@ const MIGRATIONS: Record<Storage['version'], Migration> = {
287286
data.enabled = true;
288287
return [data];
289288
},
289+
5: (data) => {
290+
if (data.walletAddress && !data.walletAddress.url) {
291+
data.walletAddress.url = data.walletAddress.id;
292+
}
293+
return [data, ['minRateOfPay']];
294+
},
290295
};

src/background/services/wallet.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
} from '@/shared/messages';
1515
import {
1616
DEFAULT_RATE_OF_PAY,
17-
MIN_RATE_OF_PAY,
1817
MAX_RATE_OF_PAY,
1918
DEFAULT_SCALE,
2019
} from '@/background/config';
@@ -87,15 +86,13 @@ export class WalletService {
8786
const exchangeRates = await getExchangeRates();
8887

8988
let rateOfPay = DEFAULT_RATE_OF_PAY;
90-
let minRateOfPay = MIN_RATE_OF_PAY;
9189
let maxRateOfPay = MAX_RATE_OF_PAY;
9290

9391
const getRateOfPay = (rate: AmountValue) => {
9492
const from = { assetCode: 'USD', assetScale: DEFAULT_SCALE };
9593
return convertWithExchangeRate(rate, from, walletAddress, exchangeRates);
9694
};
9795
rateOfPay = getRateOfPay(DEFAULT_RATE_OF_PAY);
98-
minRateOfPay = getRateOfPay(MIN_RATE_OF_PAY);
9996
maxRateOfPay = getRateOfPay(MAX_RATE_OF_PAY);
10097

10198
await this.openPaymentsService.initClient(walletAddress.id);
@@ -203,9 +200,8 @@ export class WalletService {
203200
}
204201

205202
await this.storage.set({
206-
walletAddress: { url: walletAddressUrl, ...walletAddress },
203+
walletAddress,
207204
rateOfPay,
208-
minRateOfPay,
209205
maxRateOfPay,
210206
connected: true,
211207
});

src/pages/popup/components/Settings/RateOfPay.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,13 @@ interface Props {
4444
}
4545

4646
export const RateOfPayComponent = ({ onRateChange, toggle }: Props) => {
47-
const {
48-
continuousPaymentsEnabled,
49-
rateOfPay,
50-
minRateOfPay,
51-
maxRateOfPay,
52-
walletAddress,
53-
} = usePopupState();
47+
const { continuousPaymentsEnabled, rateOfPay, maxRateOfPay, walletAddress } =
48+
usePopupState();
5449
return (
5550
<div className="space-y-8">
5651
<RateOfPayInput
5752
onRateChange={onRateChange}
5853
rateOfPay={rateOfPay}
59-
minRateOfPay={minRateOfPay}
6054
maxRateOfPay={maxRateOfPay}
6155
walletAddress={walletAddress}
6256
disabled={!continuousPaymentsEnabled}
@@ -87,7 +81,6 @@ type RateOfPayInputProps = {
8781
onRateChange: Props['onRateChange'];
8882
walletAddress: PopupState['walletAddress'];
8983
rateOfPay: PopupState['rateOfPay'];
90-
minRateOfPay: PopupState['minRateOfPay'];
9184
maxRateOfPay: PopupState['maxRateOfPay'];
9285
disabled?: boolean;
9386
};
@@ -96,7 +89,6 @@ const RateOfPayInput = ({
9689
onRateChange,
9790
walletAddress,
9891
rateOfPay,
99-
minRateOfPay,
10092
maxRateOfPay,
10193
disabled,
10294
}: RateOfPayInputProps) => {
@@ -127,7 +119,7 @@ const RateOfPayInput = ({
127119
}}
128120
onError={(error) => setErrorMessage(t(error))}
129121
errorMessage={errorMessage}
130-
min={Number(formatAmount(minRateOfPay))}
122+
min={1}
131123
max={Number(formatAmount(maxRateOfPay))}
132124
amount={formatAmount(rateOfPay)}
133125
controls={true}

src/shared/helpers/wallet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { WalletAddress, JWKS } from '@interledger/open-payments';
2+
import type { WalletInfo } from '@/shared/types';
23
import { ensureEnd } from './misc';
34

45
export function toWalletAddressUrl(s: string): string {
@@ -22,7 +23,7 @@ const isWalletAddress = (o: Record<string, unknown>): o is WalletAddress => {
2223

2324
export const getWalletInformation = async (
2425
walletAddressUrl: string,
25-
): Promise<WalletAddress> => {
26+
): Promise<WalletInfo> => {
2627
const response = await fetch(walletAddressUrl, {
2728
headers: {
2829
Accept: 'application/json',
@@ -43,7 +44,7 @@ export const getWalletInformation = async (
4344
throw new Error(msgInvalidWalletAddress);
4445
}
4546

46-
return json;
47+
return { ...json, url: walletAddressUrl };
4748
};
4849

4950
export const getJWKS = async (walletAddressUrl: string) => {

src/shared/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export interface WalletInfo extends WalletAddress {
4545
* The (normalized) wallet URL provided by user. Sometimes, wallets URLs have
4646
* redirects, and in those cases, we want to preserve what user has provided.
4747
*
48-
* @since Available only if wallet connected after this feature was released.
48+
* For wallets that were connected before this property was introduced, this
49+
* will be same as {@linkcode WalletAddress.id}.
4950
*/
50-
url?: string;
51+
url: string;
5152
}
5253

5354
export type ExtensionState =
@@ -76,7 +77,6 @@ export interface Storage {
7677
state: Partial<Record<ExtensionState, boolean>>;
7778

7879
rateOfPay?: AmountValue | undefined | null;
79-
minRateOfPay?: AmountValue | undefined | null;
8080
maxRateOfPay?: AmountValue | undefined | null;
8181

8282
/** User wallet address information */

0 commit comments

Comments
 (0)