Skip to content

Commit

Permalink
fix(bridge-ui-v2): Faucet no longer checking for destination chain (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK authored Jan 29, 2024
1 parent dc46b27 commit bfcab5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import { destNetwork, destOptions } from '$components/Bridge/state';
import SwitchChainsButton from '$components/Bridge/SwitchChainsButton.svelte';
import { ChainSelector } from '$components/ChainSelector';
import { OnAccount } from '$components/OnAccount';
import { OnNetwork } from '$components/OnNetwork';
import { hasBridge } from '$libs/bridge/bridges';
import { chainIdToChain, chains } from '$libs/chain';
import { account } from '$stores/account';
import { network } from '$stores/network';
let destChainElement: ChainSelector;
Expand All @@ -30,15 +32,6 @@
});
}
function onNetworkChange() {
updateDestOptions();
const alternateChainID = getAlternateNetwork();
if (!$destNetwork && alternateChainID) {
// if only two chains are available, set the destination chain to the other one
$destNetwork = chainIdToChain(alternateChainID);
}
}
const getAlternateNetwork = (): number | null => {
if (!$network?.id) {
return null;
Expand All @@ -48,18 +41,35 @@
// only allow switching between two chains, if we have more we do not use this util
if (chainKeys.length !== 2) {
updateDestOptions();
return null;
}
const alternateChainId = chainKeys.find((key) => key !== currentNetwork);
if (!alternateChainId) return null;
updateDestOptions();
return alternateChainId;
};
$: highlight = $destNetwork ? false : true;
const onNetworkChange = () => setAlternateNetwork();
const onAccountChange = () => setAlternateNetwork();
const setAlternateNetwork = () => {
if ($account && ($account.isConnected || $account.isConnecting)) {
const alternateChainID = getAlternateNetwork();
if (alternateChainID) {
$destNetwork = chainIdToChain(alternateChainID);
}
} else {
$destNetwork = null;
}
};
onMount(() => {
updateDestOptions();
setAlternateNetwork();
});
</script>

Expand All @@ -82,3 +92,4 @@
fromToLabel={$t('common.to')} />

<OnNetwork change={onNetworkChange} />
<OnAccount change={onAccountChange} />
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,17 @@
warningToast({ title: $t('messages.network.required') });
return;
}
if (!destChain || !destChain.id) {
warningToast({ title: $t('messages.network.required_dest') });
return;
}
// if it is an imported Token, chances are we do not yet have the bridged address
// for the destination chain, so we need to fetch it
if (token.imported) {
// ... in the case of imported tokens, we also require the destination chain to be selected. if (!destChain) {
let bridgedAddress = null;
if (!destChain || !destChain.id) {
warningToast({ title: $t('messages.network.required_dest') });
return;
}
try {
bridgedAddress = await getCrossChainAddress({
token,
Expand All @@ -94,13 +93,17 @@
tokenService.updateToken(token, $account?.address as Address);
}
}
value = token;
const info = await getCanonicalInfoForToken({ token, srcChainId: srcChain.id, destChainId: destChain.id });
if (info && value.addresses[srcChain.id] !== info.address) {
log('selected token is not canonical');
$selectedTokenIsBridged = true;
} else {
$selectedTokenIsBridged = false;
if (destChain) {
const info = await getCanonicalInfoForToken({ token, srcChainId: srcChain.id, destChainId: destChain.id });
if (info && value.addresses[srcChain.id] !== info.address) {
log('selected token is not canonical');
$selectedTokenIsBridged = true;
} else {
$selectedTokenIsBridged = false;
}
}
closeMenu();
};
Expand Down

0 comments on commit bfcab5e

Please sign in to comment.