Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/live 15540 aptos send receive fix when send max is toggled on the amount sent is different in ll and device #8763

Open
wants to merge 2 commits into
base: feat/integrate-aptos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@ import type { Account } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import { AptosAPI } from "./api";
import { APTOS_ASSET_ID } from "./constants";
import {
DEFAULT_GAS,
DEFAULT_GAS_PRICE,
getMaxSendBalance,
normalizeTransactionOptions,
} from "./logic";
import { normalizeTransactionOptions } from "./logic";
import type { Transaction } from "./types";

const buildTransaction = async (
account: Account,
transaction: Transaction,
aptosClient: AptosAPI,
): Promise<RawTransaction> => {
const amount = transaction.useAllAmount
? getMaxSendBalance(account.spendableBalance, new BigNumber(DEFAULT_GAS), new BigNumber(DEFAULT_GAS_PRICE))
: transaction.amount;

const txPayload = getPayload(transaction.recipient, amount);
const txPayload = getPayload(transaction.recipient, transaction.amount);
const txOptions = normalizeTransactionOptions(transaction.options);
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Account } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import { AptosAPI } from "./api";
import buildTransaction from "./js-buildTransaction";
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "./logic";
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL, getMaxSendBalance } from "./logic";
import type { Transaction, TransactionErrors } from "./types";

type IGetEstimatedGasReturnType = {
Expand Down Expand Up @@ -50,6 +50,14 @@ export const getFee = async (
if (account.xpub) {
try {
const publicKeyEd = new Ed25519PublicKey(account.xpub as string);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can transaction.firstEmulation be anything other than a boolean?

Wouldn't (transaction.useAllAmount && transaction.firstEmulation) suffice?

if (transaction.useAllAmount && transaction.firstEmulation === true) {
transaction.amount = getMaxSendBalance(
account.spendableBalance,
new BigNumber(DEFAULT_GAS),
new BigNumber(DEFAULT_GAS_PRICE),
);
}
const tx = await buildTransaction(account, transaction, aptosClient);
const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
const completedTx = simulation[0];
Expand Down
Loading