Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sync solana wallets #227

Merged
merged 1 commit into from
Mar 26, 2024
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
30 changes: 23 additions & 7 deletions src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,18 @@ export function useSwapWidget() {
}
}
if (srcChain && srcChain.chainType === "svm") {
const solanaWallet = wallets.find((w) => w.adapter.name === srcTrack?.walletName);
let wallet: (typeof wallets)[number] | undefined;
if (srcTrack?.chainType === "svm") {
wallet = wallets.find((w) => w.adapter.name === srcTrack?.walletName);
} else if (dstTrack?.chainType === "svm") {
wallet = wallets.find((w) => w.adapter.name === dstTrack?.walletName);
} else {
wallet = wallets.find((w) => w.adapter.connected);
}

if (solanaWallet?.adapter.connected) {
trackWallet.track("source", srcChain.chainID, solanaWallet.adapter.name, srcChain.chainType);
if (wallet) {
wallet.adapter.connect();
trackWallet.track("source", srcChain.chainID, wallet.adapter.name, srcChain.chainType);
} else {
trackWallet.untrack("source");
}
Expand Down Expand Up @@ -717,10 +725,18 @@ export function useSwapWidget() {
}
}
if (dstChain && dstChain.chainType === "svm") {
const solanaWallet = wallets.find((w) => w.adapter.name === srcTrack?.walletName);
let wallet: (typeof wallets)[number] | undefined;
if (dstTrack?.chainType === "svm") {
wallet = wallets.find((w) => w.adapter.name === dstTrack?.walletName);
} else if (srcTrack?.chainType === "svm") {
wallet = wallets.find((w) => w.adapter.name === srcTrack?.walletName);
} else {
wallet = wallets.find((w) => w.adapter.connected);
}

if (solanaWallet?.adapter.connected) {
trackWallet.track("destination", dstChain.chainID, solanaWallet.adapter.name, dstChain.chainType);
if (wallet) {
wallet.adapter.connect();
trackWallet.track("destination", dstChain.chainID, wallet.adapter.name, dstChain.chainType);
} else {
trackWallet.untrack("destination");
}
Expand All @@ -731,7 +747,7 @@ export function useSwapWidget() {
fireImmediately: true,
},
);
}, [connector, evmChain, getWalletRepo, srcChain, switchNetworkAsync]);
}, [connector, disconnect, evmChain, getWalletRepo, srcChain, switchNetworkAsync, wallets]);

/**
* sync destination chain wallet connections on track wallet level
Expand Down
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function App({ Component, pageProps }: AppProps) {
<WalletProvider
wallets={solanaWallets}
localStorageKey="solana-wallet"
autoConnect
>
<ChainProvider
assetLists={assets}
Expand Down
Loading