From 914805435c7bb9ea2c998917bc969e3774f25b1c Mon Sep 17 00:00:00 2001 From: Antonio Ventilii Date: Fri, 21 Jun 2024 06:04:40 -0300 Subject: [PATCH] refactor: change definition of tokenData --- .../tokens/AddTokenByNetwork.svelte | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 = {}; + } + }