@ledgerhq/live-common 27.0.0-next.2 → 27.0.0-next.3
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/account/importAccounts.d.ts +35 -2
- package/lib/account/importAccounts.d.ts.map +1 -1
- package/lib/account/importAccounts.integration.test.d.ts +2 -0
- package/lib/account/importAccounts.integration.test.d.ts.map +1 -0
- package/lib/account/importAccounts.integration.test.js +219 -0
- package/lib/account/importAccounts.integration.test.js.map +1 -0
- package/lib/account/importAccounts.js +130 -12
- package/lib/account/importAccounts.js.map +1 -1
- package/lib/account/importAccounts.test.d.ts +2 -0
- package/lib/account/importAccounts.test.d.ts.map +1 -0
- package/lib/{__tests__/accounts/importAccounts.js → account/importAccounts.test.js} +44 -64
- package/lib/account/importAccounts.test.js.map +1 -0
- package/package.json +1 -1
- package/src/account/importAccounts.integration.test.ts +193 -0
- package/src/{__tests__/accounts/importAccounts.ts → account/importAccounts.test.ts} +39 -59
- package/src/account/importAccounts.ts +103 -12
- package/lib/__tests__/accounts/importAccounts.d.ts +0 -2
- package/lib/__tests__/accounts/importAccounts.d.ts.map +0 -1
- package/lib/__tests__/accounts/importAccounts.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Result } from "../cross";
|
|
2
2
|
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { BridgeCacheSystem } from "../bridge/cache";
|
|
3
4
|
declare const itemModeDisplaySort: {
|
|
4
5
|
create: number;
|
|
5
6
|
update: number;
|
|
@@ -17,9 +18,41 @@ export declare const importAccountsMakeItems: ({ result, accounts, items, }: {
|
|
|
17
18
|
accounts: Account[];
|
|
18
19
|
items?: ImportItem[] | undefined;
|
|
19
20
|
}) => ImportItem[];
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* SyncNewAccountsOutput
|
|
23
|
+
* - synchronized: a map of account id to account. the account id are kept as originally set in the items[].account before a possible "remap" of the ids after a sync happened
|
|
24
|
+
* - failed: a map of account id to errors for all possible fails that happened.
|
|
25
|
+
*/
|
|
26
|
+
export declare type SyncNewAccountsOutput = {
|
|
27
|
+
synchronized: Record<string, Account>;
|
|
28
|
+
failed: Record<string, Error>;
|
|
29
|
+
};
|
|
30
|
+
export declare type SyncNewAccountsInput = {
|
|
21
31
|
items: ImportItem[];
|
|
22
32
|
selectedAccounts: string[];
|
|
23
|
-
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param items: result of importAccountsMakeItems
|
|
37
|
+
* @param selectedAccounts: user's selected accounts
|
|
38
|
+
* @param bridgeCache: the bridge cache created on user land to prepare currency for a sync
|
|
39
|
+
* @param blacklistedTokenIds: the list of blacklisted token ids to ignore sync with
|
|
40
|
+
* @returns SyncNewAccountsOutput
|
|
41
|
+
*/
|
|
42
|
+
export declare const syncNewAccountsToImport: ({ items, selectedAccounts }: SyncNewAccountsInput, bridgeCache: BridgeCacheSystem, blacklistedTokenIds?: string[] | undefined) => Promise<SyncNewAccountsOutput>;
|
|
43
|
+
export declare type ImportAccountsReduceInput = {
|
|
44
|
+
items: ImportItem[];
|
|
45
|
+
selectedAccounts: string[];
|
|
46
|
+
syncResult: SyncNewAccountsOutput;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param existingAccounts
|
|
51
|
+
* @param items: value resulting of importAccountsMakeItems
|
|
52
|
+
* @params selectedAccounts: array of all account ids selected by user for import
|
|
53
|
+
* @param syncedNewAccounts: accounts resulting of syncNewAccountsToImport(). all accounts that would be missing from that list would be ignored to be imported (fresh sync is needed to make sure the accounts are "ready")
|
|
54
|
+
* @returns all accounts
|
|
55
|
+
*/
|
|
56
|
+
export declare const importAccountsReduce: (existingAccounts: Account[], { items, selectedAccounts, syncResult }: ImportAccountsReduceInput) => Account[];
|
|
24
57
|
export {};
|
|
25
58
|
//# sourceMappingURL=importAccounts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importAccounts.d.ts","sourceRoot":"","sources":["../../src/account/importAccounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,QAAA,MAAM,mBAAmB;;;;;CAKxB,CAAC;AACF,oBAAY,cAAc,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAC9D,oBAAY,UAAU,GAAG;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,cAAc,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,uBAAuB;YAK1B,MAAM;cACJ,OAAO,EAAE;;MAEjB,UAAU,EA6EO,CAAC;
|
|
1
|
+
{"version":3,"file":"importAccounts.d.ts","sourceRoot":"","sources":["../../src/account/importAccounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAOpD,QAAA,MAAM,mBAAmB;;;;;CAKxB,CAAC;AACF,oBAAY,cAAc,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAC9D,oBAAY,UAAU,GAAG;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,cAAc,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,uBAAuB;YAK1B,MAAM;cACJ,OAAO,EAAE;;MAEjB,UAAU,EA6EO,CAAC;AAEtB;;;;GAIG;AACH,oBAAY,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B,CAAC;AAEF,oBAAY,oBAAoB,GAAG;IACjC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,gCACL,oBAAoB,eACpC,iBAAiB,iDAE7B,QAAQ,qBAAqB,CA6B/B,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACtC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,EAAE,qBAAqB,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,qBACb,OAAO,EAAE,2CACc,yBAAyB,KACjE,OAAO,EAyCT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importAccounts.integration.test.d.ts","sourceRoot":"","sources":["../../src/account/importAccounts.integration.test.ts"],"names":[],"mappings":"AAAA,OAAO,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
require("../__tests__/test-helpers/setup");
|
|
40
|
+
var cache_1 = require("../bridge/cache");
|
|
41
|
+
var cross_1 = require("../cross");
|
|
42
|
+
var _1 = require(".");
|
|
43
|
+
jest.setTimeout(200000);
|
|
44
|
+
test("importAccounts with a set of real data", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
+
var accounts, localCache, bridgeCache, result, accountsState, items, selectedAccounts, syncResult, reduced;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
accounts = [
|
|
50
|
+
{
|
|
51
|
+
id: "js:2:algorand:32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI:",
|
|
52
|
+
seedIdentifier: "32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
53
|
+
name: "Algorand legacy 32PI2C5H...RXBSVWQI",
|
|
54
|
+
starred: true,
|
|
55
|
+
used: true,
|
|
56
|
+
derivationMode: "",
|
|
57
|
+
index: 0,
|
|
58
|
+
freshAddress: "32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
59
|
+
freshAddressPath: "44'/283'/0'/0/0",
|
|
60
|
+
freshAddresses: [],
|
|
61
|
+
blockHeight: 23066613,
|
|
62
|
+
creationDate: "2022-02-04T13:12:58.000Z",
|
|
63
|
+
operationsCount: 184,
|
|
64
|
+
operations: [],
|
|
65
|
+
pendingOperations: [],
|
|
66
|
+
currencyId: "algorand",
|
|
67
|
+
unitMagnitude: 6,
|
|
68
|
+
lastSyncDate: "2022-08-26T09:24:27.076Z",
|
|
69
|
+
balance: "2100190",
|
|
70
|
+
spendableBalance: "190",
|
|
71
|
+
xpub: "32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
72
|
+
subAccounts: [],
|
|
73
|
+
algorandResources: { rewards: "190", nbAssets: 20 },
|
|
74
|
+
swapHistory: []
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "js:2:tron:TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK:",
|
|
78
|
+
seedIdentifier: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
79
|
+
name: "Tron legacy TRbtdwHo...5sx3fFCK",
|
|
80
|
+
starred: true,
|
|
81
|
+
used: true,
|
|
82
|
+
derivationMode: "",
|
|
83
|
+
index: 0,
|
|
84
|
+
freshAddress: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
85
|
+
freshAddressPath: "44'/195'/0'/0/0",
|
|
86
|
+
freshAddresses: [],
|
|
87
|
+
blockHeight: 43642499,
|
|
88
|
+
creationDate: "2022-07-19T15:32:12.000Z",
|
|
89
|
+
operationsCount: 41,
|
|
90
|
+
operations: [],
|
|
91
|
+
pendingOperations: [],
|
|
92
|
+
currencyId: "tron",
|
|
93
|
+
unitMagnitude: 6,
|
|
94
|
+
lastSyncDate: "2022-08-26T09:24:59.492Z",
|
|
95
|
+
balance: "0",
|
|
96
|
+
spendableBalance: "0",
|
|
97
|
+
xpub: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
98
|
+
subAccounts: [],
|
|
99
|
+
tronResources: {
|
|
100
|
+
frozen: {},
|
|
101
|
+
delegatedFrozen: {},
|
|
102
|
+
votes: [],
|
|
103
|
+
tronPower: 0,
|
|
104
|
+
energy: "0",
|
|
105
|
+
bandwidth: {
|
|
106
|
+
freeUsed: "0",
|
|
107
|
+
freeLimit: "1500",
|
|
108
|
+
gainedUsed: "0",
|
|
109
|
+
gainedLimit: "0"
|
|
110
|
+
},
|
|
111
|
+
unwithdrawnReward: "2730",
|
|
112
|
+
lastVotedDate: "2022-07-22T14:39:51.000Z",
|
|
113
|
+
cacheTransactionInfoById: {}
|
|
114
|
+
},
|
|
115
|
+
swapHistory: []
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "js:2:polkadot:15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP:polkadotbip44",
|
|
119
|
+
seedIdentifier: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
120
|
+
name: "Polkadot polkadotbip44 15jLBbe9...5KrKM1eP",
|
|
121
|
+
starred: true,
|
|
122
|
+
used: true,
|
|
123
|
+
derivationMode: "polkadotbip44",
|
|
124
|
+
index: 0,
|
|
125
|
+
freshAddress: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
126
|
+
freshAddressPath: "44'/354'/0'/0'/0'",
|
|
127
|
+
freshAddresses: [],
|
|
128
|
+
blockHeight: 11771108,
|
|
129
|
+
creationDate: "2022-02-24T14:39:00.007Z",
|
|
130
|
+
operationsCount: 65,
|
|
131
|
+
operations: [],
|
|
132
|
+
pendingOperations: [],
|
|
133
|
+
currencyId: "polkadot",
|
|
134
|
+
unitMagnitude: 10,
|
|
135
|
+
lastSyncDate: "2022-08-26T09:25:00.713Z",
|
|
136
|
+
balance: "15512511464",
|
|
137
|
+
spendableBalance: "15512511464",
|
|
138
|
+
xpub: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
139
|
+
polkadotResources: {
|
|
140
|
+
controller: null,
|
|
141
|
+
stash: null,
|
|
142
|
+
nonce: 63,
|
|
143
|
+
lockedBalance: "0",
|
|
144
|
+
unlockedBalance: "0",
|
|
145
|
+
unlockingBalance: "0",
|
|
146
|
+
unlockings: [],
|
|
147
|
+
nominations: []
|
|
148
|
+
},
|
|
149
|
+
swapHistory: []
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
id: "js:2:bsc:0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB:",
|
|
153
|
+
seedIdentifier: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
154
|
+
name: "Binance Smart Chain legacy 0xa22CA8...CdD06FAB",
|
|
155
|
+
starred: true,
|
|
156
|
+
used: true,
|
|
157
|
+
derivationMode: "",
|
|
158
|
+
index: 0,
|
|
159
|
+
freshAddress: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
160
|
+
freshAddressPath: "44'/60'/0'/0/0",
|
|
161
|
+
freshAddresses: [],
|
|
162
|
+
blockHeight: 20775454,
|
|
163
|
+
syncHash: "[]_655",
|
|
164
|
+
creationDate: "2022-02-04T13:11:32.001Z",
|
|
165
|
+
operationsCount: 21,
|
|
166
|
+
operations: [],
|
|
167
|
+
pendingOperations: [],
|
|
168
|
+
currencyId: "bsc",
|
|
169
|
+
unitMagnitude: 18,
|
|
170
|
+
lastSyncDate: "2022-08-26T09:25:01.109Z",
|
|
171
|
+
balance: "3128019430408477",
|
|
172
|
+
spendableBalance: "3128019430408477",
|
|
173
|
+
xpub: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
174
|
+
subAccounts: [],
|
|
175
|
+
swapHistory: []
|
|
176
|
+
},
|
|
177
|
+
].map(_1.fromAccountRaw);
|
|
178
|
+
localCache = {};
|
|
179
|
+
bridgeCache = (0, cache_1.makeBridgeCacheSystem)({
|
|
180
|
+
saveData: function (c, d) {
|
|
181
|
+
localCache[c.id] = d;
|
|
182
|
+
return Promise.resolve();
|
|
183
|
+
},
|
|
184
|
+
getData: function (c) {
|
|
185
|
+
return Promise.resolve(localCache[c.id]);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
result = {
|
|
189
|
+
accounts: accounts.map(cross_1.accountToAccountData),
|
|
190
|
+
settings: { currenciesSettings: {}, pairExchanges: {} },
|
|
191
|
+
meta: { exporterName: "Test", exporterVersion: "0" }
|
|
192
|
+
};
|
|
193
|
+
accountsState = [];
|
|
194
|
+
items = (0, _1.importAccountsMakeItems)({
|
|
195
|
+
result: result,
|
|
196
|
+
accounts: accountsState
|
|
197
|
+
});
|
|
198
|
+
selectedAccounts = accounts.map(function (a) { return a.id; });
|
|
199
|
+
return [4 /*yield*/, (0, _1.syncNewAccountsToImport)({ items: items, selectedAccounts: selectedAccounts }, bridgeCache)];
|
|
200
|
+
case 1:
|
|
201
|
+
syncResult = _a.sent();
|
|
202
|
+
reduced = (0, _1.importAccountsReduce)(accountsState, {
|
|
203
|
+
items: items,
|
|
204
|
+
selectedAccounts: selectedAccounts,
|
|
205
|
+
syncResult: syncResult
|
|
206
|
+
});
|
|
207
|
+
expect(reduced.length).toEqual(4);
|
|
208
|
+
expect(reduced[0].algorandResources).toBeDefined();
|
|
209
|
+
expect(reduced[1].tronResources).toBeDefined();
|
|
210
|
+
expect(reduced[2].polkadotResources).toBeDefined();
|
|
211
|
+
expect(reduced[0].operations.length).toBeGreaterThan(1);
|
|
212
|
+
expect(reduced[1].operations.length).toBeGreaterThan(1);
|
|
213
|
+
expect(reduced[2].operations.length).toBeGreaterThan(1);
|
|
214
|
+
expect(reduced[3].operations.length).toBeGreaterThan(1);
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}); });
|
|
219
|
+
//# sourceMappingURL=importAccounts.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importAccounts.integration.test.js","sourceRoot":"","sources":["../../src/account/importAccounts.integration.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AACzC,yCAAwD;AACxD,kCAAgD;AAChD,sBAKW;AAGX,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAExB,IAAI,CAAC,wCAAwC,EAAE;;;;;gBACvC,QAAQ,GAAG;oBACf;wBACE,EAAE,EAAE,2EAA2E;wBAC/E,cAAc,EACZ,4DAA4D;wBAC9D,IAAI,EAAE,qCAAqC;wBAC3C,OAAO,EAAE,IAAI;wBACb,IAAI,EAAE,IAAI;wBACV,cAAc,EAAE,EAAE;wBAClB,KAAK,EAAE,CAAC;wBACR,YAAY,EACV,4DAA4D;wBAC9D,gBAAgB,EAAE,iBAAiB;wBACnC,cAA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
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
var __values = (this && this.__values) || function(o) {
|
|
14
50
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
51
|
if (m) return m.call(o);
|
|
@@ -25,12 +61,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
61
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
62
|
};
|
|
27
63
|
exports.__esModule = true;
|
|
28
|
-
exports.importAccountsReduce = exports.importAccountsMakeItems = void 0;
|
|
64
|
+
exports.importAccountsReduce = exports.syncNewAccountsToImport = exports.importAccountsMakeItems = void 0;
|
|
29
65
|
var logs_1 = require("@ledgerhq/logs");
|
|
30
66
|
var cross_1 = require("../cross");
|
|
31
67
|
var support_1 = require("./support");
|
|
32
68
|
var joinSwapHistories_1 = __importDefault(require("../exchange/swap/joinSwapHistories"));
|
|
33
69
|
var isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
70
|
+
var bridge_1 = require("../bridge");
|
|
71
|
+
var promise_1 = require("../promise");
|
|
72
|
+
var env_1 = require("../env");
|
|
73
|
+
var operators_1 = require("rxjs/operators");
|
|
34
74
|
var itemModeDisplaySort = {
|
|
35
75
|
create: 1,
|
|
36
76
|
update: 2,
|
|
@@ -100,22 +140,100 @@ var importAccountsMakeItems = function (_a) {
|
|
|
100
140
|
});
|
|
101
141
|
};
|
|
102
142
|
exports.importAccountsMakeItems = importAccountsMakeItems;
|
|
103
|
-
|
|
104
|
-
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* @param items: result of importAccountsMakeItems
|
|
146
|
+
* @param selectedAccounts: user's selected accounts
|
|
147
|
+
* @param bridgeCache: the bridge cache created on user land to prepare currency for a sync
|
|
148
|
+
* @param blacklistedTokenIds: the list of blacklisted token ids to ignore sync with
|
|
149
|
+
* @returns SyncNewAccountsOutput
|
|
150
|
+
*/
|
|
151
|
+
var syncNewAccountsToImport = function (_a, bridgeCache, blacklistedTokenIds) {
|
|
105
152
|
var items = _a.items, selectedAccounts = _a.selectedAccounts;
|
|
153
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
154
|
+
var selectedItems, synchronized, failed;
|
|
155
|
+
return __generator(this, function (_b) {
|
|
156
|
+
switch (_b.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
selectedItems = items.filter(function (item) {
|
|
159
|
+
return selectedAccounts.includes(item.account.id);
|
|
160
|
+
});
|
|
161
|
+
synchronized = {};
|
|
162
|
+
failed = {};
|
|
163
|
+
return [4 /*yield*/, (0, promise_1.promiseAllBatched)((0, env_1.getEnv)("SYNC_MAX_CONCURRENT"), selectedItems, function (_a) {
|
|
164
|
+
var account = _a.account;
|
|
165
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var bridge, syncConfig, observable, reduced, synced, e_1;
|
|
167
|
+
return __generator(this, function (_b) {
|
|
168
|
+
switch (_b.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
_b.trys.push([0, 3, , 4]);
|
|
171
|
+
bridge = (0, bridge_1.getAccountBridge)(account);
|
|
172
|
+
return [4 /*yield*/, bridgeCache.prepareCurrency(account.currency)];
|
|
173
|
+
case 1:
|
|
174
|
+
_b.sent();
|
|
175
|
+
syncConfig = {
|
|
176
|
+
paginationConfig: {},
|
|
177
|
+
blacklistedTokenIds: blacklistedTokenIds
|
|
178
|
+
};
|
|
179
|
+
observable = bridge.sync(account, syncConfig);
|
|
180
|
+
reduced = observable.pipe((0, operators_1.reduce)(function (a, f) { return f(a); }, account));
|
|
181
|
+
return [4 /*yield*/, reduced.toPromise()];
|
|
182
|
+
case 2:
|
|
183
|
+
synced = _b.sent();
|
|
184
|
+
synchronized[account.id] = synced;
|
|
185
|
+
return [3 /*break*/, 4];
|
|
186
|
+
case 3:
|
|
187
|
+
e_1 = _b.sent();
|
|
188
|
+
failed[account.id] = e_1;
|
|
189
|
+
return [3 /*break*/, 4];
|
|
190
|
+
case 4: return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
})];
|
|
195
|
+
case 1:
|
|
196
|
+
_b.sent();
|
|
197
|
+
return [2 /*return*/, { synchronized: synchronized, failed: failed }];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
exports.syncNewAccountsToImport = syncNewAccountsToImport;
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param existingAccounts
|
|
206
|
+
* @param items: value resulting of importAccountsMakeItems
|
|
207
|
+
* @params selectedAccounts: array of all account ids selected by user for import
|
|
208
|
+
* @param syncedNewAccounts: accounts resulting of syncNewAccountsToImport(). all accounts that would be missing from that list would be ignored to be imported (fresh sync is needed to make sure the accounts are "ready")
|
|
209
|
+
* @returns all accounts
|
|
210
|
+
*/
|
|
211
|
+
var importAccountsReduce = function (existingAccounts, _a) {
|
|
212
|
+
var e_2, _b;
|
|
213
|
+
var items = _a.items, selectedAccounts = _a.selectedAccounts, syncResult = _a.syncResult;
|
|
106
214
|
var accounts = existingAccounts.slice(0);
|
|
107
215
|
var selectedItems = items.filter(function (item) {
|
|
108
216
|
return selectedAccounts.includes(item.account.id);
|
|
109
217
|
});
|
|
110
|
-
var _loop_1 = function (mode,
|
|
218
|
+
var _loop_1 = function (mode, id, initialAccountId) {
|
|
219
|
+
var account = syncResult.synchronized[id];
|
|
220
|
+
if (!account)
|
|
221
|
+
return "continue";
|
|
111
222
|
switch (mode) {
|
|
112
|
-
case "create":
|
|
113
|
-
accounts.
|
|
223
|
+
case "create": {
|
|
224
|
+
var exists = accounts.find(function (a) { return a.id === initialAccountId || a.id === id; });
|
|
225
|
+
if (!exists) {
|
|
226
|
+
// prevent duplicate cases to happen (in case of race condition)
|
|
227
|
+
accounts.push(account);
|
|
228
|
+
}
|
|
114
229
|
break;
|
|
230
|
+
}
|
|
115
231
|
case "update": {
|
|
116
|
-
var item = accounts.find(function (a) { return a.id === initialAccountId; });
|
|
232
|
+
var item = accounts.find(function (a) { return a.id === initialAccountId || a.id === id; });
|
|
117
233
|
var i = accounts.indexOf(item);
|
|
118
|
-
|
|
234
|
+
if (i !== -1) {
|
|
235
|
+
accounts[i] = account;
|
|
236
|
+
}
|
|
119
237
|
break;
|
|
120
238
|
}
|
|
121
239
|
default:
|
|
@@ -123,16 +241,16 @@ var importAccountsReduce = function (existingAccounts, _a) {
|
|
|
123
241
|
};
|
|
124
242
|
try {
|
|
125
243
|
for (var selectedItems_1 = __values(selectedItems), selectedItems_1_1 = selectedItems_1.next(); !selectedItems_1_1.done; selectedItems_1_1 = selectedItems_1.next()) {
|
|
126
|
-
var _c = selectedItems_1_1.value, mode = _c.mode,
|
|
127
|
-
_loop_1(mode,
|
|
244
|
+
var _c = selectedItems_1_1.value, mode = _c.mode, id = _c.account.id, initialAccountId = _c.initialAccountId;
|
|
245
|
+
_loop_1(mode, id, initialAccountId);
|
|
128
246
|
}
|
|
129
247
|
}
|
|
130
|
-
catch (
|
|
248
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
131
249
|
finally {
|
|
132
250
|
try {
|
|
133
251
|
if (selectedItems_1_1 && !selectedItems_1_1.done && (_b = selectedItems_1["return"])) _b.call(selectedItems_1);
|
|
134
252
|
}
|
|
135
|
-
finally { if (
|
|
253
|
+
finally { if (e_2) throw e_2.error; }
|
|
136
254
|
}
|
|
137
255
|
return accounts;
|
|
138
256
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importAccounts.js","sourceRoot":"","sources":["../../src/account/importAccounts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"importAccounts.js","sourceRoot":"","sources":["../../src/account/importAccounts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAqC;AAErC,kCAAgD;AAChD,qCAAwE;AACxE,yFAAmE;AACnE,2DAAqC;AAGrC,oCAA6C;AAC7C,sCAA+C;AAC/C,8BAAgC;AAEhC,4CAAwC;AAExC,IAAM,mBAAmB,GAAG;IAC1B,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,EAAE,EAAE,CAAC;IACL,WAAW,EAAE,CAAC;CACf,CAAC;AAOK,IAAM,uBAAuB,GAAG,UAAC,EAQvC;QAPC,MAAM,YAAA,EACN,QAAQ,cAAA,EACR,KAAK,WAAA;IAML,OAAA,MAAM,CAAC,QAAQ;SACZ,GAAG,CAAC,UAAC,QAAQ;QACZ,IAAM,QAAQ,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CACjC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,EAA/B,CAA+B,CAC1C,CAAC;QACF,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;QAE9B,IAAI;YACF,IAAM,SAAO,GAAG,IAAA,4BAAoB,EAAC,QAAQ,CAAC,CAAC;YAC/C,IAAM,KAAK,GAAG,IAAA,+BAAqB,EAAC,SAAO,CAAC,CAAC;YAE7C,IAAI,KAAK,EAAE;gBACT,OAAO;oBACL,gBAAgB,EAAE,SAAO,CAAC,EAAE;oBAC5B,OAAO,WAAA;oBACP,IAAI,EAAE,aAAa;iBACpB,CAAC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BACb,IAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CACxB,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,EAAE,KAAK,gBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAxC,CAAwC,CAChD,CAAC;gBACF,IAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAe,CAAC,CAAC;gBAC5C,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;oBACZ,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;iBACvB;gBACD,MAAM;aACP;YAED,QAAQ;SACT;;;QA/BH,KAIK,IAAA,kBAAA,SAAA,aAAa,CAAA,4CAAA;YAJP,IAAA,4BAIV,EAHC,IAAI,UAAA,EACO,EAAE,gBAAA,EACb,gBAAgB,sBAAA;oBAFhB,IAAI,EACO,EAAE,EACb,gBAAgB;SA6BjB;;;;;;;;;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA5CW,QAAA,oBAAoB,wBA4C/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importAccounts.test.d.ts","sourceRoot":"","sources":["../../src/account/importAccounts.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
exports.__esModule = true;
|
|
3
|
-
var
|
|
4
|
-
var currencies_1 = require("
|
|
5
|
-
var version_1 = require("
|
|
3
|
+
var _1 = require(".");
|
|
4
|
+
var currencies_1 = require("../currencies");
|
|
5
|
+
var version_1 = require("../platform/version");
|
|
6
6
|
(0, version_1.setPlatformVersion)("1.1.0");
|
|
7
7
|
(0, currencies_1.setSupportedCurrencies)(["ethereum"]);
|
|
8
8
|
describe("importAccountsMakeItems", function () {
|
|
9
|
-
|
|
10
|
-
test.skip("should migrate ethereum accounts", function () {
|
|
9
|
+
test("importing ethereum accounts", function () {
|
|
11
10
|
var result = {
|
|
12
11
|
meta: {
|
|
13
12
|
exporterName: "desktop",
|
|
@@ -15,7 +14,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
15
14
|
},
|
|
16
15
|
accounts: [
|
|
17
16
|
{
|
|
18
|
-
id: "
|
|
17
|
+
id: "js:1:ethereum:0x01:",
|
|
19
18
|
name: "Ethereum 1",
|
|
20
19
|
seedIdentifier: "seed",
|
|
21
20
|
derivationMode: "",
|
|
@@ -26,7 +25,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
26
25
|
swapHistory: []
|
|
27
26
|
},
|
|
28
27
|
{
|
|
29
|
-
id: "
|
|
28
|
+
id: "js:1:ethereum:0x02:",
|
|
30
29
|
name: "Ethereum 2",
|
|
31
30
|
seedIdentifier: "seed",
|
|
32
31
|
derivationMode: "",
|
|
@@ -37,7 +36,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
37
36
|
swapHistory: []
|
|
38
37
|
},
|
|
39
38
|
{
|
|
40
|
-
id: "
|
|
39
|
+
id: "js:1:ethereum:0x04:",
|
|
41
40
|
name: "Ethereum 4",
|
|
42
41
|
seedIdentifier: "seed",
|
|
43
42
|
derivationMode: "",
|
|
@@ -48,7 +47,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
48
47
|
swapHistory: []
|
|
49
48
|
},
|
|
50
49
|
{
|
|
51
|
-
id: "
|
|
50
|
+
id: "js:1:ethereum:0x03:",
|
|
52
51
|
name: "ETH3 name edited",
|
|
53
52
|
seedIdentifier: "seed",
|
|
54
53
|
derivationMode: "",
|
|
@@ -59,7 +58,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
59
58
|
swapHistory: []
|
|
60
59
|
},
|
|
61
60
|
{
|
|
62
|
-
id: "
|
|
61
|
+
id: "js:1:ethereum:0x05:",
|
|
63
62
|
name: "Ethereum 5",
|
|
64
63
|
seedIdentifier: "seed",
|
|
65
64
|
derivationMode: "",
|
|
@@ -79,7 +78,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
79
78
|
};
|
|
80
79
|
var accounts = [
|
|
81
80
|
{
|
|
82
|
-
id: "
|
|
81
|
+
id: "js:1:ethereum:0x01:",
|
|
83
82
|
seedIdentifier: "0x01",
|
|
84
83
|
name: "Ethereum 1",
|
|
85
84
|
derivationMode: "",
|
|
@@ -96,7 +95,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
96
95
|
balance: "51281813126095910"
|
|
97
96
|
},
|
|
98
97
|
{
|
|
99
|
-
id: "
|
|
98
|
+
id: "js:1:ethereum:0x02:",
|
|
100
99
|
seedIdentifier: "0x02",
|
|
101
100
|
name: "Ethereum 2",
|
|
102
101
|
derivationMode: "",
|
|
@@ -113,7 +112,7 @@ describe("importAccountsMakeItems", function () {
|
|
|
113
112
|
balance: "1081392000000000"
|
|
114
113
|
},
|
|
115
114
|
{
|
|
116
|
-
id: "
|
|
115
|
+
id: "js:1:ethereum:0x03:",
|
|
117
116
|
seedIdentifier: "seed",
|
|
118
117
|
name: "Ethereum 3",
|
|
119
118
|
derivationMode: "",
|
|
@@ -129,79 +128,60 @@ describe("importAccountsMakeItems", function () {
|
|
|
129
128
|
lastSyncDate: "2019-07-17T15:13:29.306Z",
|
|
130
129
|
balance: "1081392000000000"
|
|
131
130
|
},
|
|
132
|
-
].map(
|
|
133
|
-
var items = (0,
|
|
131
|
+
].map(_1.fromAccountRaw);
|
|
132
|
+
var items = (0, _1.importAccountsMakeItems)({
|
|
134
133
|
result: result,
|
|
135
134
|
accounts: accounts
|
|
136
135
|
});
|
|
137
136
|
expect(items).toMatchObject([
|
|
138
137
|
{
|
|
139
|
-
initialAccountId: "
|
|
140
|
-
account: {
|
|
141
|
-
id: "libcore:1:ethereum:xpub4:",
|
|
142
|
-
name: "Ethereum 4"
|
|
143
|
-
},
|
|
138
|
+
initialAccountId: "js:1:ethereum:0x04:",
|
|
139
|
+
account: { id: "js:1:ethereum:0x04:", name: "Ethereum 4" },
|
|
144
140
|
mode: "create"
|
|
145
141
|
},
|
|
146
142
|
{
|
|
147
|
-
initialAccountId: "
|
|
148
|
-
account: {
|
|
149
|
-
id: "libcore:1:ethereum:xpub5:",
|
|
150
|
-
name: "Ethereum 5"
|
|
151
|
-
},
|
|
143
|
+
initialAccountId: "js:1:ethereum:0x05:",
|
|
144
|
+
account: { id: "js:1:ethereum:0x05:", name: "Ethereum 5" },
|
|
152
145
|
mode: "create"
|
|
153
146
|
},
|
|
154
147
|
{
|
|
155
|
-
initialAccountId: "
|
|
156
|
-
account: {
|
|
157
|
-
id: "libcore:1:ethereum:xpub1:",
|
|
158
|
-
name: "Ethereum 1"
|
|
159
|
-
},
|
|
148
|
+
initialAccountId: "js:1:ethereum:0x03:",
|
|
149
|
+
account: { id: "js:1:ethereum:0x03:", name: "ETH3 name edited" },
|
|
160
150
|
mode: "update"
|
|
161
151
|
},
|
|
162
152
|
{
|
|
163
|
-
initialAccountId: "
|
|
164
|
-
account: {
|
|
165
|
-
|
|
166
|
-
name: "Ethereum 2"
|
|
167
|
-
},
|
|
168
|
-
mode: "update"
|
|
153
|
+
initialAccountId: "js:1:ethereum:0x01:",
|
|
154
|
+
account: { id: "js:1:ethereum:0x01:", name: "Ethereum 1" },
|
|
155
|
+
mode: "id"
|
|
169
156
|
},
|
|
170
157
|
{
|
|
171
|
-
initialAccountId: "
|
|
172
|
-
account: {
|
|
173
|
-
|
|
174
|
-
name: "ETH3 name edited"
|
|
175
|
-
},
|
|
176
|
-
mode: "update"
|
|
158
|
+
initialAccountId: "js:1:ethereum:0x02:",
|
|
159
|
+
account: { id: "js:1:ethereum:0x02:", name: "Ethereum 2" },
|
|
160
|
+
mode: "id"
|
|
177
161
|
},
|
|
178
162
|
]);
|
|
179
|
-
var
|
|
163
|
+
var syncResult = {
|
|
164
|
+
failed: {},
|
|
165
|
+
synchronized: {}
|
|
166
|
+
};
|
|
167
|
+
result.accounts.forEach(function (a) {
|
|
168
|
+
syncResult.synchronized[a.id] = a;
|
|
169
|
+
});
|
|
170
|
+
var reduced = (0, _1.importAccountsReduce)(accounts, {
|
|
180
171
|
items: items,
|
|
181
172
|
selectedAccounts: [
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
]
|
|
173
|
+
"js:1:ethereum:0x03:",
|
|
174
|
+
"js:1:ethereum:0x02:",
|
|
175
|
+
"js:1:ethereum:0x05:",
|
|
176
|
+
],
|
|
177
|
+
syncResult: syncResult
|
|
186
178
|
});
|
|
187
179
|
expect(reduced).toMatchObject([
|
|
188
|
-
{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
id: "libcore:1:ethereum:xpub2:",
|
|
194
|
-
name: "Ethereum 2"
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
id: "libcore:1:ethereum:xpub3:",
|
|
198
|
-
name: "ETH3 name edited"
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
id: "libcore:1:ethereum:xpub5:",
|
|
202
|
-
name: "Ethereum 5"
|
|
203
|
-
},
|
|
180
|
+
{ id: "js:1:ethereum:0x01:", name: "Ethereum 1" },
|
|
181
|
+
{ id: "js:1:ethereum:0x02:", name: "Ethereum 2" },
|
|
182
|
+
{ id: "js:1:ethereum:0x03:", name: "ETH3 name edited" },
|
|
183
|
+
{ id: "js:1:ethereum:0x05:", name: "Ethereum 5" },
|
|
204
184
|
]);
|
|
205
185
|
});
|
|
206
186
|
});
|
|
207
|
-
//# sourceMappingURL=importAccounts.js.map
|
|
187
|
+
//# sourceMappingURL=importAccounts.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importAccounts.test.js","sourceRoot":"","sources":["../../src/account/importAccounts.test.ts"],"names":[],"mappings":";;AACA,sBAIW;AACX,4CAAuD;AACvD,+CAAyD;AAEzD,IAAA,4BAAkB,EAAC,OAAO,CAAC,CAAC;AAE5B,IAAA,mCAAsB,EAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACrC,QAAQ,CAAC,yBAAyB,EAAE;IAClC,IAAI,CAAC,6BAA6B,EAAE;QAClC,IAAM,M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,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,CAAC;YACxB,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,IAAM,OAAO,GAAG,IAAA,uBAAoB,EAAC,QAAQ,EAAE;YAC7C,KAAK,OAAA;YACL,gBAAgB,EAAE;gBAChB,qBAAqB;gBACrB,qBAAqB;gBACrB,qBAAqB;aACtB;YACD,UAAU,YAAA;SACX,CAAC,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;YAC5B,EAAE,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE;YACjD,EAAE,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE;YACjD,EAAE,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE,kBAAkB,EAAE;YACvD,EAAE,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE;SAClD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import "../__tests__/test-helpers/setup";
|
|
2
|
+
import { makeBridgeCacheSystem } from "../bridge/cache";
|
|
3
|
+
import { accountToAccountData } from "../cross";
|
|
4
|
+
import {
|
|
5
|
+
importAccountsMakeItems,
|
|
6
|
+
importAccountsReduce,
|
|
7
|
+
fromAccountRaw,
|
|
8
|
+
syncNewAccountsToImport,
|
|
9
|
+
} from ".";
|
|
10
|
+
import { Account } from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
jest.setTimeout(200000);
|
|
13
|
+
|
|
14
|
+
test("importAccounts with a set of real data", async () => {
|
|
15
|
+
const accounts = [
|
|
16
|
+
{
|
|
17
|
+
id: "js:2:algorand:32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI:",
|
|
18
|
+
seedIdentifier:
|
|
19
|
+
"32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
20
|
+
name: "Algorand legacy 32PI2C5H...RXBSVWQI",
|
|
21
|
+
starred: true,
|
|
22
|
+
used: true,
|
|
23
|
+
derivationMode: "",
|
|
24
|
+
index: 0,
|
|
25
|
+
freshAddress:
|
|
26
|
+
"32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
27
|
+
freshAddressPath: "44'/283'/0'/0/0",
|
|
28
|
+
freshAddresses: [],
|
|
29
|
+
blockHeight: 23066613,
|
|
30
|
+
creationDate: "2022-02-04T13:12:58.000Z",
|
|
31
|
+
operationsCount: 184,
|
|
32
|
+
operations: [],
|
|
33
|
+
pendingOperations: [],
|
|
34
|
+
currencyId: "algorand",
|
|
35
|
+
unitMagnitude: 6,
|
|
36
|
+
lastSyncDate: "2022-08-26T09:24:27.076Z",
|
|
37
|
+
balance: "2100190",
|
|
38
|
+
spendableBalance: "190",
|
|
39
|
+
xpub: "32PI2C5HLHMVUF5KMNURLGCTYVIOVJJ2NLHLZ2PIMK567MKMS4RXBSVWQI",
|
|
40
|
+
subAccounts: [],
|
|
41
|
+
algorandResources: { rewards: "190", nbAssets: 20 },
|
|
42
|
+
swapHistory: [],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "js:2:tron:TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK:",
|
|
46
|
+
seedIdentifier: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
47
|
+
name: "Tron legacy TRbtdwHo...5sx3fFCK",
|
|
48
|
+
starred: true,
|
|
49
|
+
used: true,
|
|
50
|
+
derivationMode: "",
|
|
51
|
+
index: 0,
|
|
52
|
+
freshAddress: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
53
|
+
freshAddressPath: "44'/195'/0'/0/0",
|
|
54
|
+
freshAddresses: [],
|
|
55
|
+
blockHeight: 43642499,
|
|
56
|
+
creationDate: "2022-07-19T15:32:12.000Z",
|
|
57
|
+
operationsCount: 41,
|
|
58
|
+
operations: [],
|
|
59
|
+
pendingOperations: [],
|
|
60
|
+
currencyId: "tron",
|
|
61
|
+
unitMagnitude: 6,
|
|
62
|
+
lastSyncDate: "2022-08-26T09:24:59.492Z",
|
|
63
|
+
balance: "0",
|
|
64
|
+
spendableBalance: "0",
|
|
65
|
+
xpub: "TRbtdwHowocq8ThZbRnTHgK4JG5sx3fFCK",
|
|
66
|
+
subAccounts: [],
|
|
67
|
+
tronResources: {
|
|
68
|
+
frozen: {},
|
|
69
|
+
delegatedFrozen: {},
|
|
70
|
+
votes: [],
|
|
71
|
+
tronPower: 0,
|
|
72
|
+
energy: "0",
|
|
73
|
+
bandwidth: {
|
|
74
|
+
freeUsed: "0",
|
|
75
|
+
freeLimit: "1500",
|
|
76
|
+
gainedUsed: "0",
|
|
77
|
+
gainedLimit: "0",
|
|
78
|
+
},
|
|
79
|
+
unwithdrawnReward: "2730",
|
|
80
|
+
lastVotedDate: "2022-07-22T14:39:51.000Z",
|
|
81
|
+
cacheTransactionInfoById: {},
|
|
82
|
+
},
|
|
83
|
+
swapHistory: [],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "js:2:polkadot:15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP:polkadotbip44",
|
|
87
|
+
seedIdentifier: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
88
|
+
name: "Polkadot polkadotbip44 15jLBbe9...5KrKM1eP",
|
|
89
|
+
starred: true,
|
|
90
|
+
used: true,
|
|
91
|
+
derivationMode: "polkadotbip44",
|
|
92
|
+
index: 0,
|
|
93
|
+
freshAddress: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
94
|
+
freshAddressPath: "44'/354'/0'/0'/0'",
|
|
95
|
+
freshAddresses: [],
|
|
96
|
+
blockHeight: 11771108,
|
|
97
|
+
creationDate: "2022-02-24T14:39:00.007Z",
|
|
98
|
+
operationsCount: 65,
|
|
99
|
+
operations: [],
|
|
100
|
+
pendingOperations: [],
|
|
101
|
+
currencyId: "polkadot",
|
|
102
|
+
unitMagnitude: 10,
|
|
103
|
+
lastSyncDate: "2022-08-26T09:25:00.713Z",
|
|
104
|
+
balance: "15512511464",
|
|
105
|
+
spendableBalance: "15512511464",
|
|
106
|
+
xpub: "15jLBbe9LD6VSUYFkV5Fmo5LhZU5cns9E6g8qcDv5KrKM1eP",
|
|
107
|
+
polkadotResources: {
|
|
108
|
+
controller: null,
|
|
109
|
+
stash: null,
|
|
110
|
+
nonce: 63,
|
|
111
|
+
lockedBalance: "0",
|
|
112
|
+
unlockedBalance: "0",
|
|
113
|
+
unlockingBalance: "0",
|
|
114
|
+
unlockings: [],
|
|
115
|
+
nominations: [],
|
|
116
|
+
},
|
|
117
|
+
swapHistory: [],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "js:2:bsc:0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB:",
|
|
121
|
+
seedIdentifier: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
122
|
+
name: "Binance Smart Chain legacy 0xa22CA8...CdD06FAB",
|
|
123
|
+
starred: true,
|
|
124
|
+
used: true,
|
|
125
|
+
derivationMode: "",
|
|
126
|
+
index: 0,
|
|
127
|
+
freshAddress: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
128
|
+
freshAddressPath: "44'/60'/0'/0/0",
|
|
129
|
+
freshAddresses: [],
|
|
130
|
+
blockHeight: 20775454,
|
|
131
|
+
syncHash: "[]_655",
|
|
132
|
+
creationDate: "2022-02-04T13:11:32.001Z",
|
|
133
|
+
operationsCount: 21,
|
|
134
|
+
operations: [],
|
|
135
|
+
pendingOperations: [],
|
|
136
|
+
currencyId: "bsc",
|
|
137
|
+
unitMagnitude: 18,
|
|
138
|
+
lastSyncDate: "2022-08-26T09:25:01.109Z",
|
|
139
|
+
balance: "3128019430408477",
|
|
140
|
+
spendableBalance: "3128019430408477",
|
|
141
|
+
xpub: "0xa22CA840265d3C5CB1846e419B14c6a6CdD06FAB",
|
|
142
|
+
subAccounts: [],
|
|
143
|
+
swapHistory: [],
|
|
144
|
+
},
|
|
145
|
+
].map(fromAccountRaw);
|
|
146
|
+
|
|
147
|
+
const localCache = {};
|
|
148
|
+
const bridgeCache = makeBridgeCacheSystem({
|
|
149
|
+
saveData(c, d) {
|
|
150
|
+
localCache[c.id] = d;
|
|
151
|
+
return Promise.resolve();
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
getData(c) {
|
|
155
|
+
return Promise.resolve(localCache[c.id]);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const result = {
|
|
160
|
+
accounts: accounts.map(accountToAccountData),
|
|
161
|
+
settings: { currenciesSettings: {}, pairExchanges: {} },
|
|
162
|
+
meta: { exporterName: "Test", exporterVersion: "0" },
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const accountsState = [];
|
|
166
|
+
|
|
167
|
+
const items = importAccountsMakeItems({
|
|
168
|
+
result,
|
|
169
|
+
accounts: accountsState,
|
|
170
|
+
});
|
|
171
|
+
const selectedAccounts = accounts.map((a) => a.id);
|
|
172
|
+
const syncResult = await syncNewAccountsToImport(
|
|
173
|
+
{ items, selectedAccounts },
|
|
174
|
+
bridgeCache
|
|
175
|
+
);
|
|
176
|
+
const reduced = importAccountsReduce(accountsState, {
|
|
177
|
+
items,
|
|
178
|
+
selectedAccounts,
|
|
179
|
+
syncResult,
|
|
180
|
+
});
|
|
181
|
+
expect(reduced.length).toEqual(4);
|
|
182
|
+
expect((reduced[0] as AlgorandAccount).algorandResources).toBeDefined();
|
|
183
|
+
expect((reduced[1] as TronAccount).tronResources).toBeDefined();
|
|
184
|
+
expect((reduced[2] as PolkadotAccount).polkadotResources).toBeDefined();
|
|
185
|
+
expect(reduced[0].operations.length).toBeGreaterThan(1);
|
|
186
|
+
expect(reduced[1].operations.length).toBeGreaterThan(1);
|
|
187
|
+
expect(reduced[2].operations.length).toBeGreaterThan(1);
|
|
188
|
+
expect(reduced[3].operations.length).toBeGreaterThan(1);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
type AlgorandAccount = Account & { algorandResources: any };
|
|
192
|
+
type TronAccount = Account & { tronResources: any };
|
|
193
|
+
type PolkadotAccount = Account & { polkadotResources: any };
|
|
@@ -3,16 +3,15 @@ import {
|
|
|
3
3
|
importAccountsMakeItems,
|
|
4
4
|
importAccountsReduce,
|
|
5
5
|
fromAccountRaw,
|
|
6
|
-
} from "
|
|
7
|
-
import { setSupportedCurrencies } from "
|
|
8
|
-
import { setPlatformVersion } from "
|
|
6
|
+
} from ".";
|
|
7
|
+
import { setSupportedCurrencies } from "../currencies";
|
|
8
|
+
import { setPlatformVersion } from "../platform/version";
|
|
9
9
|
|
|
10
10
|
setPlatformVersion("1.1.0");
|
|
11
11
|
|
|
12
12
|
setSupportedCurrencies(["ethereum"]);
|
|
13
13
|
describe("importAccountsMakeItems", () => {
|
|
14
|
-
|
|
15
|
-
test.skip("should migrate ethereum accounts", () => {
|
|
14
|
+
test("importing ethereum accounts", () => {
|
|
16
15
|
const result = {
|
|
17
16
|
meta: {
|
|
18
17
|
exporterName: "desktop",
|
|
@@ -20,7 +19,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
20
19
|
},
|
|
21
20
|
accounts: [
|
|
22
21
|
{
|
|
23
|
-
id: "
|
|
22
|
+
id: "js:1:ethereum:0x01:",
|
|
24
23
|
name: "Ethereum 1",
|
|
25
24
|
seedIdentifier: "seed",
|
|
26
25
|
derivationMode: "",
|
|
@@ -31,7 +30,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
31
30
|
swapHistory: [],
|
|
32
31
|
},
|
|
33
32
|
{
|
|
34
|
-
id: "
|
|
33
|
+
id: "js:1:ethereum:0x02:",
|
|
35
34
|
name: "Ethereum 2",
|
|
36
35
|
seedIdentifier: "seed",
|
|
37
36
|
derivationMode: "",
|
|
@@ -42,7 +41,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
42
41
|
swapHistory: [],
|
|
43
42
|
},
|
|
44
43
|
{
|
|
45
|
-
id: "
|
|
44
|
+
id: "js:1:ethereum:0x04:",
|
|
46
45
|
name: "Ethereum 4",
|
|
47
46
|
seedIdentifier: "seed",
|
|
48
47
|
derivationMode: "",
|
|
@@ -53,7 +52,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
53
52
|
swapHistory: [],
|
|
54
53
|
},
|
|
55
54
|
{
|
|
56
|
-
id: "
|
|
55
|
+
id: "js:1:ethereum:0x03:",
|
|
57
56
|
name: "ETH3 name edited",
|
|
58
57
|
seedIdentifier: "seed",
|
|
59
58
|
derivationMode: "",
|
|
@@ -64,7 +63,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
64
63
|
swapHistory: [],
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
|
-
id: "
|
|
66
|
+
id: "js:1:ethereum:0x05:",
|
|
68
67
|
name: "Ethereum 5",
|
|
69
68
|
seedIdentifier: "seed",
|
|
70
69
|
derivationMode: "",
|
|
@@ -84,7 +83,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
84
83
|
};
|
|
85
84
|
const accounts = [
|
|
86
85
|
<AccountRaw>{
|
|
87
|
-
id: "
|
|
86
|
+
id: "js:1:ethereum:0x01:",
|
|
88
87
|
seedIdentifier: "0x01",
|
|
89
88
|
name: "Ethereum 1",
|
|
90
89
|
derivationMode: "",
|
|
@@ -101,7 +100,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
101
100
|
balance: "51281813126095910",
|
|
102
101
|
},
|
|
103
102
|
<AccountRaw>{
|
|
104
|
-
id: "
|
|
103
|
+
id: "js:1:ethereum:0x02:",
|
|
105
104
|
seedIdentifier: "0x02",
|
|
106
105
|
name: "Ethereum 2",
|
|
107
106
|
derivationMode: "",
|
|
@@ -118,7 +117,7 @@ describe("importAccountsMakeItems", () => {
|
|
|
118
117
|
balance: "1081392000000000",
|
|
119
118
|
},
|
|
120
119
|
<AccountRaw>{
|
|
121
|
-
id: "
|
|
120
|
+
id: "js:1:ethereum:0x03:",
|
|
122
121
|
seedIdentifier: "seed",
|
|
123
122
|
name: "Ethereum 3",
|
|
124
123
|
derivationMode: "",
|
|
@@ -141,71 +140,52 @@ describe("importAccountsMakeItems", () => {
|
|
|
141
140
|
});
|
|
142
141
|
expect(items).toMatchObject([
|
|
143
142
|
{
|
|
144
|
-
initialAccountId: "
|
|
145
|
-
account: {
|
|
146
|
-
id: "libcore:1:ethereum:xpub4:",
|
|
147
|
-
name: "Ethereum 4",
|
|
148
|
-
},
|
|
143
|
+
initialAccountId: "js:1:ethereum:0x04:",
|
|
144
|
+
account: { id: "js:1:ethereum:0x04:", name: "Ethereum 4" },
|
|
149
145
|
mode: "create",
|
|
150
146
|
},
|
|
151
147
|
{
|
|
152
|
-
initialAccountId: "
|
|
153
|
-
account: {
|
|
154
|
-
id: "libcore:1:ethereum:xpub5:",
|
|
155
|
-
name: "Ethereum 5",
|
|
156
|
-
},
|
|
148
|
+
initialAccountId: "js:1:ethereum:0x05:",
|
|
149
|
+
account: { id: "js:1:ethereum:0x05:", name: "Ethereum 5" },
|
|
157
150
|
mode: "create",
|
|
158
151
|
},
|
|
159
152
|
{
|
|
160
|
-
initialAccountId: "
|
|
161
|
-
account: {
|
|
162
|
-
id: "libcore:1:ethereum:xpub1:",
|
|
163
|
-
name: "Ethereum 1",
|
|
164
|
-
},
|
|
153
|
+
initialAccountId: "js:1:ethereum:0x03:",
|
|
154
|
+
account: { id: "js:1:ethereum:0x03:", name: "ETH3 name edited" },
|
|
165
155
|
mode: "update",
|
|
166
156
|
},
|
|
167
157
|
{
|
|
168
|
-
initialAccountId: "
|
|
169
|
-
account: {
|
|
170
|
-
|
|
171
|
-
name: "Ethereum 2",
|
|
172
|
-
},
|
|
173
|
-
mode: "update",
|
|
158
|
+
initialAccountId: "js:1:ethereum:0x01:",
|
|
159
|
+
account: { id: "js:1:ethereum:0x01:", name: "Ethereum 1" },
|
|
160
|
+
mode: "id",
|
|
174
161
|
},
|
|
175
162
|
{
|
|
176
|
-
initialAccountId: "
|
|
177
|
-
account: {
|
|
178
|
-
|
|
179
|
-
name: "ETH3 name edited",
|
|
180
|
-
},
|
|
181
|
-
mode: "update",
|
|
163
|
+
initialAccountId: "js:1:ethereum:0x02:",
|
|
164
|
+
account: { id: "js:1:ethereum:0x02:", name: "Ethereum 2" },
|
|
165
|
+
mode: "id",
|
|
182
166
|
},
|
|
183
167
|
]);
|
|
168
|
+
const syncResult = {
|
|
169
|
+
failed: {},
|
|
170
|
+
synchronized: {},
|
|
171
|
+
};
|
|
172
|
+
result.accounts.forEach((a) => {
|
|
173
|
+
syncResult.synchronized[a.id] = a;
|
|
174
|
+
});
|
|
184
175
|
const reduced = importAccountsReduce(accounts, {
|
|
185
176
|
items,
|
|
186
177
|
selectedAccounts: [
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
178
|
+
"js:1:ethereum:0x03:",
|
|
179
|
+
"js:1:ethereum:0x02:",
|
|
180
|
+
"js:1:ethereum:0x05:",
|
|
190
181
|
],
|
|
182
|
+
syncResult,
|
|
191
183
|
});
|
|
192
184
|
expect(reduced).toMatchObject([
|
|
193
|
-
{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
id: "libcore:1:ethereum:xpub2:",
|
|
199
|
-
name: "Ethereum 2",
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
id: "libcore:1:ethereum:xpub3:",
|
|
203
|
-
name: "ETH3 name edited",
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
id: "libcore:1:ethereum:xpub5:",
|
|
207
|
-
name: "Ethereum 5",
|
|
208
|
-
},
|
|
185
|
+
{ id: "js:1:ethereum:0x01:", name: "Ethereum 1" },
|
|
186
|
+
{ id: "js:1:ethereum:0x02:", name: "Ethereum 2" },
|
|
187
|
+
{ id: "js:1:ethereum:0x03:", name: "ETH3 name edited" },
|
|
188
|
+
{ id: "js:1:ethereum:0x05:", name: "Ethereum 5" },
|
|
209
189
|
]);
|
|
210
190
|
});
|
|
211
191
|
});
|
|
@@ -5,6 +5,13 @@ import { findAccountMigration, checkAccountSupported } from "./support";
|
|
|
5
5
|
import joinSwapHistories from "../exchange/swap/joinSwapHistories";
|
|
6
6
|
import isEqual from "lodash/isEqual";
|
|
7
7
|
import type { Account } from "@ledgerhq/types-live";
|
|
8
|
+
import { BridgeCacheSystem } from "../bridge/cache";
|
|
9
|
+
import { getAccountBridge } from "../bridge";
|
|
10
|
+
import { promiseAllBatched } from "../promise";
|
|
11
|
+
import { getEnv } from "../env";
|
|
12
|
+
import { Observable } from "rxjs";
|
|
13
|
+
import { reduce } from "rxjs/operators";
|
|
14
|
+
|
|
8
15
|
const itemModeDisplaySort = {
|
|
9
16
|
create: 1,
|
|
10
17
|
update: 2,
|
|
@@ -103,31 +110,115 @@ export const importAccountsMakeItems = ({
|
|
|
103
110
|
itemModeDisplaySort[(a as ImportItem).mode] -
|
|
104
111
|
itemModeDisplaySort[(b as ImportItem).mode]
|
|
105
112
|
) as ImportItem[];
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* SyncNewAccountsOutput
|
|
116
|
+
* - synchronized: a map of account id to account. the account id are kept as originally set in the items[].account before a possible "remap" of the ids after a sync happened
|
|
117
|
+
* - failed: a map of account id to errors for all possible fails that happened.
|
|
118
|
+
*/
|
|
119
|
+
export type SyncNewAccountsOutput = {
|
|
120
|
+
synchronized: Record<string, Account>;
|
|
121
|
+
failed: Record<string, Error>;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type SyncNewAccountsInput = {
|
|
125
|
+
items: ImportItem[];
|
|
126
|
+
selectedAccounts: string[];
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @param items: result of importAccountsMakeItems
|
|
132
|
+
* @param selectedAccounts: user's selected accounts
|
|
133
|
+
* @param bridgeCache: the bridge cache created on user land to prepare currency for a sync
|
|
134
|
+
* @param blacklistedTokenIds: the list of blacklisted token ids to ignore sync with
|
|
135
|
+
* @returns SyncNewAccountsOutput
|
|
136
|
+
*/
|
|
137
|
+
export const syncNewAccountsToImport = async (
|
|
138
|
+
{ items, selectedAccounts }: SyncNewAccountsInput,
|
|
139
|
+
bridgeCache: BridgeCacheSystem,
|
|
140
|
+
blacklistedTokenIds?: string[]
|
|
141
|
+
): Promise<SyncNewAccountsOutput> => {
|
|
142
|
+
const selectedItems = items.filter((item) =>
|
|
143
|
+
selectedAccounts.includes(item.account.id)
|
|
144
|
+
);
|
|
145
|
+
const synchronized = {};
|
|
146
|
+
const failed = {};
|
|
147
|
+
await promiseAllBatched(
|
|
148
|
+
getEnv("SYNC_MAX_CONCURRENT"),
|
|
149
|
+
selectedItems,
|
|
150
|
+
async ({ account }) => {
|
|
151
|
+
try {
|
|
152
|
+
const bridge = getAccountBridge(account);
|
|
153
|
+
await bridgeCache.prepareCurrency(account.currency);
|
|
154
|
+
const syncConfig = {
|
|
155
|
+
paginationConfig: {},
|
|
156
|
+
blacklistedTokenIds,
|
|
157
|
+
};
|
|
158
|
+
const observable = bridge.sync(account, syncConfig);
|
|
159
|
+
const reduced: Observable<Account> = observable.pipe(
|
|
160
|
+
reduce((a, f: (_: Account) => Account) => f(a), account)
|
|
161
|
+
);
|
|
162
|
+
const synced = await reduced.toPromise();
|
|
163
|
+
synchronized[account.id] = synced;
|
|
164
|
+
} catch (e) {
|
|
165
|
+
failed[account.id] = e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
return { synchronized, failed };
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type ImportAccountsReduceInput = {
|
|
173
|
+
items: ImportItem[];
|
|
174
|
+
selectedAccounts: string[];
|
|
175
|
+
syncResult: SyncNewAccountsOutput;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
* @param existingAccounts
|
|
181
|
+
* @param items: value resulting of importAccountsMakeItems
|
|
182
|
+
* @params selectedAccounts: array of all account ids selected by user for import
|
|
183
|
+
* @param syncedNewAccounts: accounts resulting of syncNewAccountsToImport(). all accounts that would be missing from that list would be ignored to be imported (fresh sync is needed to make sure the accounts are "ready")
|
|
184
|
+
* @returns all accounts
|
|
185
|
+
*/
|
|
106
186
|
export const importAccountsReduce = (
|
|
107
187
|
existingAccounts: Account[],
|
|
108
|
-
{
|
|
109
|
-
items,
|
|
110
|
-
selectedAccounts,
|
|
111
|
-
}: {
|
|
112
|
-
items: ImportItem[];
|
|
113
|
-
selectedAccounts: string[];
|
|
114
|
-
}
|
|
188
|
+
{ items, selectedAccounts, syncResult }: ImportAccountsReduceInput
|
|
115
189
|
): Account[] => {
|
|
116
190
|
const accounts = existingAccounts.slice(0);
|
|
117
191
|
const selectedItems = items.filter((item) =>
|
|
118
192
|
selectedAccounts.includes(item.account.id)
|
|
119
193
|
);
|
|
120
194
|
|
|
121
|
-
for (const {
|
|
195
|
+
for (const {
|
|
196
|
+
mode,
|
|
197
|
+
account: { id },
|
|
198
|
+
initialAccountId,
|
|
199
|
+
} of selectedItems) {
|
|
200
|
+
const account = syncResult.synchronized[id];
|
|
201
|
+
if (!account) continue;
|
|
122
202
|
switch (mode) {
|
|
123
|
-
case "create":
|
|
124
|
-
accounts.
|
|
203
|
+
case "create": {
|
|
204
|
+
const exists = accounts.find(
|
|
205
|
+
(a) => a.id === initialAccountId || a.id === id
|
|
206
|
+
);
|
|
207
|
+
if (!exists) {
|
|
208
|
+
// prevent duplicate cases to happen (in case of race condition)
|
|
209
|
+
accounts.push(account);
|
|
210
|
+
}
|
|
125
211
|
break;
|
|
212
|
+
}
|
|
126
213
|
|
|
127
214
|
case "update": {
|
|
128
|
-
const item = accounts.find(
|
|
215
|
+
const item = accounts.find(
|
|
216
|
+
(a) => a.id === initialAccountId || a.id === id
|
|
217
|
+
);
|
|
129
218
|
const i = accounts.indexOf(item as Account);
|
|
130
|
-
|
|
219
|
+
if (i !== -1) {
|
|
220
|
+
accounts[i] = account;
|
|
221
|
+
}
|
|
131
222
|
break;
|
|
132
223
|
}
|
|
133
224
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"importAccounts.d.ts","sourceRoot":"","sources":["../../../src/__tests__/accounts/importAccounts.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"importAccounts.js","sourceRoot":"","sources":["../../../src/__tests__/accounts/importAccounts.ts"],"names":[],"mappings":";;AACA,yCAIuB;AACvB,+CAA0D;AAC1D,kDAA4D;AAE5D,IAAA,4BAAkB,EAAC,OAAO,CAAC,CAAC;AAE5B,IAAA,mCAAsB,EAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACrC,QAAQ,CAAC,yBAAyB,EAAE;IAClC,iHAAiH;IACjH,IAAI,CAAC,IAAI,CAAC,kCAAkC,EAAE;QAC5C,IAAM,MAAM,GAAG;YACb,IAAI,EAAE;gBACJ,YAAY,EAAE,SAAS;gBACvB,eAAe,EAAE,QAAQ;aAC1B;YACD,QAAQ,EAAE;gBACR;oBACE,EAAE,EAAE,2BAA2B;oBAC/B,IAAI,EAAE,YAAY;oBAClB,cAAc,EAAE,MAAM;oBACtB,cAAc,EAAE,EAAE;oBAClB,YAAY,EAAE,MAAM;oBACpB,UAAU,EAAE,UAAU;oBACtB,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE,mBAAmB;oBAC5B,WAAW,EAAE,EAAE;iBAChB;gBACD;oBACE,EAAE,EAAE,2BAA2B;oBAC/B,IAAI,EAAE,YAAY;oBAClB,cAAc,EAAE,MAAM;oBACtB,cAAc,EAA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