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(bridge-ui-v2): Faucet no longer checking for destination chain #15594

Merged
merged 1 commit into from
Jan 29, 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
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
Loading