Skip to content

Commit

Permalink
refactor: change definition of tokenData
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii-DFINITY committed Jun 21, 2024
1 parent 5871e78 commit ae267e8
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
Expand All @@ -24,13 +23,17 @@
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
// 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 = {};
}
}
</script>

<div class="stretch pt-8">
Expand Down

0 comments on commit ae267e8

Please sign in to comment.