-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: icrc21_canister_call_consent_message for ledger-icrc (#710)
# Motivation Add support for `icrc21_canister_call_consent_message` to `@dfinity/ledger-icrc`. # Notes It annoys me a bit that the close basically duplicates the code of ICP (provided in PR #709) but, not sure it is worth the effort at this point to create a util or even lib for that particular topic. We might do so if more canisters starts implementing consent message but, happy to hear any thoughts about it. # Changes - Expose and implement new function `consentMessage`. - Add a new parameter for the request. - Map the potential error. --------- Signed-off-by: David Dal Busco <david.dalbusco@dfinity.org> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5ff19cc
commit 90d1109
Showing
7 changed files
with
524 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
import type { icrc21_error as Icrc21RawError } from "../../candid/icrc_ledger"; | ||
|
||
export class IcrcTransferError<T> extends Error { | ||
public errorType: T; | ||
constructor({ msg, errorType }: { msg?: string; errorType: T }) { | ||
super(msg); | ||
this.errorType = errorType; | ||
} | ||
} | ||
|
||
export class GenericError extends Error { | ||
constructor( | ||
public readonly message: string, | ||
public readonly error_code: bigint, | ||
) { | ||
super(); | ||
} | ||
} | ||
|
||
export class ConsentMessageError extends Error {} | ||
|
||
export class InsufficientPaymentError extends ConsentMessageError {} | ||
export class UnsupportedCanisterCallError extends ConsentMessageError {} | ||
export class ConsentMessageUnavailableError extends ConsentMessageError {} | ||
|
||
export const mapIcrc21ConsentMessageError = ( | ||
rawError: Icrc21RawError, | ||
): ConsentMessageError => { | ||
if ("GenericError" in rawError) { | ||
return new GenericError( | ||
rawError.GenericError.description, | ||
rawError.GenericError.error_code, | ||
); | ||
} | ||
|
||
if ("InsufficientPayment" in rawError) { | ||
return new InsufficientPaymentError( | ||
rawError.InsufficientPayment.description, | ||
); | ||
} | ||
|
||
if ("UnsupportedCanisterCall" in rawError) { | ||
return new UnsupportedCanisterCallError( | ||
rawError.UnsupportedCanisterCall.description, | ||
); | ||
} | ||
if ("ConsentMessageUnavailable" in rawError) { | ||
return new ConsentMessageUnavailableError( | ||
rawError.ConsentMessageUnavailable.description, | ||
); | ||
} | ||
|
||
// Edge case | ||
return new ConsentMessageError( | ||
`Unknown error type ${JSON.stringify(rawError)}`, | ||
); | ||
}; |
Oops, something went wrong.