Skip to content

Commit f5bfefe

Browse files
feat(extension): prepopulate banxa form fields with coinType and walletAddress [LW-12629] (#1888)
1 parent 963e9ea commit f5bfefe

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

apps/browser-extension-wallet/src/views/browser-view/components/TopUpWallet/TopUpWalletButton.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { AdaComponentTransparent, Button } from '@input-output-hk/lace-ui-toolki
22
import React, { useRef, useState } from 'react';
33
import { TopUpWalletDialog } from './TopUpWalletDialog';
44
import { useTranslation } from 'react-i18next';
5-
import { BANXA_LACE_URL } from './config';
65
import { useAnalyticsContext, useExternalLinkOpener } from '@providers';
76
import { PostHogAction } from '@lace/common';
87
import { useCurrentBlockchain } from '@src/multichain';
98
import SvgBtcComponentTransparent from './SvgBtcComponentTransparent';
9+
import { getBanxaUrl } from './utils';
10+
import { useWalletStore } from '@src/stores';
1011

1112
export const TopUpWalletButton = (): React.ReactElement => {
1213
const dialogTriggerReference = useRef<HTMLButtonElement>(null);
@@ -15,6 +16,8 @@ export const TopUpWalletButton = (): React.ReactElement => {
1516
const analytics = useAnalyticsContext();
1617
const openExternalLink = useExternalLinkOpener();
1718
const { blockchain } = useCurrentBlockchain();
19+
const { walletInfo } = useWalletStore();
20+
const walletAddress = walletInfo ? walletInfo.addresses[0].address.toString() : '';
1821
const isBitcoin = blockchain === 'bitcoin';
1922

2023
return (
@@ -43,7 +46,7 @@ export const TopUpWalletButton = (): React.ReactElement => {
4346
triggerRef={dialogTriggerReference}
4447
onConfirm={() => {
4548
analytics.sendEventToPostHog(PostHogAction.TokenBuyAdaDisclaimerContinueClick);
46-
openExternalLink(BANXA_LACE_URL);
49+
openExternalLink(getBanxaUrl({ blockchain, walletAddress }));
4750
setOpen(false);
4851
}}
4952
/>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { BANXA_LACE_URL } from './config';
2+
import { Blockchain } from '@src/multichain/BlockchainProvider';
3+
4+
const coinTypeByBlockchain: Record<Blockchain, string> = {
5+
[Blockchain.Cardano]: 'ADA',
6+
[Blockchain.Bitcoin]: 'BTC'
7+
};
8+
9+
interface BanxaUrlConfig {
10+
blockchain: Blockchain;
11+
walletAddress: string;
12+
}
13+
14+
export const getBanxaUrl = (config: BanxaUrlConfig): string => {
15+
const url = new URL(BANXA_LACE_URL);
16+
const coinType = coinTypeByBlockchain[config.blockchain];
17+
18+
url.searchParams.append('coinType', coinType);
19+
url.searchParams.append('walletAddress', config.walletAddress);
20+
21+
return url.toString();
22+
};

0 commit comments

Comments
 (0)