diff --git a/src/background/config.ts b/src/background/config.ts index 9cdc9b407..9940b4ff8 100644 --- a/src/background/config.ts +++ b/src/background/config.ts @@ -2,7 +2,6 @@ export const DEFAULT_SCALE = 2; export const DEFAULT_INTERVAL_MS = 3_600_000; export const DEFAULT_RATE_OF_PAY = '60'; -export const MIN_RATE_OF_PAY = '1'; export const MAX_RATE_OF_PAY = '100'; /** Minimum wait time between two consecutive continuous payments */ diff --git a/src/background/services/monetization.ts b/src/background/services/monetization.ts index 89091e0a9..d49f4a7ac 100644 --- a/src/background/services/monetization.ts +++ b/src/background/services/monetization.ts @@ -418,7 +418,6 @@ export class MonetizationService { 'connected', 'state', 'rateOfPay', - 'minRateOfPay', 'maxRateOfPay', 'walletAddress', 'oneTimeGrant', diff --git a/src/background/services/storage.ts b/src/background/services/storage.ts index 749d9b72e..d7e14dfe5 100644 --- a/src/background/services/storage.ts +++ b/src/background/services/storage.ts @@ -19,7 +19,7 @@ const defaultStorage = { * structural changes would need migrations for keeping compatibility with * existing installations. */ - version: 4, + version: 5, state: {}, connected: false, enabled: true, @@ -31,7 +31,6 @@ const defaultStorage = { oneTimeGrant: null, oneTimeGrantSpentAmount: '0', rateOfPay: null, - minRateOfPay: null, maxRateOfPay: null, } satisfies Omit; @@ -287,4 +286,10 @@ const MIGRATIONS: Record = { data.enabled = true; return [data]; }, + 5: (data) => { + if (data.walletAddress && !data.walletAddress.url) { + data.walletAddress.url = data.walletAddress.id; + } + return [data, ['minRateOfPay']]; + }, }; diff --git a/src/background/services/wallet.ts b/src/background/services/wallet.ts index 8c3f53afe..40b5ba2e2 100644 --- a/src/background/services/wallet.ts +++ b/src/background/services/wallet.ts @@ -14,7 +14,6 @@ import type { } from '@/shared/messages'; import { DEFAULT_RATE_OF_PAY, - MIN_RATE_OF_PAY, MAX_RATE_OF_PAY, DEFAULT_SCALE, } from '@/background/config'; @@ -87,7 +86,6 @@ export class WalletService { const exchangeRates = await getExchangeRates(); let rateOfPay = DEFAULT_RATE_OF_PAY; - let minRateOfPay = MIN_RATE_OF_PAY; let maxRateOfPay = MAX_RATE_OF_PAY; const getRateOfPay = (rate: AmountValue) => { @@ -95,7 +93,6 @@ export class WalletService { return convertWithExchangeRate(rate, from, walletAddress, exchangeRates); }; rateOfPay = getRateOfPay(DEFAULT_RATE_OF_PAY); - minRateOfPay = getRateOfPay(MIN_RATE_OF_PAY); maxRateOfPay = getRateOfPay(MAX_RATE_OF_PAY); await this.openPaymentsService.initClient(walletAddress.id); @@ -203,9 +200,8 @@ export class WalletService { } await this.storage.set({ - walletAddress: { url: walletAddressUrl, ...walletAddress }, + walletAddress, rateOfPay, - minRateOfPay, maxRateOfPay, connected: true, }); diff --git a/src/pages/popup/components/Settings/RateOfPay.tsx b/src/pages/popup/components/Settings/RateOfPay.tsx index 629cc0670..93bb1186f 100644 --- a/src/pages/popup/components/Settings/RateOfPay.tsx +++ b/src/pages/popup/components/Settings/RateOfPay.tsx @@ -44,19 +44,13 @@ interface Props { } export const RateOfPayComponent = ({ onRateChange, toggle }: Props) => { - const { - continuousPaymentsEnabled, - rateOfPay, - minRateOfPay, - maxRateOfPay, - walletAddress, - } = usePopupState(); + const { continuousPaymentsEnabled, rateOfPay, maxRateOfPay, walletAddress } = + usePopupState(); return (
{ @@ -127,7 +119,7 @@ const RateOfPayInput = ({ }} onError={(error) => setErrorMessage(t(error))} errorMessage={errorMessage} - min={Number(formatAmount(minRateOfPay))} + min={1} max={Number(formatAmount(maxRateOfPay))} amount={formatAmount(rateOfPay)} controls={true} diff --git a/src/shared/helpers/wallet.ts b/src/shared/helpers/wallet.ts index 713f28375..541a9e13e 100644 --- a/src/shared/helpers/wallet.ts +++ b/src/shared/helpers/wallet.ts @@ -1,4 +1,5 @@ import type { WalletAddress, JWKS } from '@interledger/open-payments'; +import type { WalletInfo } from '@/shared/types'; import { ensureEnd } from './misc'; export function toWalletAddressUrl(s: string): string { @@ -22,7 +23,7 @@ const isWalletAddress = (o: Record): o is WalletAddress => { export const getWalletInformation = async ( walletAddressUrl: string, -): Promise => { +): Promise => { const response = await fetch(walletAddressUrl, { headers: { Accept: 'application/json', @@ -43,7 +44,7 @@ export const getWalletInformation = async ( throw new Error(msgInvalidWalletAddress); } - return json; + return { ...json, url: walletAddressUrl }; }; export const getJWKS = async (walletAddressUrl: string) => { diff --git a/src/shared/types.ts b/src/shared/types.ts index 795542f53..a3b540a3c 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -45,9 +45,10 @@ export interface WalletInfo extends WalletAddress { * The (normalized) wallet URL provided by user. Sometimes, wallets URLs have * redirects, and in those cases, we want to preserve what user has provided. * - * @since Available only if wallet connected after this feature was released. + * For wallets that were connected before this property was introduced, this + * will be same as {@linkcode WalletAddress.id}. */ - url?: string; + url: string; } export type ExtensionState = @@ -76,7 +77,6 @@ export interface Storage { state: Partial>; rateOfPay?: AmountValue | undefined | null; - minRateOfPay?: AmountValue | undefined | null; maxRateOfPay?: AmountValue | undefined | null; /** User wallet address information */