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

fix(frontend): use jsonReplacer to stringify bigints #3569

Merged
merged 1 commit into from
Nov 14, 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
4 changes: 2 additions & 2 deletions src/frontend/src/icp/utils/icp-transactions.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import { getAccountIdentifier } from '$icp/utils/icp-account.utils';
import type { OptionIdentity } from '$lib/types/identity';
import type { Tokens, Transaction, TransactionWithId } from '@dfinity/ledger-icp';
import { fromNullable, nonNullish } from '@dfinity/utils';
import { fromNullable, jsonReplacer, nonNullish } from '@dfinity/utils';

export const mapTransactionIcpToSelf = (
tx: TransactionWithId
Expand Down Expand Up @@ -137,5 +137,5 @@ export const mapIcpTransaction = ({
};
}

throw new Error(`Unknown transaction type ${JSON.stringify(transaction)}`);
throw new Error(`Unknown transaction type ${JSON.stringify(transaction, jsonReplacer)}`);
};
4 changes: 2 additions & 2 deletions src/frontend/src/icp/utils/icrc-transactions.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
import { getIcrcAccount } from '$icp/utils/icrc-account.utils';
import type { OptionIdentity } from '$lib/types/identity';
import { encodeIcrcAccount, type IcrcTransactionWithId } from '@dfinity/ledger-icrc';
import { fromNullable, isNullish, nonNullish } from '@dfinity/utils';
import { fromNullable, isNullish, jsonReplacer, nonNullish } from '@dfinity/utils';

export const mapTransactionIcrcToSelf = (tx: IcrcTransactionWithId): IcrcTransaction[] => {
const { transaction, id } = tx;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const mapIcrcTransaction = ({
fromNullable(approve) ?? fromNullable(burn) ?? fromNullable(mint) ?? fromNullable(transfer);

if (isNullish(data)) {
throw new Error(`Unknown transaction type ${JSON.stringify(transaction)}`);
throw new Error(`Unknown transaction type ${JSON.stringify(transaction, jsonReplacer)}`);
}

const accountIdentifier = nonNullish(identity)
Expand Down
13 changes: 8 additions & 5 deletions src/frontend/src/lib/canisters/signer.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import type {
SendBtcError as SignerCanisterSendBtcError
} from '$declarations/signer/signer.did';
import { CanisterInternalError } from '$lib/canisters/errors';
import { jsonReplacer } from '@dfinity/utils';

export class SignerCanisterPaymentError extends CanisterInternalError {
constructor(err: PaymentError) {
if ('UnsupportedPaymentType' in err) {
super('Unsupported payment type');
} else if ('LedgerWithdrawFromError' in err) {
super(`Ledger error: ${JSON.stringify(err.LedgerWithdrawFromError.error)}`);
super(`Ledger error: ${JSON.stringify(err.LedgerWithdrawFromError.error, jsonReplacer)}`);
} else if ('LedgerUnreachable' in err) {
super(`Ledger unreachable: ${JSON.stringify(err.LedgerUnreachable)}`);
super(`Ledger unreachable: ${JSON.stringify(err.LedgerUnreachable, jsonReplacer)}`);
} else if ('LedgerTransferFromError' in err) {
super(`Ledger error: ${JSON.stringify(err.LedgerTransferFromError)}`);
super(`Ledger error: ${JSON.stringify(err.LedgerTransferFromError, jsonReplacer)}`);
} else if ('InsufficientFunds' in err) {
super(
`Insufficient funds needed ${err.InsufficientFunds.needed} but available ${err.InsufficientFunds.available}`
Expand Down Expand Up @@ -46,7 +47,7 @@ export const mapSignerCanisterSendBtcError = (
return new SignerCanisterPaymentError(err.PaymentError);
}
if ('BuildP2wpkhError' in err) {
return new CanisterInternalError(JSON.stringify(err.BuildP2wpkhError));
return new CanisterInternalError(JSON.stringify(err.BuildP2wpkhError, jsonReplacer));
}
return new CanisterInternalError('Unknown SignerCanisterSendBtcError');
};
Expand All @@ -56,7 +57,9 @@ export const mapSignerCanisterGetEthAddressError = (
): CanisterInternalError => {
if ('SigningError' in err) {
const [code, addOns] = err.SigningError;
return new CanisterInternalError(`Signing error: ${JSON.stringify(code)} ${addOns}`);
return new CanisterInternalError(
`Signing error: ${JSON.stringify(code, jsonReplacer)} ${addOns}`
);
}

if ('PaymentError' in err) {
Expand Down