@ledgerhq/live-common 21.19.0 → 21.19.4
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/__tests__/test-helpers/setup.js +1 -0
- package/lib/__tests__/test-helpers/setup.js.map +1 -1
- package/lib/account/helpers.d.ts.map +1 -1
- package/lib/account/helpers.js +1 -0
- package/lib/account/helpers.js.map +1 -1
- package/lib/api/Ethereum.d.ts.map +1 -1
- package/lib/api/Ethereum.js +3 -1
- package/lib/api/Ethereum.js.map +1 -1
- package/lib/api/explorerConfig/index.d.ts.map +1 -1
- package/lib/api/explorerConfig/index.js +0 -4
- package/lib/api/explorerConfig/index.js.map +1 -1
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +7 -6
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/env.d.ts +10 -5
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +5 -0
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/families/bitcoin/test-dataset.js +2 -2
- package/lib/families/bitcoin/test-dataset.js.map +1 -1
- package/lib/families/ethereum/bridge/js.d.ts.map +1 -1
- package/lib/families/ethereum/bridge/js.js +3 -0
- package/lib/families/ethereum/bridge/js.js.map +1 -1
- package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc1155.js +21 -9
- package/lib/families/ethereum/modules/erc1155.js.map +1 -1
- package/lib/families/ethereum/modules/erc721.d.ts +3 -1
- package/lib/families/ethereum/modules/erc721.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc721.js +101 -7
- package/lib/families/ethereum/modules/erc721.js.map +1 -1
- package/lib/families/ethereum/modules/index.d.ts +5 -0
- package/lib/families/ethereum/modules/index.d.ts.map +1 -1
- package/lib/families/ethereum/modules/index.js +9 -1
- package/lib/families/ethereum/modules/index.js.map +1 -1
- package/lib/families/ethereum/nft.test.js +227 -34
- package/lib/families/ethereum/nft.test.js.map +1 -1
- package/lib/families/ethereum/signOperation.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +3 -4
- package/lib/families/ethereum/signOperation.js.map +1 -1
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.js +21 -38
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/ethereum/transaction.d.ts.map +1 -1
- package/lib/families/ethereum/transaction.js +4 -4
- package/lib/families/ethereum/transaction.js.map +1 -1
- package/lib/families/ethereum/types.d.ts +2 -0
- package/lib/families/ethereum/types.d.ts.map +1 -1
- package/lib/families/ethereum/types.js.map +1 -1
- package/lib/nft/helpers.d.ts +1 -2
- package/lib/nft/helpers.d.ts.map +1 -1
- package/lib/nft/helpers.js +13 -20
- package/lib/nft/helpers.js.map +1 -1
- package/lib/nft/index.d.ts +1 -0
- package/lib/nft/index.d.ts.map +1 -1
- package/lib/nft/index.js +1 -0
- package/lib/nft/index.js.map +1 -1
- package/lib/nft/support.d.ts +4 -0
- package/lib/nft/support.d.ts.map +1 -0
- package/lib/nft/support.js +16 -0
- package/lib/nft/support.js.map +1 -0
- package/lib/reconciliation.d.ts.map +1 -1
- package/lib/reconciliation.js +5 -1
- package/lib/reconciliation.js.map +1 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/__tests__/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -49
- package/src/__tests__/test-helpers/setup.ts +1 -0
- package/src/account/helpers.ts +1 -0
- package/src/api/Ethereum.ts +5 -4
- package/src/api/explorerConfig/index.ts +0 -4
- package/src/bridge/jsHelpers.ts +7 -6
- package/src/currencies/__snapshots__/.DS_Store +0 -0
- package/src/env.ts +5 -0
- package/src/families/bitcoin/test-dataset.ts +2 -2
- package/src/families/ethereum/bridge/js.ts +8 -1
- package/src/families/ethereum/modules/erc1155.ts +22 -7
- package/src/families/ethereum/modules/erc721.ts +42 -4
- package/src/families/ethereum/modules/index.ts +20 -0
- package/src/families/ethereum/nft.test.ts +199 -26
- package/src/families/ethereum/signOperation.ts +2 -3
- package/src/families/ethereum/synchronisation.ts +104 -113
- package/src/families/ethereum/transaction.ts +8 -4
- package/src/families/ethereum/types.ts +2 -0
- package/src/nft/helpers.ts +13 -21
- package/src/nft/index.ts +1 -0
- package/src/nft/support.ts +16 -0
- package/src/reconciliation.ts +4 -1
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +0 -6152
|
@@ -15,13 +15,12 @@ import {
|
|
|
15
15
|
} from "../../account";
|
|
16
16
|
import { listTokensForCryptoCurrency } from "../../currencies";
|
|
17
17
|
import { encodeAccountId } from "../../account";
|
|
18
|
-
import type { Operation, TokenAccount, Account
|
|
18
|
+
import type { Operation, TokenAccount, Account } from "../../types";
|
|
19
19
|
import { API, apiForCurrency, Tx } from "../../api/Ethereum";
|
|
20
20
|
import { digestTokenAccounts, prepareTokenAccounts } from "./modules";
|
|
21
21
|
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
22
|
-
import { encodeNftId, nftsFromOperations } from "../../nft";
|
|
22
|
+
import { encodeNftId, isNFTActive, nftsFromOperations } from "../../nft";
|
|
23
23
|
import { NFT_VERSION } from "./versions";
|
|
24
|
-
import { getEnv } from "../../env";
|
|
25
24
|
|
|
26
25
|
export const getAccountShape: GetAccountShape = async (
|
|
27
26
|
infoInput,
|
|
@@ -41,24 +40,24 @@ export const getAccountShape: GetAccountShape = async (
|
|
|
41
40
|
const initialStableOperations = initialAccount
|
|
42
41
|
? stableOperations(initialAccount)
|
|
43
42
|
: [];
|
|
43
|
+
const shouldNFTBeActive = isNFTActive(currency);
|
|
44
44
|
// fetch transactions, incrementally if possible
|
|
45
45
|
const mostRecentStableOperation = initialStableOperations[0];
|
|
46
46
|
// when new tokens are added / blacklist changes, we need to sync again because we need to go through all operations again
|
|
47
47
|
const syncHash =
|
|
48
48
|
JSON.stringify(blacklistedTokenIds || []) +
|
|
49
49
|
"_" +
|
|
50
|
+
shouldNFTBeActive +
|
|
51
|
+
"_" +
|
|
50
52
|
listTokensForCryptoCurrency(currency, {
|
|
51
53
|
withDelisted: true,
|
|
52
54
|
}).length;
|
|
53
|
-
const
|
|
54
|
-
const firstNftSync =
|
|
55
|
-
getEnv("NFT") && typeof initialAccount?.nfts === "undefined";
|
|
55
|
+
const outdatedSyncHash = initialAccount?.syncHash !== syncHash;
|
|
56
56
|
const pullFromBlockHash =
|
|
57
57
|
initialAccount &&
|
|
58
58
|
areAllOperationsLoaded(initialAccount) &&
|
|
59
59
|
mostRecentStableOperation &&
|
|
60
|
-
!
|
|
61
|
-
!firstNftSync &&
|
|
60
|
+
!outdatedSyncHash &&
|
|
62
61
|
NFT_VERSION
|
|
63
62
|
? mostRecentStableOperation.blockHash
|
|
64
63
|
: undefined;
|
|
@@ -83,10 +82,8 @@ export const getAccountShape: GetAccountShape = async (
|
|
|
83
82
|
let newOps = flatMap(txs, txToOps({ address, id: accountId, currency }));
|
|
84
83
|
// extracting out the sub operations by token account
|
|
85
84
|
const perTokenAccountIdOperations = {};
|
|
86
|
-
// extracting and concat all nft operations for an account
|
|
87
|
-
const flatNftOps: Operation[] = [];
|
|
88
85
|
newOps.forEach((op) => {
|
|
89
|
-
const { subOperations
|
|
86
|
+
const { subOperations } = op;
|
|
90
87
|
|
|
91
88
|
if (subOperations?.length) {
|
|
92
89
|
subOperations.forEach((sop) => {
|
|
@@ -97,10 +94,6 @@ export const getAccountShape: GetAccountShape = async (
|
|
|
97
94
|
perTokenAccountIdOperations[sop.accountId].push(sop);
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
|
-
|
|
101
|
-
if (nftOperations?.length) {
|
|
102
|
-
nftOperations.forEach((nop) => flatNftOps.push(nop));
|
|
103
|
-
}
|
|
104
97
|
});
|
|
105
98
|
const subAccountsExisting = {};
|
|
106
99
|
initialAccount?.subAccounts?.forEach((a) => {
|
|
@@ -173,8 +166,8 @@ export const getAccountShape: GetAccountShape = async (
|
|
|
173
166
|
}));
|
|
174
167
|
const operations = mergeOps(initialStableOperations, newOps);
|
|
175
168
|
|
|
176
|
-
const nfts =
|
|
177
|
-
? mergeNfts(initialAccount?.nfts,
|
|
169
|
+
const nfts = isNFTActive(currency)
|
|
170
|
+
? mergeNfts(initialAccount?.nfts, nftsFromOperations(operations))
|
|
178
171
|
: undefined;
|
|
179
172
|
|
|
180
173
|
const accountShape: Partial<Account> = {
|
|
@@ -334,91 +327,23 @@ const txToOps =
|
|
|
334
327
|
});
|
|
335
328
|
|
|
336
329
|
// Creating NFTOps from transfer events related to ERC721 only
|
|
337
|
-
const erc721Operations =
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (!sending && !receiving) {
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const all: Operation[] = [];
|
|
353
|
-
|
|
354
|
-
if (sending) {
|
|
355
|
-
const type = "NFT_OUT";
|
|
356
|
-
all.push({
|
|
357
|
-
id: `${nftId}-${hash}-${type}`,
|
|
358
|
-
senders: [sender],
|
|
359
|
-
recipients: [receiver],
|
|
360
|
-
contract,
|
|
361
|
-
fee,
|
|
362
|
-
standard: "ERC721",
|
|
363
|
-
tokenId,
|
|
364
|
-
value: new BigNumber(1),
|
|
365
|
-
hash,
|
|
366
|
-
type,
|
|
367
|
-
blockHeight,
|
|
368
|
-
blockHash,
|
|
369
|
-
date,
|
|
370
|
-
transactionSequenceNumber,
|
|
371
|
-
accountId: id,
|
|
372
|
-
extra: {},
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (receiving) {
|
|
377
|
-
const type = "NFT_IN";
|
|
378
|
-
all.push({
|
|
379
|
-
id: `${nftId}-${hash}-${type}`,
|
|
380
|
-
senders: [sender],
|
|
381
|
-
recipients: [receiver],
|
|
382
|
-
contract,
|
|
383
|
-
fee,
|
|
384
|
-
standard: "ERC721",
|
|
385
|
-
tokenId,
|
|
386
|
-
value: new BigNumber(1),
|
|
387
|
-
hash,
|
|
388
|
-
type,
|
|
389
|
-
blockHeight,
|
|
390
|
-
blockHash,
|
|
391
|
-
date,
|
|
392
|
-
transactionSequenceNumber,
|
|
393
|
-
accountId: id,
|
|
394
|
-
extra: {},
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return all;
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// Creating NFTOps from transfer events related to ERC1155 only
|
|
402
|
-
const erc1155Operations = !erc1155_transfer_events
|
|
403
|
-
? []
|
|
404
|
-
: flatMap(erc1155_transfer_events, (event) => {
|
|
405
|
-
const sender = safeEncodeEIP55(event.sender);
|
|
406
|
-
const receiver = safeEncodeEIP55(event.receiver);
|
|
407
|
-
const contract = safeEncodeEIP55(event.contract);
|
|
408
|
-
const operator = safeEncodeEIP55(event.operator);
|
|
409
|
-
const sending = addr === sender;
|
|
410
|
-
const receiving = addr === receiver;
|
|
411
|
-
|
|
412
|
-
if (!sending && !receiving) {
|
|
413
|
-
return [];
|
|
414
|
-
}
|
|
330
|
+
const erc721Operations =
|
|
331
|
+
!erc721_transfer_events || !isNFTActive(currency)
|
|
332
|
+
? []
|
|
333
|
+
: flatMap(erc721_transfer_events, (event) => {
|
|
334
|
+
const sender = safeEncodeEIP55(event.sender);
|
|
335
|
+
const receiver = safeEncodeEIP55(event.receiver);
|
|
336
|
+
const contract = safeEncodeEIP55(event.contract);
|
|
337
|
+
const tokenId = event.token_id;
|
|
338
|
+
const nftId = encodeNftId(id, event.contract, tokenId);
|
|
339
|
+
const sending = addr === sender;
|
|
340
|
+
const receiving = addr === receiver;
|
|
415
341
|
|
|
416
|
-
|
|
342
|
+
if (!sending && !receiving) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
417
345
|
|
|
418
|
-
|
|
419
|
-
const tokenId = transfer.id;
|
|
420
|
-
const value = new BigNumber(transfer.value);
|
|
421
|
-
const nftId = encodeNftId(id, event.contract, tokenId);
|
|
346
|
+
const all: Operation[] = [];
|
|
422
347
|
|
|
423
348
|
if (sending) {
|
|
424
349
|
const type = "NFT_OUT";
|
|
@@ -428,10 +353,9 @@ const txToOps =
|
|
|
428
353
|
recipients: [receiver],
|
|
429
354
|
contract,
|
|
430
355
|
fee,
|
|
431
|
-
|
|
432
|
-
standard: "ERC1155",
|
|
356
|
+
standard: "ERC721",
|
|
433
357
|
tokenId,
|
|
434
|
-
value,
|
|
358
|
+
value: new BigNumber(1),
|
|
435
359
|
hash,
|
|
436
360
|
type,
|
|
437
361
|
blockHeight,
|
|
@@ -451,10 +375,9 @@ const txToOps =
|
|
|
451
375
|
recipients: [receiver],
|
|
452
376
|
contract,
|
|
453
377
|
fee,
|
|
454
|
-
|
|
455
|
-
standard: "ERC1155",
|
|
378
|
+
standard: "ERC721",
|
|
456
379
|
tokenId,
|
|
457
|
-
value,
|
|
380
|
+
value: new BigNumber(1),
|
|
458
381
|
hash,
|
|
459
382
|
type,
|
|
460
383
|
blockHeight,
|
|
@@ -465,15 +388,88 @@ const txToOps =
|
|
|
465
388
|
extra: {},
|
|
466
389
|
});
|
|
467
390
|
}
|
|
391
|
+
|
|
392
|
+
return all;
|
|
468
393
|
});
|
|
469
394
|
|
|
470
|
-
|
|
471
|
-
|
|
395
|
+
// Creating NFTOps from transfer events related to ERC1155 only
|
|
396
|
+
const erc1155Operations =
|
|
397
|
+
!erc1155_transfer_events || !isNFTActive(currency)
|
|
398
|
+
? []
|
|
399
|
+
: flatMap(erc1155_transfer_events, (event) => {
|
|
400
|
+
const sender = safeEncodeEIP55(event.sender);
|
|
401
|
+
const receiver = safeEncodeEIP55(event.receiver);
|
|
402
|
+
const contract = safeEncodeEIP55(event.contract);
|
|
403
|
+
const operator = safeEncodeEIP55(event.operator);
|
|
404
|
+
const sending = addr === sender;
|
|
405
|
+
const receiving = addr === receiver;
|
|
406
|
+
|
|
407
|
+
if (!sending && !receiving) {
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const all: Operation[] = [];
|
|
412
|
+
|
|
413
|
+
event.transfers.forEach((transfer) => {
|
|
414
|
+
const tokenId = transfer.id;
|
|
415
|
+
const value = new BigNumber(transfer.value);
|
|
416
|
+
const nftId = encodeNftId(id, event.contract, tokenId);
|
|
417
|
+
|
|
418
|
+
if (sending) {
|
|
419
|
+
const type = "NFT_OUT";
|
|
420
|
+
all.push({
|
|
421
|
+
id: `${nftId}-${hash}-${type}`,
|
|
422
|
+
senders: [sender],
|
|
423
|
+
recipients: [receiver],
|
|
424
|
+
contract,
|
|
425
|
+
fee,
|
|
426
|
+
operator,
|
|
427
|
+
standard: "ERC1155",
|
|
428
|
+
tokenId,
|
|
429
|
+
value,
|
|
430
|
+
hash,
|
|
431
|
+
type,
|
|
432
|
+
blockHeight,
|
|
433
|
+
blockHash,
|
|
434
|
+
date,
|
|
435
|
+
transactionSequenceNumber,
|
|
436
|
+
accountId: id,
|
|
437
|
+
extra: {},
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (receiving) {
|
|
442
|
+
const type = "NFT_IN";
|
|
443
|
+
all.push({
|
|
444
|
+
id: `${nftId}-${hash}-${type}`,
|
|
445
|
+
senders: [sender],
|
|
446
|
+
recipients: [receiver],
|
|
447
|
+
contract,
|
|
448
|
+
fee,
|
|
449
|
+
operator,
|
|
450
|
+
standard: "ERC1155",
|
|
451
|
+
tokenId,
|
|
452
|
+
value,
|
|
453
|
+
hash,
|
|
454
|
+
type,
|
|
455
|
+
blockHeight,
|
|
456
|
+
blockHash,
|
|
457
|
+
date,
|
|
458
|
+
transactionSequenceNumber,
|
|
459
|
+
accountId: id,
|
|
460
|
+
extra: {},
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
return all;
|
|
466
|
+
});
|
|
472
467
|
|
|
473
468
|
const nftOperations = erc721Operations
|
|
474
469
|
.concat(erc1155Operations)
|
|
475
470
|
/** @warning is this necessary ? Do we need the operations to be chronologically organised for LLD/LLM ? */
|
|
476
471
|
.sort((a, b) => b.date.getTime() - a.date.getTime());
|
|
472
|
+
|
|
477
473
|
const ops: Operation[] = [];
|
|
478
474
|
|
|
479
475
|
if (sending) {
|
|
@@ -619,11 +615,6 @@ async function loadERC20Balances(tokenAccounts, address, api) {
|
|
|
619
615
|
.filter(Boolean);
|
|
620
616
|
}
|
|
621
617
|
|
|
622
|
-
function getNfts(nftOperations: Operation[]): NFT[] {
|
|
623
|
-
const nfts: NFT[] = nftsFromOperations(nftOperations);
|
|
624
|
-
return nfts.filter((nft) => nft.amount.gt(0));
|
|
625
|
-
}
|
|
626
|
-
|
|
627
618
|
const SAFE_REORG_THRESHOLD = 80;
|
|
628
619
|
|
|
629
620
|
function stableOperations(a) {
|
|
@@ -90,12 +90,14 @@ export const formatTransaction = (
|
|
|
90
90
|
const header = (() => {
|
|
91
91
|
switch (t.mode) {
|
|
92
92
|
case "erc721.transfer":
|
|
93
|
-
return `${t.mode.toUpperCase()} Collection: ${t.collection}
|
|
94
|
-
t.
|
|
95
|
-
}`;
|
|
93
|
+
return `${t.mode.toUpperCase()} Collection: ${t.collection} (${
|
|
94
|
+
t.collectionName || ""
|
|
95
|
+
}) TokenId: ${t.tokenIds?.[0]}`;
|
|
96
96
|
case "erc1155.transfer":
|
|
97
97
|
return (
|
|
98
|
-
`${t.mode.toUpperCase()} Collection: ${t.collection}
|
|
98
|
+
`${t.mode.toUpperCase()} Collection: ${t.collection} (${
|
|
99
|
+
t.collectionName || ""
|
|
100
|
+
})` +
|
|
99
101
|
t.tokenIds
|
|
100
102
|
?.map((tokenId, index) => {
|
|
101
103
|
return `\n - TokenId: ${tokenId} Quantity: ${
|
|
@@ -153,6 +155,7 @@ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
|
153
155
|
feesStrategy: tr.feesStrategy,
|
|
154
156
|
tokenIds: tr.tokenIds,
|
|
155
157
|
collection: tr.collection,
|
|
158
|
+
collectionName: tr.collectionName,
|
|
156
159
|
quantities: tr.quantities?.map((q) => new BigNumber(q)),
|
|
157
160
|
};
|
|
158
161
|
};
|
|
@@ -180,6 +183,7 @@ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
|
180
183
|
feesStrategy: t.feesStrategy,
|
|
181
184
|
tokenIds: t.tokenIds,
|
|
182
185
|
collection: t.collection,
|
|
186
|
+
collectionName: t.collectionName,
|
|
183
187
|
quantities: t.quantities?.map((q) => q.toString()),
|
|
184
188
|
};
|
|
185
189
|
};
|
|
@@ -38,6 +38,7 @@ export type Transaction = TransactionCommon & {
|
|
|
38
38
|
networkInfo: NetworkInfo | null | undefined;
|
|
39
39
|
allowZeroAmount?: boolean;
|
|
40
40
|
collection?: string;
|
|
41
|
+
collectionName?: string;
|
|
41
42
|
tokenIds?: string[];
|
|
42
43
|
quantities?: BigNumber[];
|
|
43
44
|
};
|
|
@@ -54,6 +55,7 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
54
55
|
allowZeroAmount?: boolean;
|
|
55
56
|
tokenIds?: string[];
|
|
56
57
|
collection?: string;
|
|
58
|
+
collectionName?: string;
|
|
57
59
|
quantities?: string[];
|
|
58
60
|
};
|
|
59
61
|
export type TypedMessage = {
|
package/src/nft/helpers.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import eip55 from "eip55";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import { NFT, Operation
|
|
3
|
+
import { NFT, Operation } from "../types";
|
|
4
|
+
import { encodeNftId } from ".";
|
|
4
5
|
|
|
5
6
|
type Collection = NFT["collection"];
|
|
6
7
|
|
|
@@ -15,23 +16,22 @@ export const nftsFromOperations = (ops: Operation[]): NFT[] => {
|
|
|
15
16
|
// if ops are Operations get the prop nftOperations, else ops are considered nftOperations already
|
|
16
17
|
.flatMap((op) => (op?.nftOperations?.length ? op.nftOperations : op))
|
|
17
18
|
.reduce((acc: Record<string, NFT>, nftOp: Operation) => {
|
|
18
|
-
|
|
19
|
+
let { contract } = nftOp;
|
|
20
|
+
if (!contract) {
|
|
19
21
|
return acc;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
// Creating a "token for a contract" unique key
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
25
|
+
contract = eip55.encode(contract);
|
|
26
|
+
const { tokenId, standard, accountId } = nftOp;
|
|
27
|
+
if (!tokenId || !standard) return acc;
|
|
28
|
+
const id = encodeNftId(accountId, contract, tokenId || "");
|
|
26
29
|
|
|
27
|
-
const nft = (acc[
|
|
30
|
+
const nft = (acc[id] || {
|
|
28
31
|
id,
|
|
29
|
-
tokenId
|
|
32
|
+
tokenId,
|
|
30
33
|
amount: new BigNumber(0),
|
|
31
|
-
collection: {
|
|
32
|
-
contract,
|
|
33
|
-
standard: standard!,
|
|
34
|
-
},
|
|
34
|
+
collection: { contract, standard },
|
|
35
35
|
}) as NFT;
|
|
36
36
|
|
|
37
37
|
if (nftOp.type === "NFT_IN") {
|
|
@@ -40,12 +40,12 @@ export const nftsFromOperations = (ops: Operation[]): NFT[] => {
|
|
|
40
40
|
nft.amount = nft.amount.minus(nftOp.value);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
acc[
|
|
43
|
+
acc[id] = nft;
|
|
44
44
|
|
|
45
45
|
return acc;
|
|
46
46
|
}, {});
|
|
47
47
|
|
|
48
|
-
return Object.values(nftsMap);
|
|
48
|
+
return Object.values(nftsMap).filter((n) => n.amount.gt(0));
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export const nftsByCollections = (
|
|
@@ -76,11 +76,3 @@ export const nftsByCollections = (
|
|
|
76
76
|
export const getNftKey = (contract: string, tokenId: string): string => {
|
|
77
77
|
return `${contract}-${tokenId}`;
|
|
78
78
|
};
|
|
79
|
-
|
|
80
|
-
export const isNftTransaction = (transaction: Transaction): boolean => {
|
|
81
|
-
if (transaction.family === "ethereum") {
|
|
82
|
-
return ["erc721.transfer", "erc1155.transfer"].includes(transaction.mode);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
};
|
package/src/nft/index.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transaction, CryptoCurrency } from "../types";
|
|
2
|
+
import { getEnv } from "../env";
|
|
3
|
+
|
|
4
|
+
export const isNftTransaction = (transaction: Transaction): boolean => {
|
|
5
|
+
if (transaction.family === "ethereum") {
|
|
6
|
+
return ["erc721.transfer", "erc1155.transfer"].includes(transaction.mode);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function isNFTActive(currency: CryptoCurrency): boolean {
|
|
13
|
+
return (
|
|
14
|
+
getEnv("NFT") && getEnv("NFT_CURRENCIES").split(",").includes(currency.id)
|
|
15
|
+
);
|
|
16
|
+
}
|
package/src/reconciliation.ts
CHANGED
|
@@ -384,7 +384,10 @@ export function patchAccount(
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
const nfts = updatedRaw?.nfts?.map(fromNFTRaw);
|
|
387
|
-
if (updatedRaw.nfts &&
|
|
387
|
+
if (!updatedRaw.nfts && account.nfts) {
|
|
388
|
+
delete next.nfts;
|
|
389
|
+
changed = true;
|
|
390
|
+
} else if (!isEqual(account.nfts, nfts)) {
|
|
388
391
|
next.nfts = nfts;
|
|
389
392
|
changed = true;
|
|
390
393
|
}
|