Skip to content

Commit

Permalink
feat: enable network ID
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem committed May 16, 2024
1 parent 51d3c80 commit 7ba476e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 4 additions & 3 deletions utilities/wallet-tester/src/common/components/TxBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ function TxBuilder({ utxos, addresses, onSubmit: onPropSubmit = noop }: Props) {
onRemoveClick={() => resetField("networkId")}
render={() => (
<Input
type="text"
disabled={true}
placeholder="Auto generated"
type="number"
min={0}
max={1}
placeholder="0: testnet, 1: mainnet"
label="Network ID"
formRegister={register("networkId")}
/>
Expand Down
14 changes: 11 additions & 3 deletions utilities/wallet-tester/src/common/helpers/buildUnsignedTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
GeneralTransactionMetadata,
Int,
LinearFee,
NetworkId,
RewardAddress,
StakeCredential,
StakeDelegation,
Expand Down Expand Up @@ -173,8 +174,7 @@ export default async function buildUnsignedTx(

// #15 add network id
if (builder.networkId) {
txBuilder.add_change_if_needed
// note: auto generated
// note: network id will be after build the transaction builder
}

// aux data
Expand Down Expand Up @@ -223,7 +223,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();

// set network id after build
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;
}

0 comments on commit 7ba476e

Please sign in to comment.