Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-svg-support
Browse files Browse the repository at this point in the history
  • Loading branch information
minikin authored May 17, 2024
2 parents 6f249e0 + bca05c5 commit 569b392
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 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
19 changes: 12 additions & 7 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 @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
7 changes: 6 additions & 1 deletion utilities/wallet-tester/src/common/helpers/getCardano.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { pickBy } from "lodash-es";
import type { WalletCollections } from "types/cardano";

export default function getCardano<T extends string | undefined>(
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)
}

0 comments on commit 569b392

Please sign in to comment.