Skip to content

Commit

Permalink
chore: avoid re-asignement
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Jun 3, 2024
1 parent d041495 commit 2aa84c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
11 changes: 4 additions & 7 deletions packages/widget/src/controllers/transfers/evm/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
import { Web3Provider } from '@ethersproject/providers';
import type { UnsignedTransaction, BigNumber } from 'ethers';
import { constants, utils } from 'ethers';
import type { SubstrateFee } from '@buildwithsygma/sygma-sdk-core/substrate';
import type { Eip1193Provider } from '../../../interfaces';

/**
Expand All @@ -27,7 +26,6 @@ export async function buildEvmFungibleTransactions({
provider,
providerChainId,
env,
fee,
pendingEvmApprovalTransactions,
pendingTransferTransaction
}: {
Expand All @@ -39,7 +37,6 @@ export async function buildEvmFungibleTransactions({
provider: Eip1193Provider;
providerChainId: number;
env: Environment;
fee: EvmFee | SubstrateFee | null;
pendingEvmApprovalTransactions: UnsignedTransaction[];
pendingTransferTransaction: UnsignedTransaction;
sourceNetwork: Domain | null;
Expand Down Expand Up @@ -94,21 +91,21 @@ export async function buildEvmFungibleTransactions({
resourceId,
resourceAmount.toString()
);
fee = await evmTransfer.getFee(transfer);
const transferFee = await evmTransfer.getFee(transfer);

pendingEvmApprovalTransactions = await evmTransfer.buildApprovals(
transfer,
fee
transferFee
);

pendingTransferTransaction = await evmTransfer.buildTransferTransaction(
transfer,
fee
transferFee
);
return {
pendingEvmApprovalTransactions,
pendingTransferTransaction,
fee,
fee: transferFee,
resourceAmount
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ export class FungibleTokenTransferController implements ReactiveController {
provider: provider!,
providerChainId: providerChainId!,
env: this.env,
fee: this.fee,
pendingEvmApprovalTransactions:
this.pendingEvmApprovalTransactions,
pendingTransferTransaction: this
Expand Down Expand Up @@ -614,7 +613,6 @@ export class FungibleTokenTransferController implements ReactiveController {
destinationAddress: this.destinationAddress!,
resourceId: this.selectedResource!.resourceId,
resourceAmount: this.resourceAmount,
fee: this.fee as SubstrateFee,
pendingTransferTransaction: this
.pendingTransferTransaction as SubstrateTransaction
});
Expand Down
10 changes: 4 additions & 6 deletions packages/widget/src/controllers/transfers/substrate/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function buildSubstrateFungibleTransactions({
destinationAddress,
resourceId,
resourceAmount,
fee,
pendingTransferTransaction
}: {
address: string;
Expand All @@ -23,7 +22,6 @@ export async function buildSubstrateFungibleTransactions({
destinationAddress: string;
resourceId: string;
resourceAmount: BigNumber;
fee: SubstrateFee;
pendingTransferTransaction: SubstrateTransaction;
}): Promise<{
pendingTransferTransaction: SubstrateTransaction;
Expand All @@ -41,20 +39,20 @@ export async function buildSubstrateFungibleTransactions({
String(resourceAmount)
);

fee = await substrateTransfer.getFee(transfer);
const transferFee = await substrateTransfer.getFee(transfer);

if (resourceAmount.toString() === transfer.details.amount.toString()) {
resourceAmount = resourceAmount.sub(fee.fee.toString());
resourceAmount = resourceAmount.sub(transferFee.fee.toString());
}

pendingTransferTransaction = substrateTransfer.buildTransferTransaction(
transfer,
fee
transferFee
);

return {
pendingTransferTransaction,
resourceAmount,
fee
fee: transferFee
};
}

0 comments on commit 2aa84c3

Please sign in to comment.