Skip to content

Commit a205275

Browse files
authored
Merge pull request #6136 from BitGo/CAAS-7-round-trips
chore: parallellize keychain and queryPromise
2 parents 89470bb + 5367fbb commit a205275

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ export class Wallet implements IWallet {
21852185
}
21862186

21872187
// Doing a sanity check for password here to avoid doing further work if we know it's wrong
2188-
const keychains = await this.getKeychainsAndValidatePassphrase({
2188+
const keychainPromise = this.getKeychainsAndValidatePassphrase({
21892189
reqId: params.reqId,
21902190
walletPassphrase: params.walletPassphrase,
21912191
customSigningFunction: params.customSigningFunction,
@@ -2201,9 +2201,24 @@ export class Wallet implements IWallet {
22012201
} else {
22022202
txPrebuildQuery = params.prebuildTx ? Promise.resolve(params.prebuildTx) : this.prebuildTransaction(params);
22032203
}
2204+
let keychains: Keychain[] = [];
2205+
let txPrebuild: PrebuildTransactionResult;
2206+
2207+
const results = await Promise.allSettled([keychainPromise, txPrebuildQuery]);
22042208

2205-
// the prebuild can be overridden by providing an explicit tx
2206-
const txPrebuild = (await txPrebuildQuery) as PrebuildTransactionResult;
2209+
// Handle keychain promise (index 0)
2210+
if (results[0].status === 'fulfilled') {
2211+
keychains = results[0].value as Keychain[];
2212+
} else {
2213+
throw results[0].reason;
2214+
}
2215+
2216+
// Handle txPrebuild promise (index 1)
2217+
if (results[1].status === 'fulfilled') {
2218+
txPrebuild = results[1].value as PrebuildTransactionResult;
2219+
} else {
2220+
throw results[1].reason;
2221+
}
22072222

22082223
try {
22092224
await this.baseCoin.verifyTransaction({

0 commit comments

Comments
 (0)