Skip to content

Commit bca05c5

Browse files
authored
fix(wallet-tester): missing configurable aux hash and network ID (#500)
* fix: aux hash * fix: filter pollution * chore: fmt * feat: enable network ID * fix: note typo * fix: typo
1 parent d00fa4a commit bca05c5

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

utilities/wallet-tester/src/common/components/TxBuilder.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,10 @@ function TxBuilder({ utxos, addresses, onSubmit: onPropSubmit = noop }: Props) {
354354
onRemoveClick={() => resetField("networkId")}
355355
render={() => (
356356
<Input
357-
type="text"
358-
disabled={true}
359-
placeholder="Auto generated"
357+
type="number"
358+
min={0}
359+
max={1}
360+
placeholder="0: testnet, 1: mainnet"
360361
label="Network ID"
361362
formRegister={register("networkId")}
362363
/>

utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
GeneralTransactionMetadata,
1212
Int,
1313
LinearFee,
14+
NetworkId,
1415
RewardAddress,
1516
StakeCredential,
1617
StakeDelegation,
@@ -148,7 +149,7 @@ export default async function buildUnsignedTx(
148149

149150
// #7 add auxiliary data hash
150151
if (builder.auxiliaryDataHash) {
151-
// auto generated
152+
// note: the hash will be set after building auxillary data
152153
}
153154

154155
// #8 add validity interval start
@@ -171,11 +172,6 @@ export default async function buildUnsignedTx(
171172
txBuilder.add_required_signer(Ed25519KeyHash.from_hex(stakeCred));
172173
}
173174

174-
// #15 add network id
175-
if (builder.networkId) {
176-
// auto generated
177-
}
178-
179175
// aux data
180176
const auxMetadata = AuxiliaryData.new();
181177
const txMetadata = GeneralTransactionMetadata.new();
@@ -212,6 +208,7 @@ export default async function buildUnsignedTx(
212208

213209
if (txMetadata.len()) {
214210
auxMetadata.set_metadata(txMetadata);
211+
txBuilder.set_auxiliary_data(auxMetadata);
215212
}
216213

217214
// generate fee incase too much ADA provided for fee
@@ -221,7 +218,15 @@ export default async function buildUnsignedTx(
221218
}
222219

223220
// build a full transaction, passing in empty witness set
224-
const unsignedTx = Transaction.new(txBuilder.build(), TransactionWitnessSet.new(), auxMetadata);
221+
const txBody = txBuilder.build();
222+
223+
// #15 add network id
224+
if (builder.networkId && [0, 1].includes(Number(builder.networkId))) {
225+
const networkId = Number(builder.networkId) === 0 ? NetworkId.testnet() : NetworkId.mainnet()
226+
txBody.set_network_id(networkId);
227+
}
228+
229+
const unsignedTx = Transaction.new(txBody, TransactionWitnessSet.new(), auxMetadata);
225230

226231
return unsignedTx;
227232
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { pickBy } from "lodash-es";
12
import type { WalletCollections } from "types/cardano";
23

34
export default function getCardano<T extends string | undefined>(
45
walletName?: T
56
): T extends string ? WalletCollections[string] : WalletCollections {
6-
return (walletName ? globalThis.cardano[walletName] : globalThis.cardano) as T extends string
7+
return (walletName ? globalThis.cardano[walletName] : filterPolluteObjects(globalThis.cardano)) as T extends string
78
? WalletCollections[string]
89
: WalletCollections;
910
}
11+
12+
function filterPolluteObjects(cardano: any): WalletCollections {
13+
return pickBy(cardano, (v) => typeof v === "object" && "enable" in v)
14+
}

0 commit comments

Comments
 (0)