@ledgerhq/live-common 24.1.0 → 25.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apps/support.js +1 -1
- package/lib/apps/support.js.map +1 -1
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +4 -2
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/specs.d.ts +1 -0
- package/lib/bot/specs.d.ts.map +1 -1
- package/lib/bot/specs.js +6 -1
- package/lib/bot/specs.js.map +1 -1
- package/lib/currencies/support.d.ts +1 -1
- package/lib/currencies/support.d.ts.map +1 -1
- package/lib/env.d.ts +15 -5
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +10 -0
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/errors.d.ts +101 -306
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +3 -4
- package/lib/errors.js.map +1 -1
- package/lib/errors.test.d.ts +2 -0
- package/lib/errors.test.d.ts.map +1 -0
- package/lib/errors.test.js +20 -0
- package/lib/errors.test.js.map +1 -0
- package/lib/exchange/swap/utils/index.test.js +2 -2
- package/lib/exchange/swap/utils/index.test.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +2 -4
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/descriptor.d.ts.map +1 -1
- package/lib/families/bitcoin/descriptor.js +3 -1
- package/lib/families/bitcoin/descriptor.js.map +1 -1
- package/lib/families/bitcoin/errors.d.ts +1 -3
- package/lib/families/bitcoin/errors.d.ts.map +1 -1
- package/lib/families/bitcoin/exchange.js +1 -1
- package/lib/families/bitcoin/exchange.js.map +1 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts +1 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +20 -2
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +0 -36
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.js +14 -14
- package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts.map +1 -1
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts +2 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts.map +1 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js +146 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js.map +1 -0
- package/lib/families/cardano/errors.d.ts +1 -3
- package/lib/families/cardano/errors.d.ts.map +1 -1
- package/lib/families/crypto_org/errors.d.ts +3 -9
- package/lib/families/crypto_org/errors.d.ts.map +1 -1
- package/lib/families/ethereum/exchange.js +1 -1
- package/lib/families/ethereum/exchange.js.map +1 -1
- package/lib/families/ethereum/modules/index.d.ts +1 -1
- package/lib/families/ethereum/modules/index.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +2 -2
- package/lib/families/ethereum/signOperation.js.map +1 -1
- package/lib/families/ethereum/specs.d.ts +1 -1
- package/lib/families/ethereum/specs.js +5 -5
- package/lib/families/ethereum/specs.js.map +1 -1
- package/lib/families/polkadot/errors.d.ts +12 -36
- package/lib/families/polkadot/errors.d.ts.map +1 -1
- package/lib/families/ripple/exchange.js +1 -1
- package/lib/families/ripple/exchange.js.map +1 -1
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +3 -3
- package/lib/families/solana/errors.d.ts +20 -60
- package/lib/families/solana/errors.d.ts.map +1 -1
- package/lib/families/stellar/api/horizon.d.ts +29 -7
- package/lib/families/stellar/api/horizon.d.ts.map +1 -1
- package/lib/families/stellar/api/horizon.js +114 -58
- package/lib/families/stellar/api/horizon.js.map +1 -1
- package/lib/families/stellar/api/index.d.ts +1 -1
- package/lib/families/stellar/api/index.d.ts.map +1 -1
- package/lib/families/stellar/api/index.js +5 -1
- package/lib/families/stellar/api/index.js.map +1 -1
- package/lib/families/stellar/bridge/mock.d.ts.map +1 -1
- package/lib/families/stellar/bridge/mock.js +4 -1
- package/lib/families/stellar/bridge/mock.js.map +1 -1
- package/lib/families/stellar/bridge.integration.test.js +12 -4
- package/lib/families/stellar/bridge.integration.test.js.map +1 -1
- package/lib/families/stellar/cli-transaction.d.ts +3 -1
- package/lib/families/stellar/cli-transaction.d.ts.map +1 -1
- package/lib/families/stellar/cli-transaction.js +48 -2
- package/lib/families/stellar/cli-transaction.js.map +1 -1
- package/lib/families/stellar/deviceTransactionConfig.d.ts +7 -1
- package/lib/families/stellar/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/families/stellar/deviceTransactionConfig.js +12 -1
- package/lib/families/stellar/deviceTransactionConfig.js.map +1 -1
- package/lib/families/stellar/errors.d.ts +12 -0
- package/lib/families/stellar/errors.d.ts.map +1 -0
- package/lib/families/stellar/errors.js +16 -0
- package/lib/families/stellar/errors.js.map +1 -0
- package/lib/families/stellar/exchange.js +1 -1
- package/lib/families/stellar/exchange.js.map +1 -1
- package/lib/families/stellar/js-buildTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-buildTransaction.js +34 -16
- package/lib/families/stellar/js-buildTransaction.js.map +1 -1
- package/lib/families/stellar/js-createTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-createTransaction.js +4 -1
- package/lib/families/stellar/js-createTransaction.js.map +1 -1
- package/lib/families/stellar/js-estimateMaxSpendable.js +2 -1
- package/lib/families/stellar/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/stellar/js-getTransactionStatus.d.ts.map +1 -1
- package/lib/families/stellar/js-getTransactionStatus.js +127 -57
- package/lib/families/stellar/js-getTransactionStatus.js.map +1 -1
- package/lib/families/stellar/js-prepareTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-prepareTransaction.js +25 -7
- package/lib/families/stellar/js-prepareTransaction.js.map +1 -1
- package/lib/families/stellar/js-signOperation.d.ts.map +1 -1
- package/lib/families/stellar/js-signOperation.js +33 -6
- package/lib/families/stellar/js-signOperation.js.map +1 -1
- package/lib/families/stellar/js-synchronization.d.ts +1 -1
- package/lib/families/stellar/js-synchronization.d.ts.map +1 -1
- package/lib/families/stellar/js-synchronization.js +42 -16
- package/lib/families/stellar/js-synchronization.js.map +1 -1
- package/lib/families/stellar/logic.d.ts +21 -14
- package/lib/families/stellar/logic.d.ts.map +1 -1
- package/lib/families/stellar/logic.js +158 -57
- package/lib/families/stellar/logic.js.map +1 -1
- package/lib/families/stellar/specs.d.ts.map +1 -1
- package/lib/families/stellar/specs.js +182 -7
- package/lib/families/stellar/specs.js.map +1 -1
- package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/stellar/speculos-deviceActions.js +60 -28
- package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
- package/lib/families/stellar/tokens.d.ts +11 -0
- package/lib/families/stellar/tokens.d.ts.map +1 -0
- package/lib/families/stellar/tokens.js +82 -0
- package/lib/families/stellar/tokens.js.map +1 -0
- package/lib/families/stellar/transaction.d.ts +2 -2
- package/lib/families/stellar/transaction.d.ts.map +1 -1
- package/lib/families/stellar/transaction.js +32 -6
- package/lib/families/stellar/transaction.js.map +1 -1
- package/lib/families/stellar/types.d.ts +45 -0
- package/lib/families/stellar/types.d.ts.map +1 -1
- package/lib/families/stellar/types.js +7 -1
- package/lib/families/stellar/types.js.map +1 -1
- package/lib/families/tezos/exchange.js +1 -1
- package/lib/families/tezos/exchange.js.map +1 -1
- package/lib/generated/cli-transaction.d.ts +1 -0
- package/lib/generated/cli-transaction.d.ts.map +1 -1
- package/lib/generated/specs.d.ts +1 -1
- package/lib/generated/transaction.d.ts +1 -1
- package/lib/hw/signMessage/index.d.ts +4 -3
- package/lib/hw/signMessage/index.d.ts.map +1 -1
- package/lib/hw/signMessage/index.js +25 -11
- package/lib/hw/signMessage/index.js.map +1 -1
- package/lib/hw/signMessage/index.test.d.ts +2 -0
- package/lib/hw/signMessage/index.test.d.ts.map +1 -0
- package/lib/hw/signMessage/index.test.js +126 -0
- package/lib/hw/signMessage/index.test.js.map +1 -0
- package/lib/load/speculos.d.ts.map +1 -1
- package/lib/load/speculos.js +1 -3
- package/lib/load/speculos.js.map +1 -1
- package/lib/mock/Btc.d.ts +1 -1
- package/lib/mock/Btc.d.ts.map +1 -1
- package/lib/performance.d.ts +10 -0
- package/lib/performance.d.ts.map +1 -0
- package/lib/performance.js +72 -0
- package/lib/performance.js.map +1 -0
- package/lib/performance.test.d.ts +2 -0
- package/lib/performance.test.d.ts.map +1 -0
- package/lib/performance.test.js +28 -0
- package/lib/performance.test.js.map +1 -0
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.d.ts.map +1 -1
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.js +28 -0
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.js.map +1 -1
- package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -31
- package/lib/types/currencies.d.ts +1 -1
- package/lib/types/currencies.d.ts.map +1 -1
- package/lib/walletconnect/Provider.d.ts.map +1 -1
- package/lib/walletconnect/Provider.js +1 -3
- package/lib/walletconnect/Provider.js.map +1 -1
- package/package.json +71 -19
- package/src/apps/support.ts +1 -1
- package/src/bot/index.ts +3 -1
- package/src/bot/specs.ts +7 -1
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +34 -6
- package/src/currencies/support.ts +1 -1
- package/src/env.ts +10 -0
- package/src/errors.test.ts +21 -0
- package/src/errors.ts +1 -6
- package/src/exchange/swap/utils/index.test.ts +1 -1
- package/src/families/bitcoin/datasets/bitcoin.ts +0 -2
- package/src/families/bitcoin/descriptor.ts +4 -1
- package/src/families/bitcoin/exchange.ts +1 -1
- package/src/families/bitcoin/hw-getAddress.ts +1 -1
- package/src/families/bitcoin/js-synchronisation.ts +23 -1
- package/src/families/bitcoin/wallet-btc/storage/index.ts +17 -31
- package/src/families/bitcoin/wallet-btc/storage/types.ts +1 -0
- package/src/families/bitcoin/wallet-btc/wallet.ts +1 -1
- package/src/families/bitcoin/xpub.txs.loadExport.unit.test.ts +101 -0
- package/src/families/ethereum/exchange.ts +1 -1
- package/src/families/ethereum/modules/index.ts +1 -1
- package/src/families/ethereum/signOperation.ts +2 -2
- package/src/families/ethereum/specs.ts +5 -5
- package/src/families/ripple/exchange.ts +1 -1
- package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +765 -339
- package/src/families/stellar/api/horizon.ts +115 -33
- package/src/families/stellar/api/index.ts +4 -0
- package/src/families/stellar/bridge/mock.ts +3 -0
- package/src/families/stellar/bridge.integration.test.ts +10 -2
- package/src/families/stellar/cli-transaction.ts +75 -2
- package/src/families/stellar/deviceTransactionConfig.ts +22 -0
- package/src/families/stellar/errors.ts +34 -0
- package/src/families/stellar/exchange.ts +1 -1
- package/src/families/stellar/js-buildTransaction.ts +56 -16
- package/src/families/stellar/js-createTransaction.ts +3 -0
- package/src/families/stellar/js-estimateMaxSpendable.ts +1 -1
- package/src/families/stellar/js-getTransactionStatus.ts +152 -60
- package/src/families/stellar/js-prepareTransaction.ts +4 -3
- package/src/families/stellar/js-signOperation.ts +37 -6
- package/src/families/stellar/js-synchronization.ts +53 -11
- package/src/families/stellar/logic.ts +198 -62
- package/src/families/stellar/specs.ts +227 -8
- package/src/families/stellar/speculos-deviceActions.ts +66 -22
- package/src/families/stellar/tokens.ts +118 -0
- package/src/families/stellar/transaction.ts +31 -3
- package/src/families/stellar/types.ts +52 -0
- package/src/families/tezos/exchange.ts +1 -1
- package/src/hw/signMessage/index.test.ts +128 -0
- package/src/hw/signMessage/index.ts +37 -15
- package/src/load/speculos.ts +1 -3
- package/src/mock/Btc.ts +1 -1
- package/src/performance.test.ts +26 -0
- package/src/performance.ts +61 -0
- package/src/platform/providers/RemoteLiveAppProvider/api/index.ts +6 -0
- package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +1 -32
- package/src/types/currencies.ts +1 -1
- package/src/walletconnect/Provider.tsx +4 -5
|
@@ -3,26 +3,36 @@ import {
|
|
|
3
3
|
AmountRequired,
|
|
4
4
|
NotEnoughBalance,
|
|
5
5
|
FeeNotLoaded,
|
|
6
|
-
InvalidAddress,
|
|
7
6
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
8
7
|
NotEnoughSpendableBalance,
|
|
9
8
|
NotEnoughBalanceBecauseDestinationNotCreated,
|
|
10
9
|
RecipientRequired,
|
|
10
|
+
InvalidAddress,
|
|
11
11
|
} from "@ledgerhq/errors";
|
|
12
12
|
import {
|
|
13
13
|
StellarWrongMemoFormat,
|
|
14
|
-
SourceHasMultiSign,
|
|
15
14
|
AccountAwaitingSendPendingOperations,
|
|
15
|
+
StellarAssetRequired,
|
|
16
|
+
StellarAssetNotAccepted,
|
|
17
|
+
StellarAssetNotFound,
|
|
18
|
+
StellarNotEnoughNativeBalance,
|
|
19
|
+
StellarFeeSmallerThanRecommended,
|
|
20
|
+
StellarFeeSmallerThanBase,
|
|
21
|
+
StellarNotEnoughNativeBalanceToAddTrustline,
|
|
22
|
+
StellarMuxedAccountNotExist,
|
|
23
|
+
StellarSourceHasMultiSign,
|
|
16
24
|
} from "../../errors";
|
|
25
|
+
import { findSubAccountById } from "../../account";
|
|
17
26
|
import { formatCurrencyUnit } from "../../currencies";
|
|
18
|
-
import type { Account } from "../../types";
|
|
27
|
+
import type { Account, TokenAccount } from "../../types";
|
|
19
28
|
import type { Transaction } from "./types";
|
|
20
29
|
import {
|
|
21
30
|
isAddressValid,
|
|
22
|
-
checkRecipientExist,
|
|
23
31
|
isAccountMultiSign,
|
|
24
32
|
isMemoValid,
|
|
33
|
+
getRecipientAccount,
|
|
25
34
|
} from "./logic";
|
|
35
|
+
import { BASE_RESERVE, MIN_BALANCE } from "./api";
|
|
26
36
|
|
|
27
37
|
const getTransactionStatus = async (
|
|
28
38
|
a: Account,
|
|
@@ -38,81 +48,163 @@ const getTransactionStatus = async (
|
|
|
38
48
|
const warnings: Record<string, Error> = {};
|
|
39
49
|
const useAllAmount = !!t.useAllAmount;
|
|
40
50
|
|
|
51
|
+
const destinationNotExistMessage =
|
|
52
|
+
new NotEnoughBalanceBecauseDestinationNotCreated("", {
|
|
53
|
+
minimalAmount: `${MIN_BALANCE} XLM`,
|
|
54
|
+
});
|
|
55
|
+
|
|
41
56
|
if (a.pendingOperations.length > 0) {
|
|
42
57
|
throw new AccountAwaitingSendPendingOperations();
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
if (!t.recipient) {
|
|
46
|
-
errors.recipient = new RecipientRequired("");
|
|
47
|
-
} else if (a.freshAddress === t.recipient) {
|
|
48
|
-
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
49
|
-
} else if (!isAddressValid(t.recipient)) {
|
|
50
|
-
errors.recipient = new InvalidAddress("");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (await isAccountMultiSign(a)) {
|
|
54
|
-
errors.recipient = new SourceHasMultiSign("", {
|
|
55
|
-
currencyName: a.currency.name,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
60
|
if (!t.fees || !t.baseReserve) {
|
|
60
61
|
errors.fees = new FeeNotLoaded();
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const estimatedFees = !t.fees ? new BigNumber(0) : t.fees;
|
|
64
65
|
const baseReserve = !t.baseReserve ? new BigNumber(0) : t.baseReserve;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let totalSpent = !useAllAmount
|
|
69
|
-
? amount.plus(estimatedFees)
|
|
70
|
-
: a.balance.minus(baseReserve);
|
|
71
|
-
|
|
72
|
-
if (totalSpent.gt(a.balance.minus(baseReserve))) {
|
|
73
|
-
errors.amount = new NotEnoughSpendableBalance(undefined, {
|
|
74
|
-
minimumAmount: formatCurrencyUnit(a.currency.units[0], baseReserve, {
|
|
75
|
-
disableRounding: true,
|
|
76
|
-
showCode: true,
|
|
77
|
-
}),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
66
|
+
const isAssetPayment = t.subAccountId && t.assetCode && t.assetIssuer;
|
|
67
|
+
const nativeBalance = a.balance;
|
|
68
|
+
const nativeAmountAvailable = a.spendableBalance.minus(estimatedFees);
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
) {
|
|
85
|
-
errors.amount = new NotEnoughBalance();
|
|
86
|
-
}
|
|
70
|
+
let amount = new BigNumber(0);
|
|
71
|
+
let maxAmount = new BigNumber(0);
|
|
72
|
+
let totalSpent = new BigNumber(0);
|
|
87
73
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(amount.lt(0) || totalSpent.gt(a.balance))
|
|
92
|
-
) {
|
|
93
|
-
errors.amount = new NotEnoughBalance();
|
|
94
|
-
totalSpent = new BigNumber(0);
|
|
95
|
-
amount = new BigNumber(0);
|
|
74
|
+
// Enough native balance to cover transaction (with required reserve + fees)
|
|
75
|
+
if (!errors.amount && nativeAmountAvailable.lt(0)) {
|
|
76
|
+
errors.amount = new StellarNotEnoughNativeBalance();
|
|
96
77
|
}
|
|
97
78
|
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
// Entered fee is smaller than base fee
|
|
80
|
+
if (estimatedFees.lt(t.networkInfo?.baseFee || 0)) {
|
|
81
|
+
errors.transaction = new StellarFeeSmallerThanBase();
|
|
82
|
+
// Entered fee is smaller than recommended
|
|
83
|
+
} else if (estimatedFees.lt(t.networkInfo?.fees || 0)) {
|
|
84
|
+
warnings.transaction = new StellarFeeSmallerThanRecommended();
|
|
100
85
|
}
|
|
101
86
|
|
|
102
|
-
//
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
t.
|
|
106
|
-
|
|
107
|
-
|
|
87
|
+
// Operation specific checks
|
|
88
|
+
if (t.mode === "changeTrust") {
|
|
89
|
+
// Check asset provided
|
|
90
|
+
if (!t.assetCode || !t.assetIssuer) {
|
|
91
|
+
// This is unlikely
|
|
92
|
+
errors.transaction = new StellarAssetRequired("");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Has enough native balance to add new trustline
|
|
96
|
+
if (nativeAmountAvailable.minus(BASE_RESERVE).lt(0)) {
|
|
97
|
+
errors.amount = new StellarNotEnoughNativeBalanceToAddTrustline();
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
// Payment
|
|
101
|
+
// Check recipient address
|
|
102
|
+
if (!t.recipient) {
|
|
103
|
+
errors.recipient = new RecipientRequired("");
|
|
104
|
+
} else if (!isAddressValid(t.recipient)) {
|
|
105
|
+
errors.recipient = new InvalidAddress("");
|
|
106
|
+
} else if (a.freshAddress === t.recipient) {
|
|
107
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const recipientAccount = await getRecipientAccount({
|
|
108
111
|
account: a,
|
|
109
112
|
recipient: t.recipient,
|
|
110
|
-
})) &&
|
|
111
|
-
amount.lt(10000000)
|
|
112
|
-
) {
|
|
113
|
-
errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
|
|
114
|
-
minimalAmount: "1 XLM",
|
|
115
113
|
});
|
|
114
|
+
|
|
115
|
+
// Check recipient account
|
|
116
|
+
if (!recipientAccount?.id && !errors.recipient && !warnings.recipient) {
|
|
117
|
+
if (recipientAccount?.isMuxedAccount) {
|
|
118
|
+
errors.recipient = new StellarMuxedAccountNotExist();
|
|
119
|
+
} else {
|
|
120
|
+
if (isAssetPayment) {
|
|
121
|
+
errors.recipient = destinationNotExistMessage;
|
|
122
|
+
} else {
|
|
123
|
+
warnings.recipient = destinationNotExistMessage;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Asset payment
|
|
129
|
+
if (isAssetPayment) {
|
|
130
|
+
const asset = findSubAccountById(a, t.subAccountId || "") as TokenAccount;
|
|
131
|
+
|
|
132
|
+
if (asset === null) {
|
|
133
|
+
// This is unlikely
|
|
134
|
+
throw new StellarAssetNotFound();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Check recipient account accepts asset
|
|
138
|
+
if (
|
|
139
|
+
recipientAccount?.id &&
|
|
140
|
+
!errors.recipient &&
|
|
141
|
+
!warnings.recipient &&
|
|
142
|
+
!recipientAccount.assetIds.includes(`${t.assetCode}:${t.assetIssuer}`)
|
|
143
|
+
) {
|
|
144
|
+
errors.recipient = new StellarAssetNotAccepted("", {
|
|
145
|
+
assetCode: t.assetCode,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const assetBalance = asset?.balance || new BigNumber(0);
|
|
150
|
+
|
|
151
|
+
maxAmount = asset?.spendableBalance || assetBalance;
|
|
152
|
+
amount = useAllAmount ? maxAmount : t.amount;
|
|
153
|
+
totalSpent = amount;
|
|
154
|
+
|
|
155
|
+
if (!errors.amount && amount.gt(assetBalance)) {
|
|
156
|
+
errors.amount = new NotEnoughBalance();
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
// Native payment
|
|
160
|
+
maxAmount = nativeAmountAvailable;
|
|
161
|
+
amount = useAllAmount ? maxAmount : t.amount || 0;
|
|
162
|
+
|
|
163
|
+
if (amount.gt(maxAmount)) {
|
|
164
|
+
errors.amount = new NotEnoughBalance();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
totalSpent = useAllAmount
|
|
168
|
+
? nativeAmountAvailable
|
|
169
|
+
: t.amount.plus(estimatedFees);
|
|
170
|
+
|
|
171
|
+
// Need to send at least 1 XLM to create an account
|
|
172
|
+
if (
|
|
173
|
+
!errors.recipient &&
|
|
174
|
+
!recipientAccount?.id &&
|
|
175
|
+
!errors.amount &&
|
|
176
|
+
amount.lt(10000000)
|
|
177
|
+
) {
|
|
178
|
+
errors.amount = destinationNotExistMessage;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (totalSpent.gt(nativeBalance.minus(baseReserve))) {
|
|
182
|
+
errors.amount = new NotEnoughSpendableBalance(undefined, {
|
|
183
|
+
minimumAmount: formatCurrencyUnit(a.currency.units[0], baseReserve, {
|
|
184
|
+
disableRounding: true,
|
|
185
|
+
showCode: true,
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (
|
|
191
|
+
!errors.recipient &&
|
|
192
|
+
!errors.amount &&
|
|
193
|
+
(amount.lt(0) || totalSpent.gt(nativeBalance))
|
|
194
|
+
) {
|
|
195
|
+
errors.amount = new NotEnoughBalance();
|
|
196
|
+
totalSpent = new BigNumber(0);
|
|
197
|
+
amount = new BigNumber(0);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!errors.amount && amount.eq(0)) {
|
|
201
|
+
errors.amount = new AmountRequired();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (await isAccountMultiSign(a)) {
|
|
207
|
+
errors.recipient = new StellarSourceHasMultiSign();
|
|
116
208
|
}
|
|
117
209
|
|
|
118
210
|
if (t.memoType && t.memoValue && !isMemoValid(t.memoType, t.memoValue)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import invariant from "invariant";
|
|
2
2
|
import { fetchAccountNetworkInfo } from "./api";
|
|
3
3
|
import type { Account } from "../../types";
|
|
4
|
-
|
|
4
|
+
import { getAssetCodeIssuer } from "./logic";
|
|
5
5
|
import type { Transaction } from "./types";
|
|
6
6
|
|
|
7
7
|
const prepareTransaction = async (
|
|
@@ -12,16 +12,17 @@ const prepareTransaction = async (
|
|
|
12
12
|
invariant(networkInfo.family === "stellar", "stellar networkInfo expected");
|
|
13
13
|
const fees = t.fees || networkInfo.fees;
|
|
14
14
|
const baseReserve = t.baseReserve || networkInfo.baseReserve;
|
|
15
|
+
const [assetCode, assetIssuer] = getAssetCodeIssuer(t);
|
|
15
16
|
|
|
16
17
|
if (
|
|
17
18
|
t.networkInfo !== networkInfo ||
|
|
18
19
|
t.fees !== fees ||
|
|
19
20
|
t.baseReserve !== baseReserve
|
|
20
21
|
) {
|
|
21
|
-
return { ...t, networkInfo, fees, baseReserve };
|
|
22
|
+
return { ...t, networkInfo, fees, baseReserve, assetCode, assetIssuer };
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
return t;
|
|
25
|
+
return { ...t, assetCode, assetIssuer };
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export default prepareTransaction;
|
|
@@ -7,6 +7,7 @@ import { withDevice } from "../../hw/deviceAccess";
|
|
|
7
7
|
import type { Transaction } from "./types";
|
|
8
8
|
import { buildTransaction } from "./js-buildTransaction";
|
|
9
9
|
import { fetchSequence } from "./api";
|
|
10
|
+
import { getAmountValue } from "./logic";
|
|
10
11
|
|
|
11
12
|
const buildOptimisticOperation = async (
|
|
12
13
|
account: Account,
|
|
@@ -14,14 +15,15 @@ const buildOptimisticOperation = async (
|
|
|
14
15
|
): Promise<Operation> => {
|
|
15
16
|
const transactionSequenceNumber = await fetchSequence(account);
|
|
16
17
|
const fees = transaction.fees ?? new BigNumber(0);
|
|
18
|
+
const type = transaction.mode === "changeTrust" ? "OPT_IN" : "OUT";
|
|
19
|
+
|
|
17
20
|
const operation: Operation = {
|
|
18
|
-
id: `${account.id}
|
|
21
|
+
id: `${account.id}--${type}`,
|
|
19
22
|
hash: "",
|
|
20
|
-
type
|
|
21
|
-
value:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: transaction.amount.plus(fees),
|
|
23
|
+
type,
|
|
24
|
+
value: transaction.subAccountId
|
|
25
|
+
? fees
|
|
26
|
+
: getAmountValue(account, transaction, fees),
|
|
25
27
|
fee: fees,
|
|
26
28
|
blockHash: null,
|
|
27
29
|
blockHeight: null,
|
|
@@ -33,6 +35,35 @@ const buildOptimisticOperation = async (
|
|
|
33
35
|
transactionSequenceNumber: transactionSequenceNumber?.plus(1).toNumber(),
|
|
34
36
|
extra: {},
|
|
35
37
|
};
|
|
38
|
+
|
|
39
|
+
const { subAccountId } = transaction;
|
|
40
|
+
const { subAccounts } = account;
|
|
41
|
+
|
|
42
|
+
const tokenAccount = !subAccountId
|
|
43
|
+
? null
|
|
44
|
+
: subAccounts && subAccounts.find((ta) => ta.id === subAccountId);
|
|
45
|
+
|
|
46
|
+
if (tokenAccount && subAccountId) {
|
|
47
|
+
operation.subOperations = [
|
|
48
|
+
{
|
|
49
|
+
id: `${subAccountId}--OUT`,
|
|
50
|
+
hash: "",
|
|
51
|
+
type: "OUT",
|
|
52
|
+
value: transaction.useAllAmount
|
|
53
|
+
? tokenAccount.balance
|
|
54
|
+
: transaction.amount,
|
|
55
|
+
fee: new BigNumber(0),
|
|
56
|
+
blockHash: null,
|
|
57
|
+
blockHeight: null,
|
|
58
|
+
senders: [account.freshAddress],
|
|
59
|
+
recipients: [transaction.recipient],
|
|
60
|
+
accountId: subAccountId,
|
|
61
|
+
date: new Date(),
|
|
62
|
+
extra: {},
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
36
67
|
return operation;
|
|
37
68
|
};
|
|
38
69
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { Operation } from "../../types";
|
|
1
2
|
import { encodeAccountId } from "../../account";
|
|
2
3
|
import type { GetAccountShape } from "../../bridge/jsHelpers";
|
|
3
4
|
import { makeScanAccounts, makeSync, mergeOps } from "../../bridge/jsHelpers";
|
|
4
5
|
import { fetchAccount, fetchOperations } from "./api";
|
|
6
|
+
import { buildSubAccounts } from "./tokens";
|
|
7
|
+
import { inferSubOperations } from "../../account";
|
|
5
8
|
|
|
6
|
-
const getAccountShape: GetAccountShape = async (info) => {
|
|
7
|
-
const { address,
|
|
9
|
+
const getAccountShape: GetAccountShape = async (info, syncConfig) => {
|
|
10
|
+
const { address, currency, initialAccount, derivationMode } = info;
|
|
8
11
|
const accountId = encodeAccountId({
|
|
9
12
|
type: "js",
|
|
10
13
|
version: "2",
|
|
@@ -12,23 +15,62 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
12
15
|
xpubOrAddress: address,
|
|
13
16
|
derivationMode,
|
|
14
17
|
});
|
|
15
|
-
const
|
|
16
|
-
const startAt = oldOperations.length
|
|
17
|
-
? (oldOperations[0].blockHeight || 0) + 1
|
|
18
|
-
: 0;
|
|
19
|
-
const { blockHeight, balance, spendableBalance } = await fetchAccount(
|
|
18
|
+
const { blockHeight, balance, spendableBalance, assets } = await fetchAccount(
|
|
20
19
|
address
|
|
21
20
|
);
|
|
22
|
-
|
|
23
|
-
const
|
|
21
|
+
|
|
22
|
+
const oldOperations = initialAccount?.operations || [];
|
|
23
|
+
const lastPagingToken = oldOperations[0]?.extra?.pagingToken || 0;
|
|
24
|
+
|
|
25
|
+
const newOperations =
|
|
26
|
+
(await fetchOperations({
|
|
27
|
+
accountId,
|
|
28
|
+
addr: address,
|
|
29
|
+
order: "asc",
|
|
30
|
+
cursor: lastPagingToken,
|
|
31
|
+
})) || [];
|
|
32
|
+
|
|
33
|
+
const allOperations = mergeOps(oldOperations, newOperations);
|
|
34
|
+
const assetOperations: Operation[] = [];
|
|
35
|
+
|
|
36
|
+
allOperations.forEach((op) => {
|
|
37
|
+
if (
|
|
38
|
+
op?.extra?.assetCode &&
|
|
39
|
+
op?.extra?.assetIssuer &&
|
|
40
|
+
!["OPT_IN", "OPT_OUT"].includes(op.type)
|
|
41
|
+
) {
|
|
42
|
+
assetOperations.push(op);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const subAccounts =
|
|
47
|
+
buildSubAccounts({
|
|
48
|
+
currency,
|
|
49
|
+
accountId,
|
|
50
|
+
assets,
|
|
51
|
+
syncConfig,
|
|
52
|
+
operations: assetOperations,
|
|
53
|
+
}) || [];
|
|
54
|
+
|
|
24
55
|
const shape = {
|
|
25
56
|
id: accountId,
|
|
26
57
|
balance,
|
|
27
58
|
spendableBalance,
|
|
28
|
-
operationsCount:
|
|
59
|
+
operationsCount: allOperations.length,
|
|
29
60
|
blockHeight,
|
|
61
|
+
subAccounts,
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
...shape,
|
|
65
|
+
operations: allOperations.map((op) => {
|
|
66
|
+
const subOperations = inferSubOperations(op.hash, subAccounts);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
...op,
|
|
70
|
+
subOperations,
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
30
73
|
};
|
|
31
|
-
return { ...shape, operations };
|
|
32
74
|
};
|
|
33
75
|
|
|
34
76
|
export const sync = makeSync({ getAccountShape });
|