Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/background/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 0 additions & 1 deletion src/background/services/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ export class MonetizationService {
'connected',
'state',
'rateOfPay',
'minRateOfPay',
'maxRateOfPay',
'walletAddress',
'oneTimeGrant',
Expand Down
9 changes: 7 additions & 2 deletions src/background/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,7 +31,6 @@ const defaultStorage = {
oneTimeGrant: null,
oneTimeGrantSpentAmount: '0',
rateOfPay: null,
minRateOfPay: null,
maxRateOfPay: null,
} satisfies Omit<Storage, 'publicKey' | 'privateKey' | 'keyId'>;

Expand Down Expand Up @@ -287,4 +286,10 @@ const MIGRATIONS: Record<Storage['version'], Migration> = {
data.enabled = true;
return [data];
},
5: (data) => {
if (data.walletAddress && !data.walletAddress.url) {
data.walletAddress.url = data.walletAddress.id;
}
return [data, ['minRateOfPay']];
},
};
6 changes: 1 addition & 5 deletions src/background/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -87,15 +86,13 @@ 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) => {
const from = { assetCode: 'USD', assetScale: DEFAULT_SCALE };
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);
Expand Down Expand Up @@ -203,9 +200,8 @@ export class WalletService {
}

await this.storage.set({
walletAddress: { url: walletAddressUrl, ...walletAddress },
walletAddress,
rateOfPay,
minRateOfPay,
maxRateOfPay,
connected: true,
});
Expand Down
14 changes: 3 additions & 11 deletions src/pages/popup/components/Settings/RateOfPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="space-y-8">
<RateOfPayInput
onRateChange={onRateChange}
rateOfPay={rateOfPay}
minRateOfPay={minRateOfPay}
maxRateOfPay={maxRateOfPay}
walletAddress={walletAddress}
disabled={!continuousPaymentsEnabled}
Expand Down Expand Up @@ -87,7 +81,6 @@ type RateOfPayInputProps = {
onRateChange: Props['onRateChange'];
walletAddress: PopupState['walletAddress'];
rateOfPay: PopupState['rateOfPay'];
minRateOfPay: PopupState['minRateOfPay'];
maxRateOfPay: PopupState['maxRateOfPay'];
disabled?: boolean;
};
Expand All @@ -96,7 +89,6 @@ const RateOfPayInput = ({
onRateChange,
walletAddress,
rateOfPay,
minRateOfPay,
maxRateOfPay,
disabled,
}: RateOfPayInputProps) => {
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 3 additions & 2 deletions src/shared/helpers/wallet.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -22,7 +23,7 @@ const isWalletAddress = (o: Record<string, unknown>): o is WalletAddress => {

export const getWalletInformation = async (
walletAddressUrl: string,
): Promise<WalletAddress> => {
): Promise<WalletInfo> => {
const response = await fetch(walletAddressUrl, {
headers: {
Accept: 'application/json',
Expand All @@ -43,7 +44,7 @@ export const getWalletInformation = async (
throw new Error(msgInvalidWalletAddress);
}

return json;
return { ...json, url: walletAddressUrl };
};

export const getJWKS = async (walletAddressUrl: string) => {
Expand Down
6 changes: 3 additions & 3 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -76,7 +77,6 @@ export interface Storage {
state: Partial<Record<ExtensionState, boolean>>;

rateOfPay?: AmountValue | undefined | null;
minRateOfPay?: AmountValue | undefined | null;
maxRateOfPay?: AmountValue | undefined | null;

/** User wallet address information */
Expand Down