Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "Build consent message" to demo #380

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script lang="ts">
import type { IcpWallet } from '@dfinity/oisy-wallet-signer/icp-wallet';
import { isNullish, nonNullish } from '@dfinity/utils';
import { fade } from 'svelte/transition';
import Button from '$core/components/Button.svelte';
import Value from '$core/components/Value.svelte';
import { accountsStore } from '$lib/stores/accounts.store';
import { authStore } from '$core/stores/auth.store';
import type { Icrc1TransferRequest } from '@dfinity/ledger-icp';
import { E8S_PER_ICP } from '$core/constants/app.constants';

type Props = {
wallet: IcpWallet | undefined;
};

let { wallet }: Props = $props();

const INVALID_LEDGER_CANISTER_ID = import.meta.env.VITE_SATELLITE_ID;
console.log(INVALID_LEDGER_CANISTER_ID);

const onclick = async () => {
// TODO: handle errors
if (isNullish($authStore.identity)) {
return;
}

const account = $accountsStore?.[0];
peterpeterparker marked this conversation as resolved.
Show resolved Hide resolved

if (isNullish(account)) {
return;
}

const request: Icrc1TransferRequest = {
to: {
owner: $authStore.identity.getPrincipal(),
subaccount: []
},
amount: 1n * (E8S_PER_ICP / 2n)
};

await wallet?.icrc1Transfer({
AntonioVentilii marked this conversation as resolved.
Show resolved Hide resolved
owner: account.owner,
request,
ledgerCanisterId: INVALID_LEDGER_CANISTER_ID
});
};
</script>

{#if nonNullish(wallet) && nonNullish($accountsStore)}
<div in:fade class="mt-4">
<Value id="build-consent-message" testId="build-consent-message" title="Build Consent Message">
<Button {onclick} testId="build-consent-message-button">Build</Button>
</Value>
</div>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
return;
}

if (isNullish($accountsStore)) {
return;
}

const account = $accountsStore?.[0];

if (isNullish(account)) {
Expand Down
3 changes: 3 additions & 0 deletions demo/src/relying_party_frontend/src/routes/dev/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Balance from '$core/components/Balance.svelte';
import Connect from '$lib/components/Connect.svelte';
import { authStore } from '$core/stores/auth.store';
import BuildConsentMessage from '$lib/components/BuildConsentMessage.svelte';

let wallet = $state<IcpWallet | undefined>(undefined);

Expand Down Expand Up @@ -59,3 +60,5 @@
<Accounts {wallet} />

<CallCanister {wallet} />

<BuildConsentMessage {wallet} />
Loading