-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
564 additions
and
144 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -82,5 +82,5 @@ | |
"test": "vitest run" | ||
}, | ||
"type": "module", | ||
"version": "2.6.11" | ||
"version": "2.7.0" | ||
} |
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
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
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
136 changes: 136 additions & 0 deletions
136
src/ic_message_frontend/src/lib/components/core/ImportTokenModal.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,136 @@ | ||
<script lang="ts"> | ||
import { TokenLedgerAPI } from '$lib/canisters/tokenledger' | ||
import IconCircleSpin from '$lib/components/icons/IconCircleSpin.svelte' | ||
import IconExternalLinkLine from '$lib/components/icons/IconExternalLinkLine.svelte' | ||
import ModalCard from '$lib/components/ui/ModalCard.svelte' | ||
import type { LedgerAPI } from '$lib/types/token' | ||
import { TokenDisplay, type TokenInfo } from '$lib/utils/token' | ||
import { Principal } from '@dfinity/principal' | ||
import { tick, type SvelteComponent } from 'svelte' | ||
// Props | ||
type TokenInfoEx = TokenInfo & { api: LedgerAPI; balance: bigint } | ||
interface Props { | ||
/** Exposes parent props to this component. */ | ||
parent: SvelteComponent | ||
onsave: (token: TokenInfoEx) => Promise<void> | ||
} | ||
let { parent, onsave }: Props = $props() | ||
let ledgerId = $state('') | ||
let ledgerErr = $state('') | ||
let token: TokenInfoEx | null = $state(null) | ||
let submitting = $state(false) | ||
async function onFormChange(e: Event) { | ||
e.stopPropagation() | ||
e.preventDefault() | ||
ledgerErr = '' | ||
let id: Principal | null = null | ||
token = null | ||
try { | ||
id = Principal.fromText(ledgerId) | ||
} catch (e) {} | ||
if (!id) { | ||
return | ||
} | ||
try { | ||
submitting = true | ||
await tick() | ||
const api = await TokenLedgerAPI.fromID(id) | ||
const balance = await api.balance() | ||
token = { ...api.token, api, balance } | ||
} catch (e) { | ||
token = null | ||
ledgerErr = 'Token not found' | ||
} | ||
submitting = false | ||
} | ||
async function onclick(e: Event) { | ||
if (token) { | ||
submitting = true | ||
await onsave(token) | ||
parent['onClose'] && parent['onClose']() | ||
} | ||
} | ||
</script> | ||
|
||
<ModalCard {parent}> | ||
<div class="!mt-0 text-center text-xl font-bold">Import Token</div> | ||
|
||
<form | ||
class="m-auto !mt-4 flex flex-col content-center" | ||
oninput={onFormChange} | ||
> | ||
<div class=""> | ||
<p class=""> | ||
You can import a new token to wallet by providing its ledger canister | ||
ID. | ||
</p> | ||
<a | ||
type="button" | ||
class="mt-2 flex w-fit flex-row items-center gap-2 text-primary-500" | ||
target="_blank" | ||
href="https://internetcomputer.org/docs/current/developer-docs/daos/nns/using-the-nns-dapp/nns-dapp-importing-tokens" | ||
> | ||
<span class="*:size-5"><IconExternalLinkLine /></span> | ||
<span class="hover:underline">How to find ICRC token ledger</span> | ||
</a> | ||
</div> | ||
<div class="relative mt-4"> | ||
<input | ||
class="border-gray/10 input truncate rounded-xl bg-white/20 invalid:input-warning" | ||
type="text" | ||
name="ledgerId" | ||
maxlength="27" | ||
data-1p-ignore | ||
bind:value={ledgerId} | ||
disabled={submitting} | ||
placeholder="_____-_____-_____-_____-cai" | ||
required | ||
/> | ||
</div> | ||
{#if token} | ||
<div class="mt-4 grid grid-cols-[48px_1fr]"> | ||
<img class="size-12" alt={token.name} src={token.logo} /> | ||
<div class="pl-2"> | ||
<div class="flex flex-row justify-between"> | ||
<span class="">{token.symbol}</span> | ||
<span class="" | ||
>{new TokenDisplay(token, token.balance).display()}</span | ||
> | ||
</div> | ||
<div class="flex flex-row justify-between text-sm text-surface-500"> | ||
<span class="">{token.name}</span> | ||
</div> | ||
</div> | ||
</div> | ||
{:else if ledgerErr} | ||
<div class="mt-4"> | ||
<p class="text-error-500">{ledgerErr}</p> | ||
</div> | ||
{/if} | ||
</form> | ||
<footer class="m-auto !mt-6"> | ||
<button | ||
class="variant-filled-primary btn w-full" | ||
disabled={submitting || !token} | ||
{onclick} | ||
> | ||
{#if submitting} | ||
<span class=""><IconCircleSpin /></span> | ||
<span>Processing...</span> | ||
{:else} | ||
<span>Import</span> | ||
{/if} | ||
</button> | ||
</footer> | ||
</ModalCard> |
39 changes: 39 additions & 0 deletions
39
src/ic_message_frontend/src/lib/components/core/TransferTokenModal.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,39 @@ | ||
<script lang="ts"> | ||
import ModalCard from '$lib/components/ui/ModalCard.svelte' | ||
import SendTokenForm from '$lib/components/ui/SendTokenForm.svelte' | ||
import type { LedgerAPI, SendTokenArgs } from '$lib/types/token' | ||
import { type TokenInfo } from '$lib/utils/token' | ||
import type { Principal } from '@dfinity/principal' | ||
import { type SvelteComponent } from 'svelte' | ||
// Props | ||
type TokenInfoEx = TokenInfo & { api: LedgerAPI; balance: bigint } | ||
interface Props { | ||
/** Exposes parent props to this component. */ | ||
parent: SvelteComponent | ||
token: TokenInfoEx | ||
principal: Principal | ||
} | ||
let { parent, principal, token }: Props = $props() | ||
async function handleTokenTransfer(args: SendTokenArgs) { | ||
const idx = await token.api.transfer(args.to, args.amount) | ||
token.balance = await token.api.balance() | ||
return idx | ||
} | ||
</script> | ||
|
||
<ModalCard {parent}> | ||
<div class="!mt-0 text-center text-xl font-bold">Transfer {token.symbol}</div> | ||
<div class="mx-auto !mt-6 space-y-4"> | ||
<SendTokenForm | ||
sendFrom={principal} | ||
availableBalance={token.balance} | ||
{token} | ||
onSubmit={handleTokenTransfer} | ||
/> | ||
</div> | ||
</ModalCard> |
Oops, something went wrong.