Skip to content

Commit bf61119

Browse files
committed
chore: parallellize keychain and queryPromise
Ticket: CAAS-7
1 parent c904a16 commit bf61119

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,25 +2176,25 @@ export class Wallet implements IWallet {
21762176
}
21772177

21782178
// Doing a sanity check for password here to avoid doing further work if we know it's wrong
2179-
const keychains = await this.getKeychainsAndValidatePassphrase({
2180-
reqId: params.reqId,
2181-
walletPassphrase: params.walletPassphrase,
2182-
customSigningFunction: params.customSigningFunction,
2183-
});
2184-
2185-
let txPrebuildQuery: Promise<PrebuildTransactionResult | string>;
2186-
if (isPrebuildTransactionResult(params.prebuildTx) && params.prebuildTx.buildParams?.preview) {
2187-
// If we prebuilt the txRequest with preview=true, then we should rebuild with preview=false to persist the request
2188-
txPrebuildQuery = this.prebuildTransaction({
2189-
...params,
2190-
...{ ...params.prebuildTx.buildParams, preview: false },
2191-
});
2192-
} else {
2193-
txPrebuildQuery = params.prebuildTx ? Promise.resolve(params.prebuildTx) : this.prebuildTransaction(params);
2194-
}
2179+
// Run keychain validation and tx prebuild in parallel
2180+
const [keychains, txPrebuild] = await Promise.all([
2181+
// Validate passphrase and get keychains
2182+
this.getKeychainsAndValidatePassphrase({
2183+
reqId: params.reqId,
2184+
walletPassphrase: params.walletPassphrase,
2185+
customSigningFunction: params.customSigningFunction,
2186+
}),
21952187

2196-
// the prebuild can be overridden by providing an explicit tx
2197-
const txPrebuild = (await txPrebuildQuery) as PrebuildTransactionResult;
2188+
(async () => {
2189+
if (isPrebuildTransactionResult(params.prebuildTx) && params.prebuildTx.buildParams?.preview) {
2190+
return this.prebuildTransaction({
2191+
...params,
2192+
...{ ...params.prebuildTx.buildParams, preview: false },
2193+
});
2194+
}
2195+
return params.prebuildTx ? Promise.resolve(params.prebuildTx) : this.prebuildTransaction(params);
2196+
})() as Promise<PrebuildTransactionResult>,
2197+
]);
21982198

21992199
try {
22002200
await this.baseCoin.verifyTransaction({

0 commit comments

Comments
 (0)