@ledgerhq/coin-sui 0.11.0 → 0.12.0-nightly.0
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/.eslintrc.js +1 -0
- package/.unimportedrc.json +1 -0
- package/CHANGELOG.md +11 -0
- package/index.d.ts +0 -1
- package/jest.config.js +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +3 -0
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +31 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +3 -1
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/buildTransaction.test.js +4 -0
- package/lib/bridge/buildTransaction.test.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +15 -3
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.test.js +27 -0
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +13 -1
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getOperationExtra.d.ts +2 -0
- package/lib/bridge/getOperationExtra.d.ts.map +1 -0
- package/lib/bridge/getOperationExtra.js +6 -0
- package/lib/bridge/getOperationExtra.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +45 -20
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/preload.d.ts.map +1 -1
- package/lib/bridge/preload.js +5 -3
- package/lib/bridge/preload.js.map +1 -1
- package/lib/bridge/preload.test.js +13 -217
- package/lib/bridge/preload.test.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +5 -2
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/synchronisation.test.js +355 -7
- package/lib/bridge/synchronisation.test.js.map +1 -1
- package/lib/bridge/utils.d.ts +1 -1
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +22 -0
- package/lib/bridge/utils.js.map +1 -1
- package/lib/constants.d.ts +4 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +7 -0
- package/lib/constants.js.map +1 -0
- package/lib/errors.d.ts +13 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +21 -0
- package/lib/errors.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +5 -10
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +14 -2
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/index.d.ts +2 -1
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +3 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/stake.d.ts +3 -0
- package/lib/logic/stake.d.ts.map +1 -0
- package/lib/logic/stake.js +12 -0
- package/lib/logic/stake.js.map +1 -0
- package/lib/network/index.d.ts +5 -4
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +5 -3
- package/lib/network/index.js.map +1 -1
- package/lib/network/sdk.d.ts +5 -3
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +148 -26
- package/lib/network/sdk.js.map +1 -1
- package/lib/network/sdk.test.js +491 -6
- package/lib/network/sdk.test.js.map +1 -1
- package/lib/types/bridge.d.ts +33 -6
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +3 -0
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +31 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +3 -1
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/buildTransaction.test.js +4 -0
- package/lib-es/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +15 -3
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.test.js +27 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +13 -1
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getOperationExtra.d.ts +2 -0
- package/lib-es/bridge/getOperationExtra.d.ts.map +1 -0
- package/lib-es/bridge/getOperationExtra.js +2 -0
- package/lib-es/bridge/getOperationExtra.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +46 -21
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/preload.d.ts.map +1 -1
- package/lib-es/bridge/preload.js +5 -3
- package/lib-es/bridge/preload.js.map +1 -1
- package/lib-es/bridge/preload.test.js +14 -218
- package/lib-es/bridge/preload.test.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +6 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/synchronisation.test.js +332 -7
- package/lib-es/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +1 -1
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +22 -0
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/constants.d.ts +4 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +4 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/errors.d.ts +13 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +18 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +5 -10
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +14 -2
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -1
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +1 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/stake.d.ts +3 -0
- package/lib-es/logic/stake.d.ts.map +1 -0
- package/lib-es/logic/stake.js +8 -0
- package/lib-es/logic/stake.js.map +1 -0
- package/lib-es/network/index.d.ts +5 -4
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +4 -3
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/sdk.d.ts +5 -3
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +144 -25
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/network/sdk.test.js +491 -6
- package/lib-es/network/sdk.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts +33 -6
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +17 -9
- package/src/bridge/broadcast.ts +3 -0
- package/src/bridge/buildOptimisticOperation.ts +47 -4
- package/src/bridge/buildTransaction.test.ts +4 -0
- package/src/bridge/buildTransaction.ts +3 -1
- package/src/bridge/estimateMaxSpendable.test.ts +33 -0
- package/src/bridge/estimateMaxSpendable.ts +17 -3
- package/src/bridge/getFeesForTransaction.ts +14 -1
- package/src/bridge/getOperationExtra.ts +1 -0
- package/src/bridge/getTransactionStatus.ts +53 -21
- package/src/bridge/preload.test.ts +13 -279
- package/src/bridge/preload.ts +5 -3
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/synchronisation.test.ts +389 -7
- package/src/bridge/synchronisation.ts +6 -3
- package/src/bridge/utils.ts +25 -1
- package/src/constants.ts +4 -0
- package/src/errors.ts +21 -0
- package/src/logic/craftTransaction.ts +6 -9
- package/src/logic/estimateFees.ts +16 -1
- package/src/logic/index.ts +2 -1
- package/src/logic/stake.ts +9 -0
- package/src/network/index.ts +6 -3
- package/src/network/sdk.test.ts +538 -10
- package/src/network/sdk.ts +179 -31
- package/src/types/bridge.ts +32 -6
|
@@ -19,5 +19,32 @@ describe("estimateMaxSpendable", () => {
|
|
|
19
19
|
expect(mockEstimateFees).toHaveBeenCalledTimes(1);
|
|
20
20
|
expect(result).toEqual(balance.minus(fees));
|
|
21
21
|
});
|
|
22
|
+
it("should apply delegation-specific constraints and gas reservation", async () => {
|
|
23
|
+
// GIVEN
|
|
24
|
+
const balance = new BigNumber("5000000000"); // 5 SUI
|
|
25
|
+
const account = createFixtureAccount({ spendableBalance: balance });
|
|
26
|
+
const transaction = createFixtureTransaction({ mode: "delegate" });
|
|
27
|
+
const fees = new BigNumber("100000000"); // 0.1 SUI
|
|
28
|
+
mockEstimateFees.mockResolvedValue(fees);
|
|
29
|
+
// WHEN
|
|
30
|
+
const result = await estimateMaxSpendable({ account, transaction });
|
|
31
|
+
// THEN
|
|
32
|
+
// Should deduct fees (0.1 SUI) + gas reserve (0.1 SUI) = 0.2 SUI from 5 SUI = 4.8 SUI
|
|
33
|
+
const expectedAmount = balance.minus(fees).minus(new BigNumber("100000000")); // 4.8 SUI
|
|
34
|
+
expect(result).toEqual(expectedAmount);
|
|
35
|
+
});
|
|
36
|
+
it("should return 0 for delegation when balance is below minimum threshold", async () => {
|
|
37
|
+
// GIVEN
|
|
38
|
+
const balance = new BigNumber("800000000"); // 0.8 SUI (below 1 SUI minimum after fees/reserve)
|
|
39
|
+
const account = createFixtureAccount({ spendableBalance: balance });
|
|
40
|
+
const transaction = createFixtureTransaction({ mode: "delegate" });
|
|
41
|
+
const fees = new BigNumber("100000000"); // 0.1 SUI
|
|
42
|
+
mockEstimateFees.mockResolvedValue(fees);
|
|
43
|
+
// WHEN
|
|
44
|
+
const result = await estimateMaxSpendable({ account, transaction });
|
|
45
|
+
// THEN
|
|
46
|
+
// After deducting fees (0.1) + gas reserve (0.1) = 0.6 SUI, which is < 1 SUI minimum
|
|
47
|
+
expect(result).toEqual(new BigNumber(0));
|
|
48
|
+
});
|
|
22
49
|
});
|
|
23
50
|
//# sourceMappingURL=estimateMaxSpendable.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.test.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAGzF,MAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3B,YAAY,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE;CACvC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,sBAAsB,EAAE,GA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AAU,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CAC1B,GAAG,OAAO,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"getFeesForTransaction.d.ts","sourceRoot":"","sources":["../../src/bridge/getFeesForTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKxD;;;;;;;GAOG;AACH,wBAA8B,gBAAgB,CAAC,EAC7C,OAAO,EACP,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CAC1B,GAAG,OAAO,CAAC,SAAS,CAAC,CAsCrB"}
|
|
@@ -27,11 +27,23 @@ export default async function getEstimatedFees({ account, transaction, }) {
|
|
|
27
27
|
};
|
|
28
28
|
const subAccount = findSubAccountById(account, transaction.subAccountId ?? "");
|
|
29
29
|
const asset = toSuiAsset(subAccount?.token.contractAddress ?? DEFAULT_COIN_TYPE);
|
|
30
|
+
let transactionType;
|
|
31
|
+
switch (transaction.mode) {
|
|
32
|
+
case "delegate":
|
|
33
|
+
transactionType = "delegate";
|
|
34
|
+
break;
|
|
35
|
+
case "undelegate":
|
|
36
|
+
transactionType = "undelegate";
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
transactionType = "send";
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
30
42
|
const fees = await estimateFees({
|
|
31
43
|
recipient: getAbandonSeedAddress(account.currency.id),
|
|
32
44
|
sender: account.freshAddress,
|
|
33
45
|
amount: BigInt(t.amount.toString()),
|
|
34
|
-
type:
|
|
46
|
+
type: transactionType,
|
|
35
47
|
asset,
|
|
36
48
|
});
|
|
37
49
|
return new BigNumber(fees.toString());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFeesForTransaction.js","sourceRoot":"","sources":["../../src/bridge/getFeesForTransaction.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ED,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC;QAC9B,SAAS,EAAE,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,MAAM,EAAE,OAAO,CAAC,YAAY;QAC5B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,EAAE,eAAe;QACrB,KAAK;KACN,CAAC,CAAC;IACH,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationExtra.d.ts","sourceRoot":"","sources":["../../src/bridge/getOperationExtra.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationExtra.js","sourceRoot":"","sources":["../../src/bridge/getOperationExtra.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAU3E;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAC9C,WAAW,EACX,UAAU,EACV,iBAAiB,CAClB,CAAC,sBAAsB,CA6EvB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import { NotEnoughBalance, NotEnoughBalanceInParentAccount, RecipientRequired,
|
|
2
|
+
import { NotEnoughBalance, NotEnoughBalanceInParentAccount, RecipientRequired, InvalidAddressBecauseDestinationIsAlsoSource, AmountRequired, FeeNotLoaded, FeeTooHigh, InvalidAddress, } from "@ledgerhq/errors";
|
|
3
3
|
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
5
5
|
import { ensureAddressFormat } from "../utils";
|
|
6
|
+
import { OneSuiMinForStake, OneSuiMinForUnstake, OneSuiMinForUnstakeToBeLeft, SomeSuiForUnstake, } from "../errors";
|
|
7
|
+
import { ONE_SUI } from "../constants";
|
|
6
8
|
/**
|
|
7
9
|
* Get the status of a transaction.
|
|
8
10
|
* @function getTransactionStatus
|
|
@@ -21,34 +23,57 @@ export const getTransactionStatus = async (account, transaction) => {
|
|
|
21
23
|
const subAccount = findSubAccountById(account, transaction.subAccountId);
|
|
22
24
|
accountBalance = subAccount?.balance ?? new BigNumber(0);
|
|
23
25
|
}
|
|
24
|
-
if (amount.lte(0)) {
|
|
26
|
+
if (amount.lte(0) && !transaction.useAllAmount) {
|
|
25
27
|
errors.amount = new AmountRequired();
|
|
26
28
|
}
|
|
27
29
|
else if (estimatedFees.times(10).gt(amount) && !transaction.subAccountId) {
|
|
28
30
|
warnings.feeTooHigh = new FeeTooHigh();
|
|
29
31
|
}
|
|
30
|
-
if (!transaction.
|
|
31
|
-
errors.
|
|
32
|
-
}
|
|
33
|
-
else if (!isValidSuiAddress(transaction.recipient)) {
|
|
34
|
-
errors.recipient = new InvalidAddress(undefined, {
|
|
35
|
-
currencyName: account.currency.name,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (ensureAddressFormat(account.freshAddress) === ensureAddressFormat(transaction.recipient)) {
|
|
39
|
-
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
40
|
-
}
|
|
41
|
-
if (transaction.subAccountId && estimatedFees.gt(account.balance)) {
|
|
42
|
-
errors.amount = new NotEnoughBalanceInParentAccount();
|
|
32
|
+
if (!transaction.fees) {
|
|
33
|
+
errors.fees = new FeeNotLoaded();
|
|
43
34
|
}
|
|
44
|
-
if (
|
|
45
|
-
|
|
35
|
+
if (transaction.mode === "undelegate") {
|
|
36
|
+
const stakes = account.suiResources?.stakes?.flatMap(({ stakes }) => stakes) ?? [];
|
|
37
|
+
const stake = stakes.find(s => s.stakedSuiId === transaction.stakedSuiId);
|
|
38
|
+
if (stake) {
|
|
39
|
+
if (!transaction.useAllAmount && amount.lt(ONE_SUI)) {
|
|
40
|
+
errors.amount = new OneSuiMinForUnstake();
|
|
41
|
+
}
|
|
42
|
+
const stakeLeft = BigNumber(stake?.principal).minus(amount);
|
|
43
|
+
if (!transaction.useAllAmount && stakeLeft.lt(ONE_SUI) && stakeLeft.gt(0)) {
|
|
44
|
+
errors.amount = new OneSuiMinForUnstakeToBeLeft();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
else {
|
|
49
|
+
if (!transaction.recipient) {
|
|
50
|
+
errors.recipient = new RecipientRequired();
|
|
51
|
+
}
|
|
52
|
+
else if (!isValidSuiAddress(transaction.recipient)) {
|
|
53
|
+
errors.recipient = new InvalidAddress(undefined, {
|
|
54
|
+
currencyName: account.currency.name,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (ensureAddressFormat(account.freshAddress) === ensureAddressFormat(transaction.recipient)) {
|
|
58
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
59
|
+
}
|
|
60
|
+
if (totalSpent.eq(0) && transaction.useAllAmount) {
|
|
61
|
+
errors.amount = new NotEnoughBalance();
|
|
62
|
+
}
|
|
63
|
+
if (transaction.subAccountId && estimatedFees.gt(account.balance)) {
|
|
64
|
+
errors.amount = new NotEnoughBalanceInParentAccount();
|
|
65
|
+
}
|
|
66
|
+
if (totalSpent.gt(accountBalance)) {
|
|
67
|
+
errors.amount = new NotEnoughBalance();
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
|
-
if (
|
|
51
|
-
|
|
70
|
+
if (transaction.mode === "delegate") {
|
|
71
|
+
if (amount.lt(new BigNumber(ONE_SUI))) {
|
|
72
|
+
errors.amount = new OneSuiMinForStake();
|
|
73
|
+
}
|
|
74
|
+
// 0.1 SUI
|
|
75
|
+
if (account.balance.minus(transaction.amount).lt(ONE_SUI / 10))
|
|
76
|
+
warnings.amount = new SomeSuiForUnstake();
|
|
52
77
|
}
|
|
53
78
|
return {
|
|
54
79
|
errors,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAC/B,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAC/B,iBAAiB,EACjB,4CAA4C,EAC5C,cAAc,EACd,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;A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AAC,CAAC,MAAM;QAChD,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../../src/bridge/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../../src/bridge/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAa/C,wBAAgB,wBAAwB,IAAI,cAAc,CAEzD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,QAMrD;AAED,wBAAgB,wBAAwB,IAAI,UAAU,CAAC,cAAc,CAAC,CAErE;AAED,eAAO,MAAM,kBAAkB;;CAE7B,CAAC;AAEH,eAAO,MAAM,OAAO,QAAa,QAAQ,cAAc,CAKtD,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,cAAc,SAI3C,CAAC"}
|
package/lib-es/bridge/preload.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Subject } from "rxjs";
|
|
2
2
|
import { log } from "@ledgerhq/logs";
|
|
3
|
+
import { getValidators } from "../network/sdk";
|
|
3
4
|
const PRELOAD_MAX_AGE = 30 * 60 * 1000; // 30 minutes
|
|
4
|
-
let currentPreloadedData = {};
|
|
5
|
+
let currentPreloadedData = { validators: [] };
|
|
5
6
|
function fromHydratePreloadData(_data) {
|
|
6
|
-
return {};
|
|
7
|
+
return { validators: _data.validators };
|
|
7
8
|
}
|
|
8
9
|
const updates = new Subject();
|
|
9
10
|
export function getCurrentSuiPreloadData() {
|
|
@@ -22,8 +23,9 @@ export const getPreloadStrategy = () => ({
|
|
|
22
23
|
preloadMaxAge: PRELOAD_MAX_AGE,
|
|
23
24
|
});
|
|
24
25
|
export const preload = async () => {
|
|
26
|
+
const validators = await getValidators();
|
|
25
27
|
log("sui/preload", "preloading sui data...");
|
|
26
|
-
return {};
|
|
28
|
+
return { validators };
|
|
27
29
|
};
|
|
28
30
|
export const hydrate = (data) => {
|
|
29
31
|
const hydrated = fromHydratePreloadData(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../../src/bridge/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../../src/bridge/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAErD,IAAI,oBAAoB,GAAmB,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AAE9D,SAAS,sBAAsB,CAAC,KAAqB;IACnD,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;AAC1C,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,OAAO,EAAkB,CAAC;AAE9C,MAAM,UAAU,wBAAwB;IACtC,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAoB;IACpD,IAAI,IAAI,KAAK,oBAAoB;QAAE,OAAO;IAE1C,oBAAoB,GAAG,IAAI,CAAC;IAE5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,CAAC;IACvC,aAAa,EAAE,eAAe;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,IAA6B,EAAE;IACzD,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;IACzC,GAAG,CAAC,aAAa,EAAE,wBAAwB,CAAC,CAAC;IAE7C,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAoB,EAAE,EAAE;IAC9C,MAAM,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAE9C,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
2
|
import { take } from "rxjs/operators";
|
|
3
|
-
import { getCurrentSuiPreloadData, setSuiPreloadData, getSuiPreloadDataUpdates, getPreloadStrategy,
|
|
3
|
+
import { getCurrentSuiPreloadData, setSuiPreloadData, getSuiPreloadDataUpdates, getPreloadStrategy, } from "./preload";
|
|
4
4
|
// Mock the log function
|
|
5
5
|
jest.mock("@ledgerhq/logs", () => ({
|
|
6
6
|
log: jest.fn(),
|
|
@@ -8,56 +8,23 @@ jest.mock("@ledgerhq/logs", () => ({
|
|
|
8
8
|
describe("Sui Preload Functions", () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
// Reset the preload data before each test
|
|
11
|
-
setSuiPreloadData({});
|
|
11
|
+
setSuiPreloadData({ validators: [] });
|
|
12
12
|
});
|
|
13
13
|
describe("getCurrentSuiPreloadData", () => {
|
|
14
|
-
it("should return empty object by default", () => {
|
|
15
|
-
const data = getCurrentSuiPreloadData();
|
|
16
|
-
expect(data).toEqual({});
|
|
17
|
-
});
|
|
18
14
|
it("should return the current preloaded data", () => {
|
|
19
|
-
const testData = {
|
|
15
|
+
const testData = { validators: [] };
|
|
20
16
|
setSuiPreloadData(testData);
|
|
21
17
|
const data = getCurrentSuiPreloadData();
|
|
22
18
|
expect(data).toEqual(testData);
|
|
23
19
|
});
|
|
24
20
|
});
|
|
25
|
-
describe("setSuiPreloadData", () => {
|
|
26
|
-
it("should set the preload data", () => {
|
|
27
|
-
const testData = { key1: "value1", key2: "value2" };
|
|
28
|
-
setSuiPreloadData(testData);
|
|
29
|
-
const currentData = getCurrentSuiPreloadData();
|
|
30
|
-
expect(currentData).toEqual(testData);
|
|
31
|
-
});
|
|
32
|
-
it("should not update if data is the same reference", () => {
|
|
33
|
-
const testData = { test: "data" };
|
|
34
|
-
// Set data first time
|
|
35
|
-
setSuiPreloadData(testData);
|
|
36
|
-
const firstCall = getCurrentSuiPreloadData();
|
|
37
|
-
// Set the same data reference
|
|
38
|
-
setSuiPreloadData(testData);
|
|
39
|
-
const secondCall = getCurrentSuiPreloadData();
|
|
40
|
-
expect(firstCall).toBe(secondCall);
|
|
41
|
-
expect(firstCall).toEqual(testData);
|
|
42
|
-
});
|
|
43
|
-
it("should update if data has different content", () => {
|
|
44
|
-
const firstData = { test: "first" };
|
|
45
|
-
const secondData = { test: "second" };
|
|
46
|
-
setSuiPreloadData(firstData);
|
|
47
|
-
const firstCall = getCurrentSuiPreloadData();
|
|
48
|
-
setSuiPreloadData(secondData);
|
|
49
|
-
const secondCall = getCurrentSuiPreloadData();
|
|
50
|
-
expect(firstCall).not.toBe(secondCall);
|
|
51
|
-
expect(secondCall).toEqual(secondData);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
21
|
describe("getSuiPreloadDataUpdates", () => {
|
|
55
22
|
it("should return an Observable", () => {
|
|
56
23
|
const updates = getSuiPreloadDataUpdates();
|
|
57
24
|
expect(updates).toBeInstanceOf(Observable);
|
|
58
25
|
});
|
|
59
26
|
it("should emit updates when data is set", done => {
|
|
60
|
-
const testData = {
|
|
27
|
+
const testData = { validators: [] };
|
|
61
28
|
const updates = getSuiPreloadDataUpdates();
|
|
62
29
|
updates.pipe(take(1)).subscribe(data => {
|
|
63
30
|
expect(data).toEqual(testData);
|
|
@@ -65,189 +32,18 @@ describe("Sui Preload Functions", () => {
|
|
|
65
32
|
});
|
|
66
33
|
setSuiPreloadData(testData);
|
|
67
34
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
updates.pipe(take(2)).subscribe(data => {
|
|
74
|
-
callCount++;
|
|
75
|
-
if (callCount === 1) {
|
|
76
|
-
expect(data).toEqual(firstData);
|
|
77
|
-
}
|
|
78
|
-
else if (callCount === 2) {
|
|
79
|
-
expect(data).toEqual(secondData);
|
|
80
|
-
done();
|
|
81
|
-
}
|
|
35
|
+
describe("getPreloadStrategy", () => {
|
|
36
|
+
it("should return preload strategy with correct max age", () => {
|
|
37
|
+
const strategy = getPreloadStrategy();
|
|
38
|
+
expect(strategy).toHaveProperty("preloadMaxAge");
|
|
39
|
+
expect(strategy.preloadMaxAge).toBe(30 * 60 * 1000); // 30 minutes in milliseconds
|
|
82
40
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const updates = getSuiPreloadDataUpdates();
|
|
89
|
-
let callCount = 0;
|
|
90
|
-
updates.pipe(take(1)).subscribe(data => {
|
|
91
|
-
callCount++;
|
|
92
|
-
expect(data).toEqual(testData);
|
|
93
|
-
// Wait a bit to ensure no additional emissions
|
|
94
|
-
setTimeout(() => {
|
|
95
|
-
expect(callCount).toBe(1);
|
|
96
|
-
done();
|
|
97
|
-
}, 10);
|
|
41
|
+
it("should return consistent strategy object", () => {
|
|
42
|
+
const strategy1 = getPreloadStrategy();
|
|
43
|
+
const strategy2 = getPreloadStrategy();
|
|
44
|
+
expect(strategy1).toEqual(strategy2);
|
|
45
|
+
expect(strategy1.preloadMaxAge).toBe(30 * 60 * 1000);
|
|
98
46
|
});
|
|
99
|
-
setSuiPreloadData(testData);
|
|
100
|
-
setSuiPreloadData(testData); // Same reference, should not emit
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe("getPreloadStrategy", () => {
|
|
104
|
-
it("should return preload strategy with correct max age", () => {
|
|
105
|
-
const strategy = getPreloadStrategy();
|
|
106
|
-
expect(strategy).toHaveProperty("preloadMaxAge");
|
|
107
|
-
expect(strategy.preloadMaxAge).toBe(30 * 60 * 1000); // 30 minutes in milliseconds
|
|
108
|
-
});
|
|
109
|
-
it("should return consistent strategy object", () => {
|
|
110
|
-
const strategy1 = getPreloadStrategy();
|
|
111
|
-
const strategy2 = getPreloadStrategy();
|
|
112
|
-
expect(strategy1).toEqual(strategy2);
|
|
113
|
-
expect(strategy1.preloadMaxAge).toBe(30 * 60 * 1000);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe("preload", () => {
|
|
117
|
-
it("should return empty object", async () => {
|
|
118
|
-
const result = await preload();
|
|
119
|
-
expect(result).toEqual({});
|
|
120
|
-
});
|
|
121
|
-
it("should log preload message", async () => {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
123
|
-
const { log } = require("@ledgerhq/logs");
|
|
124
|
-
await preload();
|
|
125
|
-
expect(log).toHaveBeenCalledWith("sui/preload", "preloading sui data...");
|
|
126
|
-
});
|
|
127
|
-
it("should always return the same result", async () => {
|
|
128
|
-
const result1 = await preload();
|
|
129
|
-
const result2 = await preload();
|
|
130
|
-
expect(result1).toEqual(result2);
|
|
131
|
-
expect(result1).toEqual({});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("hydrate", () => {
|
|
135
|
-
it("should set preload data with hydrated data", () => {
|
|
136
|
-
const testData = { hydrate: "test" };
|
|
137
|
-
hydrate(testData);
|
|
138
|
-
const currentData = getCurrentSuiPreloadData();
|
|
139
|
-
expect(currentData).toEqual({}); // fromHydratePreloadData returns empty object
|
|
140
|
-
});
|
|
141
|
-
it("should emit update when hydrated", done => {
|
|
142
|
-
const testData = { hydrate: "test" };
|
|
143
|
-
const updates = getSuiPreloadDataUpdates();
|
|
144
|
-
updates.pipe(take(1)).subscribe(data => {
|
|
145
|
-
expect(data).toEqual({}); // fromHydratePreloadData returns empty object
|
|
146
|
-
done();
|
|
147
|
-
});
|
|
148
|
-
hydrate(testData);
|
|
149
|
-
});
|
|
150
|
-
it("should handle empty data", () => {
|
|
151
|
-
const emptyData = {};
|
|
152
|
-
hydrate(emptyData);
|
|
153
|
-
const currentData = getCurrentSuiPreloadData();
|
|
154
|
-
expect(currentData).toEqual({});
|
|
155
|
-
});
|
|
156
|
-
it("should handle complex data structures", () => {
|
|
157
|
-
const complexData = {
|
|
158
|
-
nested: { key: "value" },
|
|
159
|
-
array: [1, 2, 3],
|
|
160
|
-
boolean: true,
|
|
161
|
-
number: 42,
|
|
162
|
-
};
|
|
163
|
-
hydrate(complexData);
|
|
164
|
-
const currentData = getCurrentSuiPreloadData();
|
|
165
|
-
expect(currentData).toEqual({}); // fromHydratePreloadData returns empty object
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe("Integration Tests", () => {
|
|
169
|
-
it("should maintain data consistency across multiple operations", () => {
|
|
170
|
-
const testData = { integration: "test" };
|
|
171
|
-
// Set data
|
|
172
|
-
setSuiPreloadData(testData);
|
|
173
|
-
expect(getCurrentSuiPreloadData()).toEqual(testData);
|
|
174
|
-
// Hydrate should override
|
|
175
|
-
hydrate({ different: "data" });
|
|
176
|
-
expect(getCurrentSuiPreloadData()).toEqual({});
|
|
177
|
-
// Set again
|
|
178
|
-
setSuiPreloadData(testData);
|
|
179
|
-
expect(getCurrentSuiPreloadData()).toEqual(testData);
|
|
180
|
-
});
|
|
181
|
-
it("should handle rapid successive updates", done => {
|
|
182
|
-
const updates = getSuiPreloadDataUpdates();
|
|
183
|
-
const results = [];
|
|
184
|
-
updates.pipe(take(3)).subscribe(data => {
|
|
185
|
-
results.push(data);
|
|
186
|
-
if (results.length === 3) {
|
|
187
|
-
expect(results).toEqual([{ first: "update" }, { second: "update" }, { third: "update" }]);
|
|
188
|
-
done();
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
setSuiPreloadData({ first: "update" });
|
|
192
|
-
setSuiPreloadData({ second: "update" });
|
|
193
|
-
setSuiPreloadData({ third: "update" });
|
|
194
|
-
});
|
|
195
|
-
it("should work with preload strategy", async () => {
|
|
196
|
-
const strategy = getPreloadStrategy();
|
|
197
|
-
const preloadResult = await preload();
|
|
198
|
-
expect(strategy.preloadMaxAge).toBe(30 * 60 * 1000);
|
|
199
|
-
expect(preloadResult).toEqual({});
|
|
200
|
-
// Preload should not affect current data
|
|
201
|
-
expect(getCurrentSuiPreloadData()).toEqual({});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
describe("Edge Cases", () => {
|
|
205
|
-
it("should handle null data gracefully", () => {
|
|
206
|
-
// TypeScript would prevent this, but testing runtime behavior
|
|
207
|
-
const nullData = null;
|
|
208
|
-
expect(() => {
|
|
209
|
-
setSuiPreloadData(nullData);
|
|
210
|
-
}).not.toThrow();
|
|
211
|
-
});
|
|
212
|
-
it("should handle undefined data gracefully", () => {
|
|
213
|
-
// TypeScript would prevent this, but testing runtime behavior
|
|
214
|
-
const undefinedData = undefined;
|
|
215
|
-
expect(() => {
|
|
216
|
-
setSuiPreloadData(undefinedData);
|
|
217
|
-
}).not.toThrow();
|
|
218
|
-
});
|
|
219
|
-
it("should handle multiple subscribers", done => {
|
|
220
|
-
const updates1 = getSuiPreloadDataUpdates();
|
|
221
|
-
const updates2 = getSuiPreloadDataUpdates();
|
|
222
|
-
let subscriber1Called = false;
|
|
223
|
-
let subscriber2Called = false;
|
|
224
|
-
updates1.pipe(take(1)).subscribe(() => {
|
|
225
|
-
subscriber1Called = true;
|
|
226
|
-
if (subscriber1Called && subscriber2Called) {
|
|
227
|
-
done();
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
updates2.pipe(take(1)).subscribe(() => {
|
|
231
|
-
subscriber2Called = true;
|
|
232
|
-
if (subscriber1Called && subscriber2Called) {
|
|
233
|
-
done();
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
setSuiPreloadData({ multi: "subscriber" });
|
|
237
|
-
});
|
|
238
|
-
it("should handle unsubscribe scenarios", done => {
|
|
239
|
-
const updates = getSuiPreloadDataUpdates();
|
|
240
|
-
let callCount = 0;
|
|
241
|
-
const subscription = updates.subscribe(() => {
|
|
242
|
-
callCount++;
|
|
243
|
-
});
|
|
244
|
-
setSuiPreloadData({ first: "update" });
|
|
245
|
-
subscription.unsubscribe();
|
|
246
|
-
setSuiPreloadData({ second: "update" });
|
|
247
|
-
setTimeout(() => {
|
|
248
|
-
expect(callCount).toBe(1); // Should only receive first update
|
|
249
|
-
done();
|
|
250
|
-
}, 10);
|
|
251
47
|
});
|
|
252
48
|
});
|
|
253
49
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.test.js","sourceRoot":"","sources":["../../src/bridge/preload.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"preload.test.js","sourceRoot":"","sources":["../../src/bridge/preload.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAGnB,wBAAwB;AACxB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC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AAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;YAClC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;gBAC7D,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;gBAEtC,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;gBACjD,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,6BAA6B;YACpF,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;gBAClD,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;gBACvC,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;gBAEvC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrC,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -27,7 +27,7 @@ export const prepareTransaction = async (account, transaction) => {
|
|
|
27
27
|
catch (e) {
|
|
28
28
|
fees = BigNumber(0);
|
|
29
29
|
}
|
|
30
|
-
let mode = "send";
|
|
30
|
+
let mode = transaction.mode ?? "send";
|
|
31
31
|
let coinType = DEFAULT_COIN_TYPE;
|
|
32
32
|
if (transaction?.subAccountId) {
|
|
33
33
|
mode = "token.send";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,k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{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,2CAA2C,CAAC;AAKnD,OAAO,EAAqB,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,sBAAsB,CAAC;AAIrE;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,UAAU,CA8DvD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,qHAAuD,CAAC"}
|
|
@@ -2,7 +2,7 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import { encodeAccountId, encodeTokenAccountId, emptyHistoryCache, } from "@ledgerhq/coin-framework/account/index";
|
|
3
3
|
import { makeSync, mergeOps, } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
4
|
import { listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
5
|
-
import { getAccountBalances, getOperations } from "../network";
|
|
5
|
+
import { getAccountBalances, getOperations, getStakesRaw } from "../network";
|
|
6
6
|
import { DEFAULT_COIN_TYPE } from "../network/sdk";
|
|
7
7
|
import { promiseAllBatched } from "@ledgerhq/live-promise";
|
|
8
8
|
/**
|
|
@@ -26,6 +26,7 @@ export const getAccountShape = async (info, syncConfig) => {
|
|
|
26
26
|
derivationMode,
|
|
27
27
|
});
|
|
28
28
|
let operations = [];
|
|
29
|
+
const stakes = await getStakesRaw(address);
|
|
29
30
|
let syncHash = initialAccount?.syncHash ?? latestHash(oldOperations);
|
|
30
31
|
const newOperations = await getOperations(accountId, address, syncHash);
|
|
31
32
|
operations = mergeOps(oldOperations, newOperations);
|
|
@@ -55,7 +56,9 @@ export const getAccountShape = async (info, syncConfig) => {
|
|
|
55
56
|
operationsCount: mainAccountOperations.length,
|
|
56
57
|
blockHeight: 5,
|
|
57
58
|
subAccounts,
|
|
58
|
-
suiResources: {
|
|
59
|
+
suiResources: {
|
|
60
|
+
stakes,
|
|
61
|
+
},
|
|
59
62
|
operations: mainAccountOperations,
|
|
60
63
|
};
|
|
61
64
|
};
|
|
@@ -73,7 +76,7 @@ async function buildSubAccounts({ accountId, initialAccount, operations, subAcco
|
|
|
73
76
|
const tokenAccounts = [];
|
|
74
77
|
const existingAccountByTicker = {}; // used for fast lookup
|
|
75
78
|
const existingAccountTickers = []; // used to keep track of ordering
|
|
76
|
-
if (initialAccount
|
|
79
|
+
if (initialAccount?.subAccounts) {
|
|
77
80
|
for (const existingSubAccount of initialAccount.subAccounts) {
|
|
78
81
|
if (existingSubAccount.type === "TokenAccount") {
|
|
79
82
|
const { ticker, id } = existingSubAccount.token;
|