diff --git a/src/frontend/src/icp-eth/components/tokens/AddTokenByNetwork.svelte b/src/frontend/src/icp-eth/components/tokens/AddTokenByNetwork.svelte index ee7339f983..9dc1dd6e36 100644 --- a/src/frontend/src/icp-eth/components/tokens/AddTokenByNetwork.svelte +++ b/src/frontend/src/icp-eth/components/tokens/AddTokenByNetwork.svelte @@ -9,7 +9,6 @@ import { nonNullish } from '@dfinity/utils'; import { isNetworkIdICP } from '$lib/utils/network.utils'; import { isNetworkIdEthereum } from '$lib/utils/network.utils.js'; - import { onDestroy } from 'svelte'; export let network: Network | undefined; export let tokenData: Record; @@ -24,13 +23,18 @@ let indexCanisterId: string; let erc20ContractAddress: string; - onDestroy(() => { - tokenData = isNetworkIdICP(network?.id) - ? { ledgerCanisterId, indexCanisterId } - : isNetworkIdEthereum(network?.id) - ? { erc20ContractAddress } - : {}; - }); + // Since we persist the values of relevant variables when switching networks, this ensures that, + // when the user returns to the previous component, only the data related to the selected network + // is passed. + $: { + if (isNetworkIdICP(network?.id)) { + tokenData = { ledgerCanisterId, indexCanisterId }; + } else if (isNetworkIdEthereum(network?.id)) { + tokenData = { erc20ContractAddress }; + } else { + tokenData = {}; + } + }