@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
71 lines • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = require("bignumber.js");
const errors_1 = require("@ledgerhq/errors");
const jsHelpers_1 = require("@ledgerhq/ledger-wallet-framework/bridge/jsHelpers");
const mockHelpers_1 = require("../../../bridge/mockHelpers");
const account_1 = require("../../../account");
const validateAddress_1 = require("../../../bridge/validateAddress");
const receive = (0, mockHelpers_1.makeAccountBridgeReceive)();
const createTransaction = () => ({
family: "icon",
mode: "send",
amount: new bignumber_js_1.BigNumber(0),
recipient: "",
useAllAmount: false,
fees: null,
});
const prepareTransaction = async (a, t) => t;
const estimateMaxSpendable = ({ account, parentAccount, transaction }) => {
const mainAccount = (0, account_1.getMainAccount)(account, parentAccount);
const estimatedFees = transaction?.fees || new bignumber_js_1.BigNumber(5000);
return Promise.resolve(bignumber_js_1.BigNumber.max(0, mainAccount.spendableBalance.minus(estimatedFees)));
};
const getTransactionStatus = (account, t) => {
const errors = {};
const warnings = {};
const useAllAmount = !!t.useAllAmount;
const estimatedFees = new bignumber_js_1.BigNumber(5000);
const totalSpent = useAllAmount ? account.balance : new bignumber_js_1.BigNumber(t.amount).plus(estimatedFees);
const amount = useAllAmount ? account.balance.minus(estimatedFees) : new bignumber_js_1.BigNumber(t.amount);
if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
warnings.amount = new errors_1.FeeTooHigh();
}
if (totalSpent.gt(account.balance)) {
errors.amount = new errors_1.NotEnoughBalance();
}
if (!t.recipient) {
errors.recipient = new errors_1.RecipientRequired();
}
else if ((0, mockHelpers_1.isInvalidRecipient)(t.recipient)) {
errors.recipient = new errors_1.InvalidAddress();
}
return Promise.resolve({
errors,
warnings,
estimatedFees,
amount,
totalSpent,
});
};
const accountBridge = {
estimateMaxSpendable,
createTransaction,
updateTransaction: jsHelpers_1.updateTransaction,
getTransactionStatus,
prepareTransaction,
sync: mockHelpers_1.sync,
receive,
signOperation: mockHelpers_1.signOperation,
signRawOperation: mockHelpers_1.signRawOperation,
broadcast: mockHelpers_1.broadcast,
getSerializedAddressParameters: jsHelpers_1.getSerializedAddressParameters,
validateAddress: validateAddress_1.validateAddress,
};
const currencyBridge = {
scanAccounts: mockHelpers_1.scanAccounts,
preload: (async () => { }),
hydrate: () => { },
};
exports.default = { currencyBridge, accountBridge };
//# sourceMappingURL=mock.js.map