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
11 changes: 2 additions & 9 deletions src/background/services/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
getWalletInformation,
isErrorWithKey,
ErrorWithKey,
errorWithKeyToJSON,
Expand Down Expand Up @@ -74,15 +73,9 @@ export class WalletService {
}

async connectWallet(params: ConnectWalletPayload) {
const {
walletAddressUrl,
amount,
recurring,
autoKeyAdd,
autoKeyAddConsent,
} = params;
const { walletAddress, amount, recurring, autoKeyAdd, autoKeyAddConsent } =
params;

const walletAddress = await getWalletInformation(walletAddressUrl);
const exchangeRates = await getExchangeRates();

let rateOfPay = DEFAULT_RATE_OF_PAY;
Expand Down
15 changes: 10 additions & 5 deletions src/pages/popup/components/ConnectWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import {
toWalletAddressUrl,
type ErrorWithKeyLike,
} from '@/shared/helpers';
import type { WalletAddress } from '@interledger/open-payments';
import type { ConnectWalletPayload, Response } from '@/shared/messages';
import type { DeepReadonly, PopupTransientState } from '@/shared/types';
import type {
DeepReadonly,
PopupTransientState,
WalletInfo,
} from '@/shared/types';

interface Inputs {
walletAddressUrl: string;
Expand All @@ -46,7 +49,7 @@ interface ConnectWalletFormProps {
state?: ConnectTransientState;
walletAddressPlaceholder?: string;
saveValue?: (key: keyof Inputs, val: Inputs[typeof key]) => void;
getWalletInfo: (walletAddressUrl: string) => Promise<WalletAddress>;
getWalletInfo: (walletAddressUrl: string) => Promise<WalletInfo>;
connectWallet: (data: ConnectWalletPayload) => Promise<Response>;
clearConnectState: () => Promise<unknown>;
onConnect?: () => void;
Expand Down Expand Up @@ -102,7 +105,7 @@ export const ConnectWalletForm = ({
);

const [walletAddressInfo, setWalletAddressInfo] =
React.useState<WalletAddress | null>(null);
React.useState<WalletInfo | null>(null);

const [errors, setErrors] = React.useState<Errors>({
walletAddressUrl: null,
Expand Down Expand Up @@ -244,7 +247,9 @@ export const ConnectWalletForm = ({
}
setErrors((prev) => ({ ...prev, keyPair: null, connect: null }));
const res = await connectWallet({
walletAddressUrl: toWalletAddressUrl(walletAddress),
walletAddress:
walletAddressInfo ??
(await getWalletInfo(toWalletAddressUrl(walletAddress))),
Comment on lines +251 to +252

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walletAddressInfo should not be null here, but if it is, then we fetch it.
#957 should help avoid problems like this.

amount,
recurring,
autoKeyAdd: !skipAutoKeyShare,
Expand Down
11 changes: 8 additions & 3 deletions src/shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import type {
OutgoingPayment,
} from '@interledger/open-payments';
import type { Browser } from 'webextension-polyfill';
import type { AmountValue, PopupTransientState, Storage } from '@/shared/types';
import type {
AmountValue,
PopupTransientState,
Storage,
WalletInfo,
} from '@/shared/types';
import type { ErrorWithKeyLike } from '@/shared/helpers';
import type { PopupState } from '@/popup/lib/store';
import type { AppState } from '@/app/lib/store';
Expand Down Expand Up @@ -91,7 +96,7 @@ export class MessageManager<TMessages extends MessageMap> {

// #region Popup ↦ BG
export interface ConnectWalletPayload {
walletAddressUrl: string;
walletAddress: WalletInfo;
amount: string;
recurring: boolean;
autoKeyAdd: boolean;
Expand Down Expand Up @@ -121,7 +126,7 @@ export interface UpdateRateOfPayPayload {
}

export interface UpdateBudgetPayload {
walletAddressUrl: ConnectWalletPayload['walletAddressUrl'];
walletAddressUrl: string;
amount: ConnectWalletPayload['amount'];
recurring: ConnectWalletPayload['recurring'];
}
Expand Down