-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created new component AddTokenByNetwork (#1502)
* feat: created new component AddTokenByNetwork * style: include fade effect when switching networks * fix: removed reset of local variables * refactor: as per review, the new components will have the same logic as SendNetwork * chore: renamed variable to erc20ContractAddress * fix: according to review, we use all networks * fix: find network name not among networksMainnets
- Loading branch information
1 parent
f9bd534
commit 4928e9b
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/frontend/src/icp-eth/components/tokens/AddTokenByNetwork.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script lang="ts"> | ||
import { i18n } from '$lib/stores/i18n.store'; | ||
import { Dropdown, DropdownItem } from '@dfinity/gix-components'; | ||
import { networks } from '$lib/derived/networks.derived'; | ||
import IcAddTokenForm from '$icp/components/tokens/IcAddTokenForm.svelte'; | ||
import AddTokenForm from '$eth/components/tokens/AddTokenForm.svelte'; | ||
import { fade } from 'svelte/transition'; | ||
import type { Network } from '$lib/types/network'; | ||
import { nonNullish } from '@dfinity/utils'; | ||
import { isNetworkIdICP } from '$lib/utils/network.utils'; | ||
import { isNetworkIdEthereum } from '$lib/utils/network.utils.js'; | ||
export let network: Network | undefined; | ||
export let tokenData: Record<string, string>; | ||
let networkName: string | undefined = network?.name; | ||
$: networkName, | ||
(network = nonNullish(networkName) | ||
? $networks.find(({ name }) => name === networkName) | ||
: undefined); | ||
let ledgerCanisterId: string; | ||
let indexCanisterId: string; | ||
let erc20ContractAddress: string; | ||
$: tokenData = { | ||
ledgerCanisterId, | ||
indexCanisterId, | ||
erc20ContractAddress | ||
}; | ||
</script> | ||
|
||
<div class="stretch pt-8"> | ||
<label for="network" class="font-bold px-4.5">{$i18n.tokens.manage.text.network}:</label> | ||
|
||
<div id="network" class="mb-4 mt-1 pt-0.5"> | ||
<Dropdown name="network" bind:selectedValue={networkName}> | ||
<option disabled selected value={undefined} class="hidden" | ||
><span class="description">{$i18n.tokens.manage.placeholder.select_network}</span></option | ||
> | ||
{#each $networks as network} | ||
<DropdownItem value={network.name}>{network.name}</DropdownItem> | ||
{/each} | ||
</Dropdown> | ||
</div> | ||
|
||
{#if nonNullish(network)} | ||
<div class="mt-8"> | ||
{#if isNetworkIdICP(network?.id)} | ||
<div in:fade> | ||
<IcAddTokenForm on:icBack on:icNext bind:ledgerCanisterId bind:indexCanisterId /> | ||
</div> | ||
{:else if isNetworkIdEthereum(network?.id)} | ||
<div in:fade> | ||
<AddTokenForm on:icBack on:icNext bind:contractAddress={erc20ContractAddress} /> | ||
</div> | ||
{/if} | ||
</div> | ||
{/if} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.hidden { | ||
display: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters