@ledgerhq/live-common 21.13.2 → 21.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/lib/__tests__/derivation.js +1 -1
  2. package/lib/__tests__/derivation.js.map +1 -1
  3. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +2 -2
  4. package/lib/account/groupOperations.js +1 -1
  5. package/lib/account/groupOperations.js.map +1 -1
  6. package/lib/account/pending.d.ts +1 -0
  7. package/lib/account/pending.d.ts.map +1 -1
  8. package/lib/account/serialization.d.ts +6 -4
  9. package/lib/account/serialization.d.ts.map +1 -1
  10. package/lib/account/serialization.js +47 -9
  11. package/lib/account/serialization.js.map +1 -1
  12. package/lib/api/Ethereum.d.ts +22 -1
  13. package/lib/api/Ethereum.d.ts.map +1 -1
  14. package/lib/api/Ethereum.js +21 -1
  15. package/lib/api/Ethereum.js.map +1 -1
  16. package/lib/apps/polyfill.d.ts.map +1 -1
  17. package/lib/apps/polyfill.js +1 -0
  18. package/lib/apps/polyfill.js.map +1 -1
  19. package/lib/bridge/jsHelpers.d.ts +2 -1
  20. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  21. package/lib/bridge/jsHelpers.js +27 -1
  22. package/lib/bridge/jsHelpers.js.map +1 -1
  23. package/lib/csvExport.d.ts.map +1 -1
  24. package/lib/csvExport.js +3 -1
  25. package/lib/csvExport.js.map +1 -1
  26. package/lib/currencies/sortByMarketcap.d.ts.map +1 -1
  27. package/lib/currencies/sortByMarketcap.js +8 -1
  28. package/lib/currencies/sortByMarketcap.js.map +1 -1
  29. package/lib/derivation.js +1 -1
  30. package/lib/derivation.js.map +1 -1
  31. package/lib/env.d.ts +15 -5
  32. package/lib/env.d.ts.map +1 -1
  33. package/lib/env.js +12 -1
  34. package/lib/env.js.map +1 -1
  35. package/lib/env.react.d.ts +1 -1
  36. package/lib/env.react.d.ts.map +1 -1
  37. package/lib/families/bitcoin/cache.d.ts +1 -0
  38. package/lib/families/bitcoin/cache.d.ts.map +1 -1
  39. package/lib/families/bitcoin/cache.js +7 -1
  40. package/lib/families/bitcoin/cache.js.map +1 -1
  41. package/lib/families/bitcoin/errors.d.ts +4 -0
  42. package/lib/families/bitcoin/errors.d.ts.map +1 -0
  43. package/lib/families/bitcoin/errors.js +6 -0
  44. package/lib/families/bitcoin/errors.js.map +1 -0
  45. package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +1 -1
  46. package/lib/families/bitcoin/js-getTransactionStatus.js +24 -11
  47. package/lib/families/bitcoin/js-getTransactionStatus.js.map +1 -1
  48. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  49. package/lib/families/bitcoin/js-synchronisation.js +8 -19
  50. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  51. package/lib/families/bitcoin/logic.d.ts +1 -1
  52. package/lib/families/bitcoin/logic.d.ts.map +1 -1
  53. package/lib/families/bitcoin/logic.js +6 -0
  54. package/lib/families/bitcoin/logic.js.map +1 -1
  55. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  56. package/lib/families/bitcoin/specs.js +2 -1
  57. package/lib/families/bitcoin/specs.js.map +1 -1
  58. package/lib/families/bitcoin/test-dataset.js +2 -2
  59. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  60. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +4 -0
  61. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  62. package/lib/families/bitcoin/wallet-btc/crypto/base.js +36 -5
  63. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  64. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts +1 -0
  65. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
  66. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +19 -1
  67. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
  68. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts +1 -0
  69. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  70. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +4 -0
  71. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  72. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +1 -0
  73. package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
  74. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +1 -0
  75. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  76. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +4 -0
  77. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  78. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +1 -0
  79. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  80. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +4 -0
  81. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  82. package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts.map +1 -1
  83. package/lib/families/bitcoin/wallet-btc/explorer/index.js +0 -3
  84. package/lib/families/bitcoin/wallet-btc/explorer/index.js.map +1 -1
  85. package/lib/families/bitcoin/wallet-btc/index.d.ts +2 -2
  86. package/lib/families/bitcoin/wallet-btc/index.d.ts.map +1 -1
  87. package/lib/families/bitcoin/wallet-btc/index.js +4 -5
  88. package/lib/families/bitcoin/wallet-btc/index.js.map +1 -1
  89. package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +3 -3
  90. package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +5 -5
  91. package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +5 -5
  92. package/lib/families/bitcoin/wallet-btc/utils.d.ts +3 -1
  93. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  94. package/lib/families/bitcoin/wallet-btc/utils.js +30 -10
  95. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  96. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  97. package/lib/families/bitcoin/wallet-btc/wallet.js +5 -3
  98. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  99. package/lib/families/bitcoin/wallet-btc/xpub.d.ts +2 -6
  100. package/lib/families/bitcoin/wallet-btc/xpub.d.ts.map +1 -1
  101. package/lib/families/bitcoin/wallet-btc/xpub.js +62 -52
  102. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  103. package/lib/families/elrond/js-getTransactionStatus.d.ts.map +1 -1
  104. package/lib/families/elrond/js-getTransactionStatus.js +3 -0
  105. package/lib/families/elrond/js-getTransactionStatus.js.map +1 -1
  106. package/lib/families/elrond/js-signOperation.d.ts.map +1 -1
  107. package/lib/families/elrond/js-signOperation.js +3 -1
  108. package/lib/families/elrond/js-signOperation.js.map +1 -1
  109. package/lib/families/ethereum/signOperation.d.ts.map +1 -1
  110. package/lib/families/ethereum/signOperation.js +7 -0
  111. package/lib/families/ethereum/signOperation.js.map +1 -1
  112. package/lib/families/ethereum/specs.d.ts +1 -0
  113. package/lib/families/ethereum/specs.d.ts.map +1 -1
  114. package/lib/families/ethereum/specs.js +41 -0
  115. package/lib/families/ethereum/specs.js.map +1 -1
  116. package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
  117. package/lib/families/ethereum/synchronisation.js +175 -15
  118. package/lib/families/ethereum/synchronisation.js.map +1 -1
  119. package/lib/families/ethereum/versions.d.ts +2 -0
  120. package/lib/families/ethereum/versions.d.ts.map +1 -0
  121. package/lib/families/ethereum/versions.js +5 -0
  122. package/lib/families/ethereum/versions.js.map +1 -0
  123. package/lib/generated/specs.d.ts +1 -0
  124. package/lib/generated/specs.d.ts.map +1 -1
  125. package/lib/nft/NftMetadataProvider/index.d.ts +10 -0
  126. package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -0
  127. package/lib/nft/NftMetadataProvider/index.js +244 -0
  128. package/lib/nft/NftMetadataProvider/index.js.map +1 -0
  129. package/lib/nft/NftMetadataProvider/logic.d.ts +3 -0
  130. package/lib/nft/NftMetadataProvider/logic.d.ts.map +1 -0
  131. package/lib/nft/NftMetadataProvider/logic.js +22 -0
  132. package/lib/nft/NftMetadataProvider/logic.js.map +1 -0
  133. package/lib/nft/NftMetadataProvider/types.d.ts +44 -0
  134. package/lib/nft/NftMetadataProvider/types.d.ts.map +1 -0
  135. package/lib/nft/NftMetadataProvider/types.js +3 -0
  136. package/lib/nft/NftMetadataProvider/types.js.map +1 -0
  137. package/lib/nft/helpers.d.ts +10 -0
  138. package/lib/nft/helpers.d.ts.map +1 -0
  139. package/lib/nft/helpers.js +85 -0
  140. package/lib/nft/helpers.js.map +1 -0
  141. package/lib/nft/index.d.ts +4 -0
  142. package/lib/nft/index.d.ts.map +1 -0
  143. package/lib/nft/index.js +16 -0
  144. package/lib/nft/index.js.map +1 -0
  145. package/lib/nft/nftId.d.ts +3 -0
  146. package/lib/nft/nftId.d.ts.map +1 -0
  147. package/lib/nft/nftId.js +33 -0
  148. package/lib/nft/nftId.js.map +1 -0
  149. package/lib/operation.d.ts +1 -1
  150. package/lib/operation.d.ts.map +1 -1
  151. package/lib/operation.js +19 -5
  152. package/lib/operation.js.map +1 -1
  153. package/lib/reconciliation.d.ts.map +1 -1
  154. package/lib/reconciliation.js +6 -0
  155. package/lib/reconciliation.js.map +1 -1
  156. package/lib/types/account.d.ts +3 -0
  157. package/lib/types/account.d.ts.map +1 -1
  158. package/lib/types/index.d.ts +1 -0
  159. package/lib/types/index.d.ts.map +1 -1
  160. package/lib/types/index.js +1 -0
  161. package/lib/types/index.js.map +1 -1
  162. package/lib/types/nft.d.ts +29 -0
  163. package/lib/types/nft.d.ts.map +1 -0
  164. package/lib/types/nft.js +3 -0
  165. package/lib/types/nft.js.map +1 -0
  166. package/lib/types/operation.d.ts +12 -1
  167. package/lib/types/operation.d.ts.map +1 -1
  168. package/package.json +13 -13
  169. package/src/__tests__/__snapshots__/all.libcore.ts.snap +64428 -57815
  170. package/src/__tests__/derivation.ts +1 -1
  171. package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
  172. package/src/account/groupOperations.ts +2 -2
  173. package/src/account/serialization.ts +52 -0
  174. package/src/api/Ethereum.ts +40 -2
  175. package/src/apps/polyfill.ts +1 -0
  176. package/src/bridge/jsHelpers.ts +35 -0
  177. package/src/csvExport.ts +3 -2
  178. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +1361 -1
  179. package/src/currencies/sortByMarketcap.ts +9 -1
  180. package/src/derivation.ts +1 -1
  181. package/src/env.ts +12 -1
  182. package/src/families/bitcoin/cache.ts +12 -0
  183. package/src/families/bitcoin/errors.ts +5 -0
  184. package/src/families/bitcoin/js-getTransactionStatus.ts +15 -1
  185. package/src/families/bitcoin/js-synchronisation.ts +11 -25
  186. package/src/families/bitcoin/logic.ts +7 -2
  187. package/src/families/bitcoin/specs.ts +6 -1
  188. package/src/families/bitcoin/test-dataset.ts +2 -2
  189. package/src/families/bitcoin/wallet-btc/crypto/base.ts +40 -5
  190. package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +21 -1
  191. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +5 -0
  192. package/src/families/bitcoin/wallet-btc/crypto/types.ts +1 -0
  193. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +5 -0
  194. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +5 -0
  195. package/src/families/bitcoin/wallet-btc/explorer/index.ts +0 -5
  196. package/src/families/bitcoin/wallet-btc/index.ts +4 -4
  197. package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +3 -3
  198. package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +5 -5
  199. package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +5 -5
  200. package/src/families/bitcoin/wallet-btc/utils.ts +34 -9
  201. package/src/families/bitcoin/wallet-btc/wallet.ts +4 -2
  202. package/src/families/bitcoin/wallet-btc/xpub.ts +37 -53
  203. package/src/families/elrond/js-getTransactionStatus.ts +4 -0
  204. package/src/families/elrond/js-signOperation.ts +3 -1
  205. package/src/families/ethereum/modules/__snapshots__/compound.resilience.test.ts.snap +2876 -0
  206. package/src/families/ethereum/signOperation.ts +8 -0
  207. package/src/families/ethereum/specs.ts +47 -0
  208. package/src/families/ethereum/synchronisation.ts +185 -6
  209. package/src/families/ethereum/versions.ts +1 -0
  210. package/src/nft/NftMetadataProvider/index.tsx +205 -0
  211. package/src/nft/NftMetadataProvider/logic.ts +20 -0
  212. package/src/nft/NftMetadataProvider/types.ts +60 -0
  213. package/src/nft/helpers.ts +78 -0
  214. package/src/nft/index.ts +3 -0
  215. package/src/nft/nftId.ts +17 -0
  216. package/src/operation.ts +22 -3
  217. package/src/reconciliation.ts +7 -0
  218. package/src/types/account.ts +4 -0
  219. package/src/types/index.ts +1 -0
  220. package/src/types/nft.ts +38 -0
  221. package/src/types/operation.ts +23 -1
