Skip to content

Commit e638eae

Browse files
authored
fix(ConnectWalletForm): connect with fetched wallet info only (#1088)
1 parent c7d2a6e commit e638eae

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/background/services/wallet.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
getWalletInformation,
32
isErrorWithKey,
43
ErrorWithKey,
54
errorWithKeyToJSON,
@@ -74,15 +73,9 @@ export class WalletService {
7473
}
7574

7675
async connectWallet(params: ConnectWalletPayload) {
77-
const {
78-
walletAddressUrl,
79-
amount,
80-
recurring,
81-
autoKeyAdd,
82-
autoKeyAddConsent,
83-
} = params;
76+
const { walletAddress, amount, recurring, autoKeyAdd, autoKeyAddConsent } =
77+
params;
8478

85-
const walletAddress = await getWalletInformation(walletAddressUrl);
8679
const exchangeRates = await getExchangeRates();
8780

8881
let rateOfPay = DEFAULT_RATE_OF_PAY;

src/pages/popup/components/ConnectWalletForm.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import {
2020
toWalletAddressUrl,
2121
type ErrorWithKeyLike,
2222
} from '@/shared/helpers';
23-
import type { WalletAddress } from '@interledger/open-payments';
2423
import type { ConnectWalletPayload, Response } from '@/shared/messages';
25-
import type { DeepReadonly, PopupTransientState } from '@/shared/types';
24+
import type {
25+
DeepReadonly,
26+
PopupTransientState,
27+
WalletInfo,
28+
} from '@/shared/types';
2629

2730
interface Inputs {
2831
walletAddressUrl: string;
@@ -46,7 +49,7 @@ interface ConnectWalletFormProps {
4649
state?: ConnectTransientState;
4750
walletAddressPlaceholder?: string;
4851
saveValue?: (key: keyof Inputs, val: Inputs[typeof key]) => void;
49-
getWalletInfo: (walletAddressUrl: string) => Promise<WalletAddress>;
52+
getWalletInfo: (walletAddressUrl: string) => Promise<WalletInfo>;
5053
connectWallet: (data: ConnectWalletPayload) => Promise<Response>;
5154
clearConnectState: () => Promise<unknown>;
5255
onConnect?: () => void;
@@ -102,7 +105,7 @@ export const ConnectWalletForm = ({
102105
);
103106

104107
const [walletAddressInfo, setWalletAddressInfo] =
105-
React.useState<WalletAddress | null>(null);
108+
React.useState<WalletInfo | null>(null);
106109

107110
const [errors, setErrors] = React.useState<Errors>({
108111
walletAddressUrl: null,
@@ -244,7 +247,9 @@ export const ConnectWalletForm = ({
244247
}
245248
setErrors((prev) => ({ ...prev, keyPair: null, connect: null }));
246249
const res = await connectWallet({
247-
walletAddressUrl: toWalletAddressUrl(walletAddress),
250+
walletAddress:
251+
walletAddressInfo ??
252+
(await getWalletInfo(toWalletAddressUrl(walletAddress))),
248253
amount,
249254
recurring,
250255
autoKeyAdd: !skipAutoKeyShare,

src/shared/messages.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import type {
33
OutgoingPayment,
44
} from '@interledger/open-payments';
55
import type { Browser } from 'webextension-polyfill';
6-
import type { AmountValue, PopupTransientState, Storage } from '@/shared/types';
6+
import type {
7+
AmountValue,
8+
PopupTransientState,
9+
Storage,
10+
WalletInfo,
11+
} from '@/shared/types';
712
import type { ErrorWithKeyLike } from '@/shared/helpers';
813
import type { PopupState } from '@/popup/lib/store';
914
import type { AppState } from '@/app/lib/store';
@@ -91,7 +96,7 @@ export class MessageManager<TMessages extends MessageMap> {
9196

9297
// #region Popup ↦ BG
9398
export interface ConnectWalletPayload {
94-
walletAddressUrl: string;
99+
walletAddress: WalletInfo;
95100
amount: string;
96101
recurring: boolean;
97102
autoKeyAdd: boolean;
@@ -121,7 +126,7 @@ export interface UpdateRateOfPayPayload {
121126
}
122127

123128
export interface UpdateBudgetPayload {
124-
walletAddressUrl: ConnectWalletPayload['walletAddressUrl'];
129+
walletAddressUrl: string;
125130
amount: ConnectWalletPayload['amount'];
126131
recurring: ConnectWalletPayload['recurring'];
127132
}

0 commit comments

Comments
 (0)