Skip to content

Commit

Permalink
refactor: extract consent message
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Dec 23, 2024
1 parent c81046e commit afd590c
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/services/signer.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Principal} from '@dfinity/principal';
import {isNullish, notEmptyString} from '@dfinity/utils';
import {SignerApi} from '../api/signer.api';
import {icrc21_consent_message_response} from '../declarations/icrc-21';
import {
notifyErrorActionAborted,
notifyErrorMissingPrompt,
Expand All @@ -25,7 +26,7 @@ export class SignerService {
readonly #signerApi = new SignerApi();

async assertAndPromptConsentMessage({
params: {canisterId, method, arg, sender},
params: {sender, ...params},
prompt,
notify,
options: {owner, host}
Expand All @@ -52,22 +53,9 @@ export class SignerService {
prompt({origin, status: 'loading'});

try {
const response = await this.#signerApi.consentMessage({
owner,
host,
canisterId,
request: {
method,
arg: base64ToUint8Array(arg),
// TODO: consumer should be able to define user_preferences
user_preferences: {
metadata: {
language: 'en',
utc_offset_minutes: []
},
device_spec: []
}
}
const response = await this.callConsentMessage({
params,
options: {host, owner}
});

if ('Err' in response) {
Expand Down Expand Up @@ -171,6 +159,32 @@ export class SignerService {
return {result: 'invalid'};
}

private async callConsentMessage({
params: {canisterId, method, arg},
options: {owner, host}
}: {
params: Omit<IcrcCallCanisterRequestParams, 'sender'>;
options: SignerOptions;
}): Promise<icrc21_consent_message_response> {
return await this.#signerApi.consentMessage({
owner,
host,
canisterId,
request: {
method,
arg: base64ToUint8Array(arg),
// TODO: consumer should be able to define user_preferences
user_preferences: {
metadata: {
language: 'en',
utc_offset_minutes: []
},
device_spec: []
}
}
});
}

private async promptConsentMessage({
prompt,
...payload
Expand Down

0 comments on commit afd590c

Please sign in to comment.