@ledgerhq/live-common 21.16.0 → 21.16.1

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 (83) hide show
  1. package/lib/account/formatters.d.ts.map +1 -1
  2. package/lib/account/formatters.js +33 -1
  3. package/lib/account/formatters.js.map +1 -1
  4. package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
  5. package/lib/families/bitcoin/datasets/bitcoin.js +4 -0
  6. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  7. package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
  8. package/lib/families/bitcoin/datasets/bitcoin_cash.js +4 -0
  9. package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
  10. package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
  11. package/lib/families/bitcoin/datasets/bitcoin_gold.js +4 -0
  12. package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
  13. package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
  14. package/lib/families/bitcoin/datasets/dash.js +4 -0
  15. package/lib/families/bitcoin/datasets/dash.js.map +1 -1
  16. package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
  17. package/lib/families/bitcoin/datasets/decred.js +4 -0
  18. package/lib/families/bitcoin/datasets/decred.js.map +1 -1
  19. package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
  20. package/lib/families/bitcoin/datasets/digibyte.js +4 -0
  21. package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
  22. package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
  23. package/lib/families/bitcoin/datasets/dogecoin.js +4 -0
  24. package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
  25. package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
  26. package/lib/families/bitcoin/datasets/komodo.js +4 -0
  27. package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
  28. package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
  29. package/lib/families/bitcoin/datasets/litecoin.js +4 -0
  30. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  31. package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
  32. package/lib/families/bitcoin/datasets/peercoin.js +4 -0
  33. package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
  34. package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
  35. package/lib/families/bitcoin/datasets/pivx.js +4 -0
  36. package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
  37. package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
  38. package/lib/families/bitcoin/datasets/qtum.js +4 -0
  39. package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
  40. package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
  41. package/lib/families/bitcoin/datasets/stakenet.js +4 -0
  42. package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
  43. package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
  44. package/lib/families/bitcoin/datasets/vertcoin.js +4 -0
  45. package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
  46. package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
  47. package/lib/families/bitcoin/datasets/viacoin.js +4 -0
  48. package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
  49. package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
  50. package/lib/families/bitcoin/datasets/zcash.js +4 -0
  51. package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
  52. package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
  53. package/lib/families/bitcoin/datasets/zencash.js +4 -0
  54. package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
  55. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  56. package/lib/families/bitcoin/js-synchronisation.js +30 -8
  57. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  58. package/lib/nft/NftMetadataProvider/index.d.ts +7 -0
  59. package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -1
  60. package/lib/nft/NftMetadataProvider/index.js +3 -3
  61. package/lib/nft/NftMetadataProvider/index.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/__tests__/__snapshots__/all.libcore.ts.snap +55 -122848
  64. package/src/account/formatters.ts +43 -0
  65. package/src/families/bitcoin/datasets/bitcoin.ts +4 -0
  66. package/src/families/bitcoin/datasets/bitcoin_cash.ts +4 -0
  67. package/src/families/bitcoin/datasets/bitcoin_gold.ts +4 -0
  68. package/src/families/bitcoin/datasets/dash.ts +4 -0
  69. package/src/families/bitcoin/datasets/decred.ts +4 -0
  70. package/src/families/bitcoin/datasets/digibyte.ts +4 -0
  71. package/src/families/bitcoin/datasets/dogecoin.ts +4 -0
  72. package/src/families/bitcoin/datasets/komodo.ts +4 -0
  73. package/src/families/bitcoin/datasets/litecoin.ts +4 -0
  74. package/src/families/bitcoin/datasets/peercoin.ts +4 -0
  75. package/src/families/bitcoin/datasets/pivx.ts +4 -0
  76. package/src/families/bitcoin/datasets/qtum.ts +4 -0
  77. package/src/families/bitcoin/datasets/stakenet.ts +4 -0
  78. package/src/families/bitcoin/datasets/vertcoin.ts +4 -0
  79. package/src/families/bitcoin/datasets/viacoin.ts +4 -0
  80. package/src/families/bitcoin/datasets/zcash.ts +4 -0
  81. package/src/families/bitcoin/datasets/zencash.ts +4 -0
  82. package/src/families/bitcoin/js-synchronisation.ts +37 -11
  83. package/src/nft/NftMetadataProvider/index.tsx +1 -1
