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(signer): support ledgers that do not implement ICRC-21 #4082

Merged
merged 11 commits into from
Jan 9, 2025
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@dfinity/gix-components": "^5.0.0-next-2024-12-10",
"@dfinity/ledger-icp": "^2.6.5",
"@dfinity/ledger-icrc": "^2.7.0",
"@dfinity/oisy-wallet-signer": "^0.0.3",
"@dfinity/oisy-wallet-signer": "^0.1.1",
"@dfinity/principal": "^2.1.2",
"@dfinity/utils": "^2.8.0",
"@dfinity/verifiable-credentials": "^0.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script lang="ts">
import { Markdown } from '@dfinity/gix-components';
import type {
icrc21_consent_info,
ConsentMessageApproval,
Rejection
Rejection,
ResultConsentInfo
} from '@dfinity/oisy-wallet-signer';
import { isNullish, nonNullish } from '@dfinity/utils';
import { getContext } from 'svelte';
import { fade } from 'svelte/transition';
import SignerConsentMessageWarning from '$lib/components/signer/SignerConsentMessageWarning.svelte';
import SignerLoading from '$lib/components/signer/SignerLoading.svelte';
import SignerOrigin from '$lib/components/signer/SignerOrigin.svelte';
import ButtonGroup from '$lib/components/ui/ButtonGroup.svelte';
Expand All @@ -22,7 +23,7 @@

let approve: ConsentMessageApproval | undefined;
let reject: Rejection | undefined;
let consentInfo: icrc21_consent_info | undefined;
let consentInfo: ResultConsentInfo | undefined;

$: ({ approve, reject, consentInfo } =
nonNullish($payload) && $payload.status === 'result'
Expand Down Expand Up @@ -54,9 +55,15 @@
return;
}

const consentInfoMsg = nonNullish(consentInfo)
? 'Warn' in consentInfo
? consentInfo.Warn.consentInfo
: consentInfo.Ok
: undefined;

displayMessage =
nonNullish(consentInfo) && 'GenericDisplayMessage' in consentInfo.consent_message
? consentInfo.consent_message.GenericDisplayMessage
nonNullish(consentInfoMsg) && 'GenericDisplayMessage' in consentInfoMsg.consent_message
? consentInfoMsg.consent_message.GenericDisplayMessage
: undefined;
};

Expand Down Expand Up @@ -122,6 +129,8 @@

<SignerOrigin payload={$payload} />

<SignerConsentMessageWarning {consentInfo} />

<div class="msg mb-6 rounded-lg border border-dust px-8 py-4">
<Markdown text={content} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import type { ResultConsentInfo } from '@dfinity/oisy-wallet-signer';
import { nonNullish } from '@dfinity/utils';
import MessageBox from '$lib/components/ui/MessageBox.svelte';
import { i18n } from '$lib/stores/i18n.store';

export let consentInfo: ResultConsentInfo | undefined;

// The ICRC-49 standard specifies that a user should be warned when a consent message is interpreted on the frontend side instead of being retrieved through a canister.
// See https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_49_call_canister.md#message-processing
let displayWarning: boolean | undefined;
$: displayWarning = nonNullish(consentInfo) && 'Warn' in consentInfo;
</script>

{#if displayWarning}
<MessageBox level="light-warning"
>{$i18n.signer.consent_message.warning.token_without_consent_message}</MessageBox
>
{/if}
3 changes: 3 additions & 0 deletions src/frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@
"text": {
"loading": "Loading consent message..."
},
"warning": {
"token_without_consent_message": "This token does not provide confirmation messages, so the information below was extracted by OISY."
},
"error": {
"no_approve_callback": "No callback to approve the consent message, which is unexpected. Close the wallet and try again.",
"no_reject_callback": "No callback to reject the consent message, which is unexpected. Close the wallet and try again.",
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/lib/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ interface I18nSigner {
origin: { text: { request_from: string; invalid_origin: string }; alt: { link_to_dapp: string } };
consent_message: {
text: { loading: string };
warning: { token_without_consent_message: string };
error: { no_approve_callback: string; no_reject_callback: string; retrieve: string };
};
call_canister: {
Expand Down
Loading