@ledgerhq/coin-vechain 2.11.1-nightly.4 → 2.12.0-nightly.6
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +21 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +5 -3
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +5 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/package.json +5 -5
- package/src/bridge/synchronisation.test.ts +62 -3
- package/src/bridge/synchronisation.ts +4 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/coin-vechain@2.11.1-nightly.
|
|
2
|
+
> @ledgerhq/coin-vechain@2.11.1-nightly.5 build /home/runner/work/ledger-live/ledger-live/libs/coin-modules/coin-vechain
|
|
3
3
|
> tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ledgerhq/coin-evm
|
|
2
2
|
|
|
3
|
+
## 2.12.0-nightly.6
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#12497](https://github.com/LedgerHQ/ledger-live/pull/12497) [`119fb5b`](https://github.com/LedgerHQ/ledger-live/commit/119fb5b33b977f93d681d5f38131e3d7eb6d4237) Thanks [@gre-ledger](https://github.com/gre-ledger)! - Prepare vechain for async CryptoAssetsStore migration - add await to token lookups
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`607e4be`](https://github.com/LedgerHQ/ledger-live/commit/607e4be33145c102debce1606224b08579888aa8)]:
|
|
12
|
+
- @ledgerhq/cryptoassets@13.32.0-nightly.4
|
|
13
|
+
- @ledgerhq/coin-framework@6.8.0-nightly.6
|
|
14
|
+
|
|
15
|
+
## 2.11.1-nightly.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`c1a4bfd`](https://github.com/LedgerHQ/ledger-live/commit/c1a4bfd34b46c6b6587d247673cadb3c078deb1d), [`6ccabef`](https://github.com/LedgerHQ/ledger-live/commit/6ccabef8f3c4e8cc042299d531684595ebadcc55)]:
|
|
20
|
+
- @ledgerhq/devices@8.7.0-nightly.1
|
|
21
|
+
- @ledgerhq/cryptoassets@13.32.0-nightly.3
|
|
22
|
+
- @ledgerhq/coin-framework@6.8.0-nightly.5
|
|
23
|
+
|
|
3
24
|
## 2.11.1-nightly.4
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAY,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAK/C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,OAAO,CA+EpD,CAAC"}
|
|
@@ -8,10 +8,10 @@ const bignumber_js_1 = require("bignumber.js");
|
|
|
8
8
|
const eip55_1 = __importDefault(require("eip55"));
|
|
9
9
|
const index_1 = require("@ledgerhq/coin-framework/account/index");
|
|
10
10
|
const network_1 = require("../network");
|
|
11
|
-
const tokens_1 = require("@ledgerhq/cryptoassets/tokens");
|
|
12
11
|
const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
13
12
|
const helpers_1 = require("./helpers");
|
|
14
13
|
const sdk_core_1 = require("@vechain/sdk-core");
|
|
14
|
+
const legacy_state_1 = require("@ledgerhq/cryptoassets/legacy/legacy-state");
|
|
15
15
|
const getAccountShape = async (info) => {
|
|
16
16
|
const { initialAccount, currency, derivationMode } = info;
|
|
17
17
|
const address = eip55_1.default.encode(info.address);
|
|
@@ -31,7 +31,10 @@ const getAccountShape = async (info) => {
|
|
|
31
31
|
// Merge new operations with the previously synced ones
|
|
32
32
|
const newOperations = await (0, network_1.getOperations)(accountId, address, startAt);
|
|
33
33
|
//Get last token operations
|
|
34
|
-
const
|
|
34
|
+
const vthoToken = legacy_state_1.tokensById["vechain/vip180/vtho"];
|
|
35
|
+
if (!vthoToken)
|
|
36
|
+
throw new Error("VTHO token not found");
|
|
37
|
+
const vthoAccountId = (0, index_1.encodeTokenAccountId)(accountId, vthoToken);
|
|
35
38
|
const vthoOperations = await (0, network_1.getTokenOperations)(vthoAccountId, address, sdk_core_1.VTHO_ADDRESS, 1); // from parameter must be 1 otherwise the response is empty
|
|
36
39
|
const operations = (0, jsHelpers_1.mergeOps)(oldOperations, newOperations);
|
|
37
40
|
//Account creation date set to now if there are no operation or at the first operation on the account
|
|
@@ -41,7 +44,6 @@ const getAccountShape = async (info) => {
|
|
|
41
44
|
operationsDates.concat(vthoOperations.map(c => c.date.getTime()));
|
|
42
45
|
minDate = Math.min(...operationsDates);
|
|
43
46
|
}
|
|
44
|
-
const vthoToken = (0, tokens_1.findTokenById)("vechain/vip180/vtho");
|
|
45
47
|
if (!vthoToken) {
|
|
46
48
|
throw new Error('token with id "vechain/vip180/vtho" not found');
|
|
47
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyC;AAEzC,kDAA0B;AAC1B,kEAIgD;AAEhD,wCAA+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":";;;;;;AA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AS;gBAChB,OAAO,EAAE,IAAI,wBAAS,CAAC,MAAM,CAAC;gBAC9B,gBAAgB,EAAE,IAAI,wBAAS,CAAC,MAAM,CAAC;gBACvC,YAAY,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;gBAC7D,eAAe,EAAE,cAAc,CAAC,MAAM;gBACtC,UAAU,EAAE,cAAc;gBAC1B,WAAW;gBACX,iBAAiB,EACf,CAAC,cAAc,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,IAAI,EAAE;gBACzF,mBAAmB,EACjB,CAAC,cAAc,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC;oBACnF,yBAAiB;gBACnB,WAAW,EAAE,EAAE;aAChB;SACF;KACF,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,IAAI,EAAE,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC;AA/EW,QAAA,eAAe,mBA+E1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAY,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAK/C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,OAAO,CA+EpD,CAAC"}
|
|
@@ -2,10 +2,10 @@ import { BigNumber } from "bignumber.js";
|
|
|
2
2
|
import eip55 from "eip55";
|
|
3
3
|
import { emptyHistoryCache, encodeAccountId, encodeTokenAccountId, } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { getAccount, getLastBlockHeight, getOperations, getTokenOperations } from "../network";
|
|
5
|
-
import { findTokenById } from "@ledgerhq/cryptoassets/tokens";
|
|
6
5
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
6
|
import { isAccountEmpty } from "./helpers";
|
|
8
7
|
import { VTHO_ADDRESS } from "@vechain/sdk-core";
|
|
8
|
+
import { tokensById } from "@ledgerhq/cryptoassets/legacy/legacy-state";
|
|
9
9
|
export const getAccountShape = async (info) => {
|
|
10
10
|
const { initialAccount, currency, derivationMode } = info;
|
|
11
11
|
const address = eip55.encode(info.address);
|
|
@@ -25,7 +25,10 @@ export const getAccountShape = async (info) => {
|
|
|
25
25
|
// Merge new operations with the previously synced ones
|
|
26
26
|
const newOperations = await getOperations(accountId, address, startAt);
|
|
27
27
|
//Get last token operations
|
|
28
|
-
const
|
|
28
|
+
const vthoToken = tokensById["vechain/vip180/vtho"];
|
|
29
|
+
if (!vthoToken)
|
|
30
|
+
throw new Error("VTHO token not found");
|
|
31
|
+
const vthoAccountId = encodeTokenAccountId(accountId, vthoToken);
|
|
29
32
|
const vthoOperations = await getTokenOperations(vthoAccountId, address, VTHO_ADDRESS, 1); // from parameter must be 1 otherwise the response is empty
|
|
30
33
|
const operations = mergeOps(oldOperations, newOperations);
|
|
31
34
|
//Account creation date set to now if there are no operation or at the first operation on the account
|
|
@@ -35,7 +38,6 @@ export const getAccountShape = async (info) => {
|
|
|
35
38
|
operationsDates.concat(vthoOperations.map(c => c.date.getTime()));
|
|
36
39
|
minDate = Math.min(...operationsDates);
|
|
37
40
|
}
|
|
38
|
-
const vthoToken = findTokenById("vechain/vip180/vtho");
|
|
39
41
|
if (!vthoToken) {
|
|
40
42
|
throw new Error('token with id "vechain/vip180/vtho" not found');
|
|
41
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,
|
|
1
|
+
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAmB,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,MAAM,CAAC,MAAM,eAAe,GAA6B,KAAK,EAAC,IAAI,EAAC,EAAE;IACpE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE3C,MAAM,aAAa,GAAG,cAAc,EAAE,UAAU,IAAI,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,WAAW,IAA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AiB;gBACnB,WAAW,EAAE,EAAE;aAChB;SACF;KACF,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,IAAI,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-vechain",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0-nightly.6",
|
|
4
4
|
"description": "Ledger VeChain Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"rxjs": "^7.8.1",
|
|
87
87
|
"@vechain/sdk-core": "2.0.0",
|
|
88
88
|
"@vechain/sdk-network": "2.0.0",
|
|
89
|
-
"@ledgerhq/coin-framework": "^6.8.0-nightly.
|
|
90
|
-
"@ledgerhq/cryptoassets": "^13.32.0-nightly.
|
|
91
|
-
"@ledgerhq/devices": "8.
|
|
89
|
+
"@ledgerhq/coin-framework": "^6.8.0-nightly.6",
|
|
90
|
+
"@ledgerhq/cryptoassets": "^13.32.0-nightly.4",
|
|
91
|
+
"@ledgerhq/devices": "8.7.0-nightly.1",
|
|
92
92
|
"@ledgerhq/errors": "^6.27.0-nightly.0",
|
|
93
93
|
"@ledgerhq/live-env": "^2.20.0-nightly.0",
|
|
94
94
|
"@ledgerhq/live-network": "^2.1.0-nightly.1"
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"msw": "^2.2.13",
|
|
104
104
|
"ts-jest": "^29.1.1",
|
|
105
105
|
"@ledgerhq/types-cryptoassets": "^7.29.0",
|
|
106
|
-
"@ledgerhq/types-live": "^6.88.0-nightly.
|
|
106
|
+
"@ledgerhq/types-live": "^6.88.0-nightly.3",
|
|
107
107
|
"@ledgerhq/disable-network-setup": "^0.1.0-nightly.0"
|
|
108
108
|
},
|
|
109
109
|
"scripts": {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { faker } from "@faker-js/faker";
|
|
2
2
|
import { createEmptyHistoryCache } from "@ledgerhq/coin-framework/account";
|
|
3
3
|
import { makeScanAccounts } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
-
import { getCryptoCurrencyById
|
|
4
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
5
|
+
import { getCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
|
|
6
|
+
import { initializeLegacyTokens } from "@ledgerhq/cryptoassets/legacy/legacy-data";
|
|
7
|
+
import { addTokens } from "@ledgerhq/cryptoassets/legacy/legacy-utils";
|
|
5
8
|
import BigNumber from "bignumber.js";
|
|
6
9
|
import { setupServer } from "msw/node";
|
|
7
10
|
import { firstValueFrom } from "rxjs";
|
|
8
11
|
import { getAccountShape } from "./synchronisation";
|
|
9
12
|
import { Operation } from "@ledgerhq/types-live";
|
|
10
13
|
|
|
14
|
+
jest.mock("@ledgerhq/coin-framework/crypto-assets/index");
|
|
15
|
+
|
|
11
16
|
const mockGetAccount = jest.fn();
|
|
12
17
|
const mockGetOperations = jest.fn();
|
|
13
18
|
const mockGetTokenOperations = jest.fn();
|
|
@@ -30,6 +35,57 @@ describe("scanAccounts", () => {
|
|
|
30
35
|
const currency = getCryptoCurrencyById("vechain");
|
|
31
36
|
|
|
32
37
|
beforeAll(() => {
|
|
38
|
+
// Initialize legacy tokens
|
|
39
|
+
initializeLegacyTokens(addTokens);
|
|
40
|
+
|
|
41
|
+
// Mock the crypto assets store
|
|
42
|
+
const vthoToken = {
|
|
43
|
+
type: "TokenCurrency",
|
|
44
|
+
id: "vechain/vip180/vtho",
|
|
45
|
+
contractAddress: "0x0000000000000000000000000000456E65726779",
|
|
46
|
+
parentCurrency: {
|
|
47
|
+
type: "CryptoCurrency",
|
|
48
|
+
id: "vechain",
|
|
49
|
+
coinType: 818,
|
|
50
|
+
name: "Vechain",
|
|
51
|
+
managerAppName: "VeChain",
|
|
52
|
+
ticker: "VET",
|
|
53
|
+
scheme: "vechain",
|
|
54
|
+
color: "#82BE00",
|
|
55
|
+
family: "vechain",
|
|
56
|
+
blockAvgTime: 10,
|
|
57
|
+
tokenTypes: ["vip180"],
|
|
58
|
+
units: [
|
|
59
|
+
{ name: "VET", code: "VET", magnitude: 18 },
|
|
60
|
+
{ name: "Gwei", code: "Gwei", magnitude: 9 },
|
|
61
|
+
{ name: "Mwei", code: "Mwei", magnitude: 6 },
|
|
62
|
+
{ name: "Kwei", code: "Kwei", magnitude: 3 },
|
|
63
|
+
{ name: "wei", code: "wei", magnitude: 0 },
|
|
64
|
+
],
|
|
65
|
+
explorerViews: [
|
|
66
|
+
{
|
|
67
|
+
tx: "https://explore.vechain.org/transactions/$hash",
|
|
68
|
+
address: "https://explore.vechain.org/accounts/$address",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
tokenType: "vip180",
|
|
73
|
+
name: "Vethor",
|
|
74
|
+
ticker: "VTHO",
|
|
75
|
+
disableCountervalue: false,
|
|
76
|
+
units: [{ name: "Vethor", code: "VTHO", magnitude: 18 }],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
(getCryptoAssetsStore as jest.Mock).mockReturnValue({
|
|
80
|
+
findTokenById: jest.fn().mockImplementation((id: string) => {
|
|
81
|
+
if (id === "vechain/vip180/vtho") {
|
|
82
|
+
return Promise.resolve(vthoToken);
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve(null);
|
|
85
|
+
}),
|
|
86
|
+
findTokenByAddressInCurrency: jest.fn().mockResolvedValue(null),
|
|
87
|
+
});
|
|
88
|
+
|
|
33
89
|
setupServer().listen({ onUnhandledRequest: "error" });
|
|
34
90
|
});
|
|
35
91
|
|
|
@@ -54,6 +110,9 @@ describe("scanAccounts", () => {
|
|
|
54
110
|
mockGetOperations.mockResolvedValueOnce([]);
|
|
55
111
|
mockGetTokenOperations.mockResolvedValueOnce([]);
|
|
56
112
|
|
|
113
|
+
// Get the token asynchronously
|
|
114
|
+
const vthoToken = await getCryptoAssetsStore().findTokenById("vechain/vip180/vtho");
|
|
115
|
+
|
|
57
116
|
// When
|
|
58
117
|
const scanAccounts = makeScanAccounts({
|
|
59
118
|
getAccountShape,
|
|
@@ -102,13 +161,13 @@ describe("scanAccounts", () => {
|
|
|
102
161
|
swapHistory: [],
|
|
103
162
|
type: "Account",
|
|
104
163
|
used: false,
|
|
105
|
-
feesCurrency:
|
|
164
|
+
feesCurrency: vthoToken,
|
|
106
165
|
subAccounts: [
|
|
107
166
|
{
|
|
108
167
|
type: "TokenAccount",
|
|
109
168
|
id: "js:2:vechain:0x5066118c66793ED86bd379b50b20E32B0FC1aBf5:vechain+vechain%2Fvip180%2Fvtho",
|
|
110
169
|
parentId: "js:2:vechain:0x5066118c66793ED86bd379b50b20E32B0FC1aBf5:vechain",
|
|
111
|
-
token:
|
|
170
|
+
token: vthoToken,
|
|
112
171
|
balance: new BigNumber("0"),
|
|
113
172
|
spendableBalance: new BigNumber("0"),
|
|
114
173
|
creationDate: expect.any(Date),
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
} from "@ledgerhq/coin-framework/account/index";
|
|
9
9
|
|
|
10
10
|
import { getAccount, getLastBlockHeight, getOperations, getTokenOperations } from "../network";
|
|
11
|
-
import { findTokenById } from "@ledgerhq/cryptoassets/tokens";
|
|
12
11
|
import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
13
12
|
import { Account } from "@ledgerhq/types-live";
|
|
14
13
|
import { isAccountEmpty } from "./helpers";
|
|
15
14
|
import { VTHO_ADDRESS } from "@vechain/sdk-core";
|
|
15
|
+
import { tokensById } from "@ledgerhq/cryptoassets/legacy/legacy-state";
|
|
16
16
|
|
|
17
17
|
export const getAccountShape: GetAccountShape<Account> = async info => {
|
|
18
18
|
const { initialAccount, currency, derivationMode } = info;
|
|
@@ -39,7 +39,9 @@ export const getAccountShape: GetAccountShape<Account> = async info => {
|
|
|
39
39
|
const newOperations = await getOperations(accountId, address, startAt);
|
|
40
40
|
|
|
41
41
|
//Get last token operations
|
|
42
|
-
const
|
|
42
|
+
const vthoToken = tokensById["vechain/vip180/vtho"];
|
|
43
|
+
if (!vthoToken) throw new Error("VTHO token not found");
|
|
44
|
+
const vthoAccountId = encodeTokenAccountId(accountId, vthoToken);
|
|
43
45
|
const vthoOperations = await getTokenOperations(vthoAccountId, address, VTHO_ADDRESS, 1); // from parameter must be 1 otherwise the response is empty
|
|
44
46
|
|
|
45
47
|
const operations = mergeOps(oldOperations, newOperations);
|
|
@@ -52,7 +54,6 @@ export const getAccountShape: GetAccountShape<Account> = async info => {
|
|
|
52
54
|
minDate = Math.min(...operationsDates);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
const vthoToken = findTokenById("vechain/vip180/vtho");
|
|
56
57
|
if (!vthoToken) {
|
|
57
58
|
throw new Error('token with id "vechain/vip180/vtho" not found');
|
|
58
59
|
}
|