Skip to content

Commit

Permalink
out -> estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
lvndry committed Sep 28, 2023
1 parent ddbc903 commit b15c08a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions libs/ledger-live-common/src/families/tezos/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,24 @@ const prepareTransaction = async (
}

try {
let out: Estimate;
let estimate: Estimate;
switch (transaction.mode) {
case "send":
out = await tezos.estimate.transfer({
estimate = await tezos.estimate.transfer({
mutez: true,
to: transaction.recipient,
amount: amount.toNumber(),
storageLimit: DEFAULT_STORAGE_LIMIT.ORIGINATION, // https://github.com/TezTech/eztz/blob/master/PROTO_003_FEES.md for originating an account
});
break;
case "delegate":
out = await tezos.estimate.setDelegate({
estimate = await tezos.estimate.setDelegate({
source: account.freshAddress,
delegate: transaction.recipient,
});
break;
case "undelegate":
out = await tezos.estimate.setDelegate({
estimate = await tezos.estimate.setDelegate({
source: account.freshAddress,
});
break;
Expand All @@ -246,7 +246,7 @@ const prepareTransaction = async (
}

if (tx.useAllAmount) {
const totalFees = out.suggestedFeeMutez + out.burnFeeMutez;
const totalFees = estimate.suggestedFeeMutez + estimate.burnFeeMutez;
const maxAmount = account.balance
.minus(totalFees + (tezosResources.revealed ? 0 : DEFAULT_FEE.REVEAL))
.toNumber();
Expand All @@ -258,17 +258,17 @@ const prepareTransaction = async (
const increasedFee = (gasBuffer: number, opSize: number) => {
return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
};
const incr = increasedFee(gasBuffer, Number(out.opSize));
tx.fees = new BigNumber(out.suggestedFeeMutez + incr);
tx.gasLimit = new BigNumber(out.gasLimit + gasBuffer);
const incr = increasedFee(gasBuffer, Number(estimate.opSize));
tx.fees = new BigNumber(estimate.suggestedFeeMutez + incr);
tx.gasLimit = new BigNumber(estimate.gasLimit + gasBuffer);
tx.amount = maxAmount - incr > 0 ? new BigNumber(maxAmount - incr) : new BigNumber(0);
} else {
tx.fees = new BigNumber(out.suggestedFeeMutez);
tx.gasLimit = new BigNumber(out.gasLimit);
tx.storageLimit = new BigNumber(out.storageLimit);
tx.fees = new BigNumber(estimate.suggestedFeeMutez);
tx.gasLimit = new BigNumber(estimate.gasLimit);
tx.storageLimit = new BigNumber(estimate.storageLimit);
}

tx.storageLimit = new BigNumber(out.storageLimit);
tx.storageLimit = new BigNumber(estimate.storageLimit);
tx.estimatedFees = tx.fees;
if (!tezosResources.revealed) {
tx.estimatedFees = tx.estimatedFees.plus(DEFAULT_FEE.REVEAL);
Expand Down

0 comments on commit b15c08a

Please sign in to comment.