diff --git a/utilities/wallet-tester/src/common/components/TxBuilder.tsx b/utilities/wallet-tester/src/common/components/TxBuilder.tsx index 3f06a0d9f7..fe29b8f31b 100644 --- a/utilities/wallet-tester/src/common/components/TxBuilder.tsx +++ b/utilities/wallet-tester/src/common/components/TxBuilder.tsx @@ -354,9 +354,10 @@ function TxBuilder({ utxos, addresses, onSubmit: onPropSubmit = noop }: Props) { onRemoveClick={() => resetField("networkId")} render={() => ( diff --git a/utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts b/utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts index 4c12ef8e3d..59f981467b 100644 --- a/utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts +++ b/utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts @@ -11,6 +11,7 @@ import { GeneralTransactionMetadata, Int, LinearFee, + NetworkId, RewardAddress, StakeCredential, StakeDelegation, @@ -148,7 +149,7 @@ export default async function buildUnsignedTx( // #7 add auxiliary data hash if (builder.auxiliaryDataHash) { - // auto generated + // note: the hash will be set after building auxillary data } // #8 add validity interval start @@ -171,11 +172,6 @@ export default async function buildUnsignedTx( txBuilder.add_required_signer(Ed25519KeyHash.from_hex(stakeCred)); } - // #15 add network id - if (builder.networkId) { - // auto generated - } - // aux data const auxMetadata = AuxiliaryData.new(); const txMetadata = GeneralTransactionMetadata.new(); @@ -212,6 +208,7 @@ export default async function buildUnsignedTx( if (txMetadata.len()) { auxMetadata.set_metadata(txMetadata); + txBuilder.set_auxiliary_data(auxMetadata); } // generate fee incase too much ADA provided for fee @@ -221,7 +218,15 @@ export default async function buildUnsignedTx( } // build a full transaction, passing in empty witness set - const unsignedTx = Transaction.new(txBuilder.build(), TransactionWitnessSet.new(), auxMetadata); + const txBody = txBuilder.build(); + + // #15 add network id + if (builder.networkId && [0, 1].includes(Number(builder.networkId))) { + const networkId = Number(builder.networkId) === 0 ? NetworkId.testnet() : NetworkId.mainnet() + txBody.set_network_id(networkId); + } + + const unsignedTx = Transaction.new(txBody, TransactionWitnessSet.new(), auxMetadata); return unsignedTx; } diff --git a/utilities/wallet-tester/src/common/helpers/getCardano.ts b/utilities/wallet-tester/src/common/helpers/getCardano.ts index 68f491b6b4..b6e326b551 100644 --- a/utilities/wallet-tester/src/common/helpers/getCardano.ts +++ b/utilities/wallet-tester/src/common/helpers/getCardano.ts @@ -1,9 +1,14 @@ +import { pickBy } from "lodash-es"; import type { WalletCollections } from "types/cardano"; export default function getCardano( walletName?: T ): T extends string ? WalletCollections[string] : WalletCollections { - return (walletName ? globalThis.cardano[walletName] : globalThis.cardano) as T extends string + return (walletName ? globalThis.cardano[walletName] : filterPolluteObjects(globalThis.cardano)) as T extends string ? WalletCollections[string] : WalletCollections; } + +function filterPolluteObjects(cardano: any): WalletCollections { + return pickBy(cardano, (v) => typeof v === "object" && "enable" in v) +}