Skip to content

Commit

Permalink
Merge pull request #962 from input-output-hk/fix/try-catch-bech32-cas…
Browse files Browse the repository at this point in the history
…ting

fix: use try/catch with potential unknown address type
  • Loading branch information
mchappell authored Oct 25, 2024
2 parents fc1bfa9 + f286ea4 commit 04888f3
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/ui/app/components/transaction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,25 @@ const getTimestamp = (date) => {
};

const getAddressCredentials = (address) => {
const cmlAddress = Loader.Cardano.Address.from_bech32(address);
return [cmlAddress.payment_cred()?.to_cbor_hex(), cmlAddress.staking_cred()?.to_cbor_hex()];
}
try {
const cmlAddress = Loader.Cardano.Address.from_bech32(address);
return [
cmlAddress.payment_cred()?.to_cbor_hex() || null,
cmlAddress.staking_cred()?.to_cbor_hex() || null,
];
} catch (error) {
try {
// try casting as byron address
const cmlAddress = Loader.Cardano.ByronAddress.from_base58(address);
return [
cmlAddress.to_address()?.payment_cred()?.to_cbor_hex() || null,
cmlAddress.to_address()?.staking_cred()?.to_cbor_hex() || null,
];
} catch {}
console.error(error);
return [null, null];
}
};

const matchesAnyCredential = (address, [ownPaymentCred, ownStakingCred]) => {
const [otherPaymentCred, otherStakingCred] = getAddressCredentials(address);
Expand All @@ -516,7 +532,8 @@ const calculateAmount = (currentAddr, uTxOList, validContract = true) => {
let outputs = compileOutputs(
uTxOList.outputs.filter(
(output) =>
matchesAnyCredential(output.address, ownCredentials) && !(output.collateral && validContract)
matchesAnyCredential(output.address, ownCredentials) &&
!(output.collateral && validContract)
)
);
let amounts = [];
Expand Down

0 comments on commit 04888f3

Please sign in to comment.