@@ -12,6 +12,15 @@ import { formatCurrencyUnit } from "../currencies";
12
12
  import { getOperationAmountNumber } from "../operation";
13
13
  import { getTagDerivationMode } from "../derivation";
14
14
  import byFamily from "../generated/account";
15
+ import { nftsByCollections } from "../nft";
16
+
17
+ const styling = {
18
+ bold: (str: string) => `\x1b[1m${str}\x1b[22m`,
19
+ underline: (str: string) => `\x1b[4m${str}\x1b[24m`,
20
+ cyan: (str: string) => `\x1b[36m${str}\x1b[37m`,
21
+ magenta: (str: string) => `\x1b[35m${str}\x1b[37m`,
22
+ reverse: (str: string) => `\x1b[7m${str}\x1b[27m`,
23
+ };
15
24
 
16
25
  const isSignificantAccount = (acc) =>
17
26
  acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6));
@@ -80,6 +89,7 @@ const cliFormat = (account, level?: string) => {
80
89
  derivationMode,
81
90
  index,
82
91
  operations,
92
+ nfts,
83
93
  } = account;
84
94
  const tag = getTagDerivationMode(account.currency, derivationMode);
85
95
  const balance = formatCurrencyUnit(account.unit, account.balance, {
@@ -122,6 +132,39 @@ const cliFormat = (account, level?: string) => {
122
132
  maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountUnit(ta))
123
133
  )
124
134
  .join("\n");
135
+
136
+ if (nfts?.length) {
137
+ const NFTCollections = nftsByCollections(nfts);
138
+
139
+ str += "\n";
140
+ str += `NFT Collections (${NFTCollections.length}) `;
141
+ str += "\n";
142
+
143
+ str += NFTCollections.map(
144
+ // nfts are set to any because there not just NFT, we added a metadata prop on the fly
145
+ // in the first step of the Rxjs flow to avoid having some async code here
146
+ ({ contract, nfts }: { contract: string; nfts: any[] }) => {
147
+ const tokenName = nfts?.[0]?.metadata?.tokenName;
148
+ const { bold, magenta, cyan, reverse } = styling;
149
+
150
+ return (
151
+ `${bold(tokenName ?? "Unknown Collection Name")} (${magenta(
152
+ contract
153
+ )}): ` +
154
+ nfts
155
+ .map((t) =>
156
+ t?.metadata?.nftName
157
+ ? `\n ${t.amount}x ${reverse(
158
+ ` ${t?.metadata?.nftName} `
159
+ )} ${cyan("#" + t.tokenId)}`
160
+ : `\n ${t.amount}x ${cyan("#" + t.tokenId)}`
161
+ )
162
+ .join()
163
+ );
164
+ }
165
+ ).join("\n");
166
+ }
167
+
125
168
  if (level === "basic") return str;
126
169
  str += "\nOPERATIONS (" + operations.length + ")";
127
170
  str += operations
@@ -28,6 +28,10 @@ const networkInfo: NetworkInfoRaw = {
28
28
  },
29
29
  };
