Skip to content

Commit

Permalink
feat: return bridge txs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Dec 12, 2024
1 parent de86356 commit 786c0c0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,12 @@ export class WalletController extends BaseController {
throw new Error(
t('background.error.notFindChain', { payTokenChainServerId })
);

const txs = [] as string[];
try {
if (shouldTwoStepApprove) {
unTriggerTxCounter.increase(3);
await this.approveToken(
const tx = await this.approveToken(
payTokenChainServerId,
payTokenId,
to,
Expand All @@ -754,14 +756,15 @@ export class WalletController extends BaseController {
gasPrice,
{ isBridge: true }
);
txs.push(tx);
unTriggerTxCounter.decrease();
}

if (shouldApprove) {
if (!shouldTwoStepApprove) {
unTriggerTxCounter.increase(2);
}
await this.approveToken(
const tx = await this.approveToken(
payTokenChainServerId,
payTokenId,
to,
Expand All @@ -775,13 +778,14 @@ export class WalletController extends BaseController {
gasPrice,
{ isBridge: true }
);
txs.push(tx);
unTriggerTxCounter.decrease();
}

if (info) {
bridgeService.addTx(chainObj.enum, data, info);
}
await this.sendRequest({
const tx = await this.sendRequest({
$ctx:
shouldApprove && payTokenId !== chainObj.nativeTokenAddress
? {
Expand All @@ -806,10 +810,13 @@ export class WalletController extends BaseController {
},
],
});
txs.push(tx);
unTriggerTxCounter.decrease();
} catch (e) {
unTriggerTxCounter.reset();
}

return txs;
};

buildBridgeToken = async (
Expand All @@ -824,7 +831,6 @@ export class WalletController extends BaseController {
gasPrice,
info,
value,
isBuild = true,
}: {
data: string;
to: string;
Expand All @@ -837,7 +843,6 @@ export class WalletController extends BaseController {
payTokenRawAmount: string;
gasPrice?: number;
info: BridgeRecord;
isBuild?: boolean;
},
$ctx?: any
) => {
Expand Down Expand Up @@ -866,7 +871,7 @@ export class WalletController extends BaseController {
},
gasPrice,
{ isBridge: true },
isBuild
true
);
txs.push(res.params[0]);
unTriggerTxCounter.decrease();
Expand All @@ -889,7 +894,7 @@ export class WalletController extends BaseController {
},
gasPrice,
{ isBridge: true },
isBuild
true
);
txs.push(res.params[0]);
unTriggerTxCounter.decrease();
Expand Down Expand Up @@ -924,7 +929,7 @@ export class WalletController extends BaseController {
},
],
},
isBuild
true
);
txs.push(res.params[0]);
unTriggerTxCounter.decrease();
Expand Down

0 comments on commit 786c0c0

Please sign in to comment.