Skip to content

Commit 04888f3

Browse files
authored
Merge pull request #962 from input-output-hk/fix/try-catch-bech32-casting
fix: use try/catch with potential unknown address type
2 parents fc1bfa9 + f286ea4 commit 04888f3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/ui/app/components/transaction.jsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,25 @@ const getTimestamp = (date) => {
495495
};
496496

497497
const getAddressCredentials = (address) => {
498-
const cmlAddress = Loader.Cardano.Address.from_bech32(address);
499-
return [cmlAddress.payment_cred()?.to_cbor_hex(), cmlAddress.staking_cred()?.to_cbor_hex()];
500-
}
498+
try {
499+
const cmlAddress = Loader.Cardano.Address.from_bech32(address);
500+
return [
501+
cmlAddress.payment_cred()?.to_cbor_hex() || null,
502+
cmlAddress.staking_cred()?.to_cbor_hex() || null,
503+
];
504+
} catch (error) {
505+
try {
506+
// try casting as byron address
507+
const cmlAddress = Loader.Cardano.ByronAddress.from_base58(address);
508+
return [
509+
cmlAddress.to_address()?.payment_cred()?.to_cbor_hex() || null,
510+
cmlAddress.to_address()?.staking_cred()?.to_cbor_hex() || null,
511+
];
512+
} catch {}
513+
console.error(error);
514+
return [null, null];
515+
}
516+
};
501517

502518
const matchesAnyCredential = (address, [ownPaymentCred, ownStakingCred]) => {
503519
const [otherPaymentCred, otherStakingCred] = getAddressCredentials(address);
@@ -516,7 +532,8 @@ const calculateAmount = (currentAddr, uTxOList, validContract = true) => {
516532
let outputs = compileOutputs(
517533
uTxOList.outputs.filter(
518534
(output) =>
519-
matchesAnyCredential(output.address, ownCredentials) && !(output.collateral && validContract)
535+
matchesAnyCredential(output.address, ownCredentials) &&
536+
!(output.collateral && validContract)
520537
)
521538
);
522539
let amounts = [];

0 commit comments

Comments
 (0)