30
30
  const dataset: CurrenciesData<Transaction> = {
31
+ FIXME_ignoreAccountFields: [
32
+ "bitcoinResources.walletAccount", // it is not "stable"
33
+ "bitcoinResources.utxos", // TODO: fix ordering
34
+ ],
31
35
  scanAccounts: [scanAccounts1],
32
36
  accounts: [
33
37
  {
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "bitcoin_cash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "bitcoin_gold seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "dash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "decred seed 1",
@@ -27,6 +27,10 @@ const networkInfo: NetworkInfoRaw = {
27
27
  },
28
28
  };
29
29
  const dataset: CurrenciesData<Transaction> = {
30
+ FIXME_ignoreAccountFields: [
31
+ "bitcoinResources.walletAccount", // it is not "stable"
32
+ "bitcoinResources.utxos", // TODO: fix ordering
33
+ ],
30
34
  scanAccounts: [scanAccounts1],
31
35
  accounts: [
32
36
  {
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "dogecoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "komodo seed 1",
@@ -27,6 +27,10 @@ const networkInfo: NetworkInfoRaw = {
27
27
  },
28
28
  };
29
29
  const dataset: CurrenciesData<Transaction> = {
30
+ FIXME_ignoreAccountFields: [
31
+ "bitcoinResources.walletAccount", // it is not "stable"
32
+ "bitcoinResources.utxos", // TODO: fix ordering
33
+ ],
30
34
  scanAccounts: [scanAccounts1],
31
35
  accounts: [
32
36
  {
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "peercoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "pivx seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "qtum seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "stakenet seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "vertcoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "viacoin seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "zcash seed 1",
@@ -1,6 +1,10 @@
1
1
  import type { CurrenciesData } from "../../../types";
2
2
  import type { Transaction } from "../types";
3
3
  const dataset: CurrenciesData<Transaction> = {
4
+ FIXME_ignoreAccountFields: [
5
+ "bitcoinResources.walletAccount", // it is not "stable"
6
+ "bitcoinResources.utxos", // TODO: fix ordering
7
+ ],
4
8
  scanAccounts: [
5
9
  {
6
10
  name: "zencash seed 1",
@@ -129,24 +129,50 @@ const mapTxToOperations = (
129
129
  const transactionSequenceNumber =
130
130
  (accountInputs.length > 0 && accountInputs[0].sequence) || undefined;
131
131
 
132
- // Change output is the last one
132
+ const hasSpentNothing = value.eq(0);
133
+ // Change output is always the last one
133
134
  const changeOutputIndex = tx.outputs
134
135
  .map((o) => o.output_index)
135
136
  .reduce((p, c) => (p > c ? p : c));
136
137
 
137
138
  for (const output of tx.outputs) {
138
139
  if (output.address) {
139
- if (accountAddresses.includes(output.address)) {
140
+ if (!accountAddresses.includes(output.address)) {
141
+ // The output doesn't belong to this account
142
+ if (output.output_index < changeOutputIndex) {
143
+ // The output isn't the change output
144
+ recipients.push(
145
+ syncReplaceAddress
146
+ ? syncReplaceAddress(output.address)
147
+ : output.address
148
+ );
149
+ }
150
+ } else {
151
+ // The output belongs to this account
140
152
  accountOutputs.push(output);
141
- } else if (
142
- !changeAddresses.includes(output.address) ||
143
- output.output_index !== changeOutputIndex
144
- ) {
145
- recipients.push(
146
- syncReplaceAddress
147
- ? syncReplaceAddress(output.address)
148
- : output.address
149
- );
153
+
154
+ if (!changeAddresses.includes(output.address)) {
155
+ // The output isn't a change output of this account
156
+ recipients.push(
157
+ syncReplaceAddress
158
+ ? syncReplaceAddress(output.address)
159
+ : output.address
160
+ );
161
+ } else {
162
+ // The output is a change output of this account,
163
+ // we count it as a recipient only in some special cases
164
+ if (
165
+ (recipients.length === 0 &&
166
+ output.output_index >= changeOutputIndex) ||
167
+ hasSpentNothing
168
+ ) {
169
+ recipients.push(
170
+ syncReplaceAddress
171
+ ? syncReplaceAddress(output.address)
172
+ : output.address
173
+ );
174
+ }
175
+ }
150
176
  }
151
177
  }
152
178
  }
@@ -28,7 +28,7 @@ const NftMetadataContext = createContext<NFTMetadataContextType>({
28
28
  clearCache: () => {},
29
29
  });
30
30
 
31
- const metadataCallBatcher = (() => {
31
+ export const metadataCallBatcher = (() => {
32
32
  const batch: BatchElement[] = [];
33
33
 
34
34
  let debounce;