@@ -6,7 +6,7 @@ import {
6
6
  describe("derivation", () => {
7
7
  test("getPreferredNewAccountScheme should return a list of schemes for a given currency", () => {
8
8
  const testData = [
9
- ["bitcoin", ["native_segwit", "segwit", ""]],
9
+ ["bitcoin", ["native_segwit", "taproot", "segwit", ""]],
10
10
  ["ethereum", null],
11
11
  ["cosmos", null],
12
12
  ["litecoin", ["native_segwit", "segwit", ""]],
@@ -63,7 +63,7 @@ describe("testing wallet", () => {
63
63
  fromAccount: account,
64
64
  txInfo,
65
65
  });
66
- expect(tx).toEqual("66ad13fd62ca677ae4d169ec5fe84be2f846562a");
66
+ expect(tx).toEqual("d6154bba4915d07453bb09d4fa02d62e975b4475");
67
67
  });
68
68
 
69
69
  it("should allow to build a transaction splitting outputs", async () => {
@@ -87,7 +87,7 @@ describe("testing wallet", () => {
87
87
  fromAccount: account,
88
88
  txInfo,
89
89
  });
90
- expect(tx).toEqual("23ab414d38fe836e22619d6ee84fdebafa6b5168");
90
+ expect(tx).toEqual("d922a70d6a66b96cdaba4565270a21f97eb23a6d");
91
91
  });
92
92
 
93
93
  it("should throw during sync if there is an error in explorer", async () => {
@@ -1,6 +1,6 @@
1
1
  import type { AccountLikeArray, AccountLike, Operation } from "../types";
2
2
  import { flattenAccounts } from "./helpers";
3
- import { flattenOperationWithInternals } from "../operation";
3
+ import { flattenOperationWithInternalsAndNfts } from "../operation";
4
4
  export type DailyOperationsSection = {
5
5
  day: Date;
6
6
  data: Operation[];
@@ -105,7 +105,7 @@ export function groupAccountsOperationsByDay(
105
105
  indexes[bestOpInfo.accountI]++;
106
106
  }
107
107
 
108
- const ops = flattenOperationWithInternals(bestOp);
108
+ const ops = flattenOperationWithInternalsAndNfts(bestOp);
109
109
  return {
110
110
  ops,
111
111
  date: bestOp.date,
@@ -16,6 +16,8 @@ import type {
16
16
  OperationRaw,
17
17
  SubAccount,
18
18
  SubAccountRaw,
19
+ NFT,
20
+ NFTRaw,
19
21
  } from "../types";
20
22
  import type { TronResources, TronResourcesRaw } from "../families/tron/types";
21
23
  import {
@@ -101,6 +103,7 @@ export const toOperationRaw = (
101
103
  fee,
102
104
  subOperations,
103
105
  internalOperations,
106
+ nftOperations,
104
107
  extra,
105
108
  id,
106
109
  hash,
@@ -112,6 +115,10 @@ export const toOperationRaw = (
112
115
  transactionSequenceNumber,
113
116
  accountId,
114
117
  hasFailed,
118
+ contract,
119
+ operator,
120
+ standard,
121
+ tokenId,
115
122
  }: Operation,
116
123
  preserveSubOperation?: boolean
117
124
  ): OperationRaw => {
@@ -142,6 +149,10 @@ export const toOperationRaw = (
142
149
  date: date.toISOString(),
143
150
  value: value.toFixed(),
144
151
  fee: fee.toString(),
152
+ contract,
153
+ operator,
154
+ standard,
155
+ tokenId,
145
156
  };
146
157
 
147
158
  if (transactionSequenceNumber !== undefined) {
@@ -160,6 +171,10 @@ export const toOperationRaw = (
160
171
  copy.internalOperations = internalOperations.map((o) => toOperationRaw(o));
161
172
  }
162
173
 
174
+ if (nftOperations) {
175
+ copy.nftOperations = nftOperations.map((o) => toOperationRaw(o));
176
+ }
177
+
163
178
  return copy;
164
179
  };
165
180
  export const inferSubOperations = (
@@ -198,6 +213,7 @@ export const fromOperationRaw = (
198
213
  extra,
199
214
  subOperations,
200
215
  internalOperations,
216
+ nftOperations,
201
217
  id,
202
218
  hash,
203
219
  type,
@@ -207,6 +223,10 @@ export const fromOperationRaw = (
207
223
  blockHash,
208
224
  transactionSequenceNumber,
209
225
  hasFailed,
226
+ contract,
227
+ operator,
228
+ standard,
229
+ tokenId,
210
230
  }: OperationRaw,
211
231
  accountId: string,
212
232
  subAccounts?: SubAccount[] | null | undefined
@@ -238,6 +258,10 @@ export const fromOperationRaw = (
238
258
  value: new BigNumber(value),
239
259
  fee: new BigNumber(fee),
240
260
  extra: e || {},
261
+ contract,
262
+ operator,
263
+ standard,
264
+ tokenId,
241
265
  };
242
266
 
243
267
  if (transactionSequenceNumber !== undefined) {
@@ -262,6 +286,12 @@ export const fromOperationRaw = (
262
286
  );
263
287
  }
264
288
 
289
+ if (nftOperations) {
290
+ res.nftOperations = nftOperations.map((o) =>
291
+ fromOperationRaw(o, o.accountId)
292
+ );
293
+ }
294
+
265
295
  return res;
266
296
  };
267
297
  export const toTronResourcesRaw = ({
@@ -677,6 +707,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
677
707
  polkadotResources,
678
708
  elrondResources,
679
709
  cryptoOrgResources,
710
+ nfts,
680
711
  } = rawAccount;
681
712
  const subAccounts =
682
713
  subAccountsRaw &&
@@ -734,6 +765,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
734
765
  swapHistory: [],
735
766
  syncHash,
736
767
  balanceHistoryCache: balanceHistoryCache || emptyHistoryCache,
768
+ nfts: nfts?.map((n) => fromNFTRaw(n)),
737
769
  };
738
770
  res.balanceHistoryCache = generateHistoryFromOperations(res);
739
771
 
@@ -834,6 +866,7 @@ export function toAccountRaw({
834
866
  polkadotResources,
835
867
  elrondResources,
836
868
  cryptoOrgResources,
869
+ nfts,
837
870
  }: Account): AccountRaw {
838
871
  const res: AccountRaw = {
839
872
  id,
@@ -857,6 +890,7 @@ export function toAccountRaw({
857
890
  lastSyncDate: lastSyncDate.toISOString(),
858
891
  balance: balance.toFixed(),
859
892
  spendableBalance: spendableBalance.toFixed(),
893
+ nfts: nfts?.map((n) => toNFTRaw(n)),
860
894
  };
861
895
 
862
896
  if (balanceHistory) {
@@ -914,3 +948,21 @@ export function toAccountRaw({
914
948
  }
915
949
  return res;
916
950
  }
951
+
952
+ export function toNFTRaw({ id, tokenId, amount, collection }: NFT): NFTRaw {
953
+ return {
954
+ id,
955
+ tokenId,
956
+ amount: amount.toFixed(),
957
+ collection,
958
+ };
959
+ }
960
+
961
+ export function fromNFTRaw({ id, tokenId, amount, collection }: NFTRaw): NFT {
962
+ return {
963
+ id,
964
+ tokenId,
965
+ amount: new BigNumber(amount),
966
+ collection,
967
+ };
968
+ }
@@ -3,12 +3,14 @@ import invariant from "invariant";
3
3
  import { BigNumber } from "bignumber.js";
4
4
  import { LedgerAPINotAvailable } from "@ledgerhq/errors";
5
5
  import JSONBigNumber from "@ledgerhq/json-bignumber";
6
- import type { CryptoCurrency } from "../types";
6
+ import type { CryptoCurrency, NFTMetadataResponse } from "../types";
7
7
  import type { EthereumGasLimitRequest } from "../families/ethereum/types";
8
8
  import network from "../network";
9
9
  import { blockchainBaseURL } from "./Ledger";
10
10
  import { FeeEstimationFailed } from "../errors";
11
11
  import { makeLRUCache } from "../cache";
12
+ import { getEnv } from "../env";
13
+
12
14
  export type Block = {
13
15
  height: BigNumber;
14
16
  }; // TODO more fields actually
@@ -37,6 +39,22 @@ export type Tx = {
37
39
  }>;
38
40
  truncated: boolean;
39
41
  };
42
+ erc721_transfer_events?: Array<{
43
+ contract: string;
44
+ sender: string;
45
+ receiver: string;
46
+ token_id: string;
47
+ }>;
48
+ erc1155_transfer_events?: Array<{
49
+ contract: string;
50
+ sender: string;
51
+ operator: string;
52
+ receiver: string;
53
+ transfers: Array<{
54
+ id: string;
55
+ value: string;
56
+ }>;
57
+ }>;
40
58
  actions?: Array<{
41
59
  from: string;
42
60
  to: string;
@@ -59,6 +77,12 @@ export type ERC20BalanceOutput = Array<{
59
77
  contract: string;
60
78
  balance: BigNumber;
61
79
  }>;
80
+ export type NFTMetadataInput = Readonly<
81
+ Array<{
82
+ contract: string;
83
+ tokenId: string;
84
+ }>
85
+ >;
62
86
  export type API = {
63
87
  getTransactions: (
64
88
  address: string,
@@ -72,6 +96,7 @@ export type API = {
72
96
  getAccountNonce: (address: string) => Promise<number>;
73
97
  broadcastTransaction: (signedTransaction: string) => Promise<string>;
74
98
  getERC20Balances: (input: ERC20BalancesInput) => Promise<ERC20BalanceOutput>;
99
+ getNFTMetadata: (input: NFTMetadataInput) => Promise<NFTMetadataResponse[]>;
75
100
  getAccountBalance: (address: string) => Promise<BigNumber>;
76
101
  roughlyEstimateGasLimit: (address: string) => Promise<BigNumber>;
77
102
  getERC20ApprovalsPerContract: (
@@ -107,7 +132,10 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
107
132
  let { data } = await network({
108
133
  method: "GET",
109
134
  url: URL.format({
110
- pathname: `${baseURL}/addresses/${address}/transactions`,
135
+ pathname:
136
+ getEnv("NFT") && currency.ticker === "ETH"
137
+ ? `https://explorers.api-01.live.ledger-stg.com/blockchain/v3/eth/addresses/${address}/transactions`
138
+ : `${baseURL}/addresses/${address}/transactions`,
111
139
  query: {
112
140
  batch_size,
113
141
  noinput: true,
@@ -178,6 +206,16 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
178
206
  return data;
179
207
  },
180
208
 
209
+ async getNFTMetadata(input) {
210
+ const { data }: { data: NFTMetadataResponse[] } = await network({
211
+ method: "POST",
212
+ url: getEnv("NFT_ETH_METADATA_SERVICE"),
213
+ data: input,
214
+ });
215
+
216
+ return data;
217
+ },
218
+
181
219
  async getERC20ApprovalsPerContract(owner, contract) {
182
220
  try {
183
221
  const { data } = await network({
@@ -48,6 +48,7 @@ export const whitelistDependencies = ["Decred", "Decred Testnet"];
48
48
  ["Compound", "Ethereum"],
49
49
  ["Opensea", "Ethereum"],
50
50
  ["StakeDAO", "Ethereum"],
51
+ ["Yearn", "Ethereum"],
51
52
  ].forEach(([name, dep]) => declareDep(name, dep));
52
53
  export const getDependencies = (appName: string): string[] =>
53
54
  directDep[appName] || [];
@@ -1,4 +1,5 @@
1
1
  import isEqual from "lodash/isEqual";
2
+ import setWith from "lodash/setWith";
2
3
  import { BigNumber } from "bignumber.js";
3
4
  import { Observable, from } from "rxjs";
4
5
  import { log } from "@ledgerhq/logs";
@@ -34,6 +35,7 @@ import type {
34
35
  SyncConfig,
35
36
  CryptoCurrency,
36
37
  DerivationMode,
38
+ NFT,
37
39
  } from "../types";
38
40
  import type { CurrencyBridge, AccountBridge } from "../types/bridge";
39
41
  import getAddress from "../hw/getAddress";
@@ -116,6 +118,39 @@ Operation[] {
116
118
  return all;
117
119
  }
118
120
 
121
+ export const mergeNfts = (
122
+ oldNfts: NFT[] | undefined,
123
+ newNfts: NFT[] | undefined
124
+ ): NFT[] => {
125
+ if (!newNfts?.length) return oldNfts ?? [];
126
+
127
+ // Getting a map of id => NFT
128
+ const newNftsPerId: Record<string, NFT> = (newNfts as NFT[]).reduce(
129
+ (acc, curr) => setWith(acc, curr.id, curr, Object),
130
+ {}
131
+ );
132
+
133
+ // copying the argument to avoid mutating it
134
+ const nfts = oldNfts?.slice() ?? [];
135
+ for (let i = 0; i < nfts.length; i++) {
136
+ const nft = nfts[i];
137
+ // The NFTs are the same, do don't anything
138
+ if (!newNftsPerId[nft.id] || isEqual(nft, newNftsPerId[nft.id])) {
139
+ // NFT already in, deleting it from the newNfts to keep only the un-added ones at the end
140
+ delete newNftsPerId[nft.id];
141
+ continue;
142
+ }
143
+
144
+ // Use the new NFT instead (as a copy cause we're deleting the reference just after)
145
+ nfts[i] = Object.assign({}, newNftsPerId[nft.id]);
146
+ // Delete it from the newNfts to keep only the un-added ones at the end
147
+ delete newNftsPerId[nft.id];
148
+ }
149
+
150
+ // Adding the rest of newNfts that was not already in oldNfts
151
+ return nfts.concat(Object.values(newNftsPerId));
152
+ };
153
+
119
154
  export const makeSync =
120
155
  (
121
156
  getAccountShape: GetAccountShape,
package/src/csvExport.ts CHANGED
@@ -2,7 +2,7 @@ import { BigNumber } from "bignumber.js";
2
2
  import type { Currency, Account, AccountLike, Operation } from "./types";
3
3
  import { formatCurrencyUnit } from "./currencies";
4
4
  import { getAccountCurrency, getMainAccount, flattenAccounts } from "./account";
5
- import { flattenOperationWithInternals } from "./operation";
5
+ import { flattenOperationWithInternalsAndNfts } from "./operation";
6
6
  import { calculate } from "./countervalues/logic";
7
7
  import type { CounterValuesState } from "./countervalues/types";
8
8
 
@@ -143,7 +143,8 @@ const accountRows = (
143
143
  ): Array<string[]> =>
144
144
  account.operations
145
145
  .reduce(
146
- (ops: Operation[], op) => ops.concat(flattenOperationWithInternals(op)),
146
+ (ops: Operation[], op) =>
147
+ ops.concat(flattenOperationWithInternalsAndNfts(op)),
147
148
  []
148
149
  )
149
150
  .map((operation) =>