@ledgerhq/live-common 21.18.0 → 21.19.2
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/addAccounts.d.ts.map +1 -1
- package/lib/account/addAccounts.js +3 -2
- package/lib/account/addAccounts.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 +2 -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 +9 -8
- 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/getAccountNetworkInfo.d.ts.map +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.js +12 -2
- package/lib/families/bitcoin/getAccountNetworkInfo.js.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/bitcoin/types.d.ts +1 -0
- package/lib/families/bitcoin/types.d.ts.map +1 -1
- package/lib/families/bitcoin/types.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/explorer/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/index.js +19 -0
- package/lib/families/bitcoin/wallet-btc/explorer/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/explorer/types.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/explorer/types.d.ts.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.d.ts +2 -0
- package/lib/families/ethereum/nft.test.d.ts.map +1 -0
- package/lib/families/ethereum/nft.test.js +360 -0
- package/lib/families/ethereum/nft.test.js.map +1 -0
- package/lib/families/ethereum/signOperation.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +3 -12
- 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/synchronisation.test.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/hw/uninstallApp.d.ts.map +1 -1
- package/lib/hw/uninstallApp.js +1 -1
- package/lib/hw/uninstallApp.js.map +1 -1
- package/lib/nft/helpers.js +2 -3
- 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 +4 -4
- 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/addAccounts.ts +3 -2
- package/src/account/helpers.ts +1 -0
- package/src/api/Ethereum.ts +4 -4
- package/src/api/explorerConfig/index.ts +0 -4
- package/src/bridge/jsHelpers.ts +9 -8
- package/src/currencies/{.DS_Store → __snapshots__/.DS_Store} +0 -0
- package/src/env.ts +5 -0
- package/src/families/bitcoin/getAccountNetworkInfo.ts +8 -1
- package/src/families/bitcoin/test-dataset.ts +2 -2
- package/src/families/bitcoin/types.ts +1 -0
- package/src/families/bitcoin/wallet-btc/explorer/index.ts +7 -0
- package/src/families/bitcoin/wallet-btc/explorer/types.ts +1 -0
- 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 +263 -0
- package/src/families/ethereum/signOperation.ts +3 -16
- package/src/families/ethereum/synchronisation.test.ts +1 -0
- 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/hw/uninstallApp.ts +13 -8
- package/src/nft/helpers.ts +2 -2
- package/src/nft/index.ts +1 -0
- package/src/nft/support.ts +16 -0
- package/src/reconciliation.ts +4 -1
- package/src/types/account.ts +1 -1
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +0 -6152
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/LedgerHQ/ledger-live-common"
|
|
10
10
|
},
|
|
11
|
-
"version": "21.
|
|
11
|
+
"version": "21.19.2",
|
|
12
12
|
"main": "lib/index.js",
|
|
13
13
|
"types": "lib/index.d.ts",
|
|
14
14
|
"license": "Apache-2.0",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@crypto-com/chain-jslib": "0.0.19",
|
|
46
46
|
"@ledgerhq/compressjs": "1.3.2",
|
|
47
|
-
"@ledgerhq/cryptoassets": "6.
|
|
47
|
+
"@ledgerhq/cryptoassets": "6.18.0",
|
|
48
48
|
"@ledgerhq/devices": "6.11.2",
|
|
49
49
|
"@ledgerhq/errors": "6.10.0",
|
|
50
50
|
"@ledgerhq/hw-app-algorand": "6.11.2",
|
|
51
|
-
"@ledgerhq/hw-app-btc": "6.17.
|
|
51
|
+
"@ledgerhq/hw-app-btc": "6.17.1",
|
|
52
52
|
"@ledgerhq/hw-app-cosmos": "6.11.2",
|
|
53
|
-
"@ledgerhq/hw-app-eth": "6.
|
|
53
|
+
"@ledgerhq/hw-app-eth": "6.18.0",
|
|
54
54
|
"@ledgerhq/hw-app-polkadot": "6.11.2",
|
|
55
55
|
"@ledgerhq/hw-app-str": "6.11.2",
|
|
56
56
|
"@ledgerhq/hw-app-tezos": "6.11.2",
|
package/src/.DS_Store
CHANGED
|
Binary file
|
package/src/__tests__/.DS_Store
CHANGED
|
Binary file
|
|
@@ -11485,45 +11485,6 @@ Array [
|
|
|
11485
11485
|
]
|
|
11486
11486
|
`;
|
|
11487
11487
|
|
|
11488
|
-
exports[`bitcoin_cash currency bridge scanAccounts bitcoin_cash seed 1 1`] = `
|
|
11489
|
-
Array [
|
|
11490
|
-
Object {
|
|
11491
|
-
"balance": "0",
|
|
11492
|
-
"bitcoinResources": Object {},
|
|
11493
|
-
"currencyId": "bitcoin_cash",
|
|
11494
|
-
"derivationMode": "",
|
|
11495
|
-
"freshAddress": "bitcoincash:qrt2zkjjchuxkmr3f70tc2yppl5pxwr36uuur9lzm9",
|
|
11496
|
-
"freshAddressPath": "44'/145'/0'/0/0",
|
|
11497
|
-
"freshAddresses": Array [
|
|
11498
|
-
Object {
|
|
11499
|
-
"address": "1LZru3UChDXkw4aYzn5dFdjvNDrKp3MtiA",
|
|
11500
|
-
"derivationPath": "44'/145'/0'/0/0",
|
|
11501
|
-
},
|
|
11502
|
-
],
|
|
11503
|
-
"id": "js:2:bitcoin_cash:xpub6D7pqJa4V3SFSigcsRaFL2mpfG7469osrMkk4ieR2uk8y1v3nuQUD8W8v36PLWQtVRSggSQM7jLpGNKH7sqCaoPSJEp9wZCVkRnMWoiUUXa:",
|
|
11504
|
-
"index": 0,
|
|
11505
|
-
"name": "Bitcoin Cash 1",
|
|
11506
|
-
"nfts": undefined,
|
|
11507
|
-
"operationsCount": 0,
|
|
11508
|
-
"pendingOperations": Array [],
|
|
11509
|
-
"seedIdentifier": "04884ed3fe628a8487f782f97f38e7a9f014e624f1ea679951cf3a67445ea33fb334f4cc19e6c421b3ef9943d526cd4fbfebacebe8a62cc45db79a33d3ab04bd47",
|
|
11510
|
-
"spendableBalance": "0",
|
|
11511
|
-
"starred": false,
|
|
11512
|
-
"swapHistory": Array [],
|
|
11513
|
-
"syncHash": undefined,
|
|
11514
|
-
"unitMagnitude": 8,
|
|
11515
|
-
"used": false,
|
|
11516
|
-
"xpub": "xpub6D7pqJa4V3SFSigcsRaFL2mpfG7469osrMkk4ieR2uk8y1v3nuQUD8W8v36PLWQtVRSggSQM7jLpGNKH7sqCaoPSJEp9wZCVkRnMWoiUUXa",
|
|
11517
|
-
},
|
|
11518
|
-
]
|
|
11519
|
-
`;
|
|
11520
|
-
|
|
11521
|
-
exports[`bitcoin_cash currency bridge scanAccounts bitcoin_cash seed 1 2`] = `
|
|
11522
|
-
Array [
|
|
11523
|
-
Array [],
|
|
11524
|
-
]
|
|
11525
|
-
`;
|
|
11526
|
-
|
|
11527
11488
|
exports[`dash currency bridge scanAccounts dash seed 1 1`] = `
|
|
11528
11489
|
Array [
|
|
11529
11490
|
Object {
|
|
@@ -15216,7 +15177,7 @@ Array [
|
|
|
15216
15177
|
"starred": false,
|
|
15217
15178
|
"subAccounts": Array [],
|
|
15218
15179
|
"swapHistory": Array [],
|
|
15219
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
15180
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
15220
15181
|
"unitMagnitude": 18,
|
|
15221
15182
|
"used": true,
|
|
15222
15183
|
},
|
|
@@ -15257,7 +15218,7 @@ Array [
|
|
|
15257
15218
|
"starred": false,
|
|
15258
15219
|
"subAccounts": Array [],
|
|
15259
15220
|
"swapHistory": Array [],
|
|
15260
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
15221
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
15261
15222
|
"unitMagnitude": 18,
|
|
15262
15223
|
"used": true,
|
|
15263
15224
|
},
|
|
@@ -15737,7 +15698,7 @@ Array [
|
|
|
15737
15698
|
"starred": false,
|
|
15738
15699
|
"subAccounts": Array [],
|
|
15739
15700
|
"swapHistory": Array [],
|
|
15740
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
15701
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
15741
15702
|
"unitMagnitude": 18,
|
|
15742
15703
|
"used": true,
|
|
15743
15704
|
},
|
|
@@ -16072,7 +16033,7 @@ Array [
|
|
|
16072
16033
|
"starred": false,
|
|
16073
16034
|
"subAccounts": Array [],
|
|
16074
16035
|
"swapHistory": Array [],
|
|
16075
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
16036
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
16076
16037
|
"unitMagnitude": 18,
|
|
16077
16038
|
"used": true,
|
|
16078
16039
|
},
|
|
@@ -16169,7 +16130,7 @@ Array [
|
|
|
16169
16130
|
"starred": false,
|
|
16170
16131
|
"subAccounts": Array [],
|
|
16171
16132
|
"swapHistory": Array [],
|
|
16172
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
16133
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
16173
16134
|
"unitMagnitude": 18,
|
|
16174
16135
|
"used": true,
|
|
16175
16136
|
},
|
|
@@ -16294,7 +16255,7 @@ Array [
|
|
|
16294
16255
|
"starred": false,
|
|
16295
16256
|
"subAccounts": Array [],
|
|
16296
16257
|
"swapHistory": Array [],
|
|
16297
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
16258
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
16298
16259
|
"unitMagnitude": 18,
|
|
16299
16260
|
"used": true,
|
|
16300
16261
|
},
|
|
@@ -16391,7 +16352,7 @@ Array [
|
|
|
16391
16352
|
"starred": false,
|
|
16392
16353
|
"subAccounts": Array [],
|
|
16393
16354
|
"swapHistory": Array [],
|
|
16394
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
16355
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_6026",
|
|
16395
16356
|
"unitMagnitude": 18,
|
|
16396
16357
|
"used": true,
|
|
16397
16358
|
},
|
|
@@ -48324,7 +48285,7 @@ Array [
|
|
|
48324
48285
|
"starred": false,
|
|
48325
48286
|
"subAccounts": Array [],
|
|
48326
48287
|
"swapHistory": Array [],
|
|
48327
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
48288
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_0",
|
|
48328
48289
|
"unitMagnitude": 18,
|
|
48329
48290
|
"used": true,
|
|
48330
48291
|
},
|
|
@@ -48351,7 +48312,7 @@ Array [
|
|
|
48351
48312
|
"starred": false,
|
|
48352
48313
|
"subAccounts": Array [],
|
|
48353
48314
|
"swapHistory": Array [],
|
|
48354
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
48315
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_0",
|
|
48355
48316
|
"unitMagnitude": 18,
|
|
48356
48317
|
"used": true,
|
|
48357
48318
|
},
|
|
@@ -48378,7 +48339,7 @@ Array [
|
|
|
48378
48339
|
"starred": false,
|
|
48379
48340
|
"subAccounts": Array [],
|
|
48380
48341
|
"swapHistory": Array [],
|
|
48381
|
-
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]
|
|
48342
|
+
"syncHash": "[\\"ethereum/erc20/ampleforth\\",\\"ethereum/erc20/steth\\"]_false_0",
|
|
48382
48343
|
"unitMagnitude": 18,
|
|
48383
48344
|
"used": true,
|
|
48384
48345
|
},
|
|
@@ -74,7 +74,7 @@ export function groupAddAccounts(
|
|
|
74
74
|
);
|
|
75
75
|
|
|
76
76
|
if (existingAccount) {
|
|
77
|
-
if (!acc.used) {
|
|
77
|
+
if (!acc.used && !alreadyEmptyAccount) {
|
|
78
78
|
alreadyEmptyAccount = existingAccount;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -122,7 +122,8 @@ export function groupAddAccounts(
|
|
|
122
122
|
? creatableAccounts.filter(
|
|
123
123
|
(a) =>
|
|
124
124
|
context.preferredNewAccountSchemes &&
|
|
125
|
-
|
|
125
|
+
// Note: we could use a simple preferredNewAccountScheme param
|
|
126
|
+
a.derivationMode === context.preferredNewAccountSchemes[0]
|
|
126
127
|
)
|
|
127
128
|
: creatableAccounts,
|
|
128
129
|
});
|
package/src/account/helpers.ts
CHANGED
|
@@ -150,6 +150,7 @@ export function clearAccount<T extends AccountLike>(account: T): T {
|
|
|
150
150
|
copy.bitcoinResources = initialBitcoinResourcesValue;
|
|
151
151
|
}
|
|
152
152
|
delete copy.balanceHistory;
|
|
153
|
+
delete copy.nfts;
|
|
153
154
|
return copy as T;
|
|
154
155
|
}
|
|
155
156
|
export function findSubAccountById(
|
package/src/api/Ethereum.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { blockchainBaseURL } from "./Ledger";
|
|
|
10
10
|
import { FeeEstimationFailed } from "../errors";
|
|
11
11
|
import { makeLRUCache } from "../cache";
|
|
12
12
|
import { getEnv } from "../env";
|
|
13
|
+
import { isNFTActive } from "../nft/support";
|
|
13
14
|
|
|
14
15
|
export type Block = {
|
|
15
16
|
height: BigNumber;
|
|
@@ -132,10 +133,9 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
|
|
|
132
133
|
let { data } = await network({
|
|
133
134
|
method: "GET",
|
|
134
135
|
url: URL.format({
|
|
135
|
-
pathname:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
: `${baseURL}/addresses/${address}/transactions`,
|
|
136
|
+
pathname: isNFTActive(currency)
|
|
137
|
+
? `https://explorers.api-01.live.ledger-stg.com/blockchain/v3/eth/addresses/${address}/transactions`
|
|
138
|
+
: `${baseURL}/addresses/${address}/transactions`,
|
|
139
139
|
query: {
|
|
140
140
|
batch_size,
|
|
141
141
|
noinput: true,
|
package/src/bridge/jsHelpers.ts
CHANGED
|
@@ -134,21 +134,22 @@ export const mergeNfts = (
|
|
|
134
134
|
const nfts = oldNfts?.slice() ?? [];
|
|
135
135
|
for (let i = 0; i < nfts.length; i++) {
|
|
136
136
|
const nft = nfts[i];
|
|
137
|
+
|
|
137
138
|
// The NFTs are the same, do don't anything
|
|
138
|
-
if (!newNftsPerId[nft.id]
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
if (!newNftsPerId[nft.id]) {
|
|
140
|
+
nfts.splice(i, 1);
|
|
141
|
+
i--;
|
|
142
|
+
} else if (!isEqual(nft, newNftsPerId[nft.id])) {
|
|
143
|
+
// Use the new NFT instead (as a copy cause we're deleting the reference just after)
|
|
144
|
+
nfts[i] = Object.assign({}, newNftsPerId[nft.id]);
|
|
142
145
|
}
|
|
143
146
|
|
|
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
147
|
// Delete it from the newNfts to keep only the un-added ones at the end
|
|
147
148
|
delete newNftsPerId[nft.id];
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
//
|
|
151
|
-
return
|
|
151
|
+
// Prepending newNfts to respect nfts's newest to oldest order
|
|
152
|
+
return Object.values(newNftsPerId).concat(nfts);
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
export const makeSync =
|
|
Binary file
|
package/src/env.ts
CHANGED
|
@@ -381,6 +381,11 @@ const envDefinitions = {
|
|
|
381
381
|
parser: boolParser,
|
|
382
382
|
desc: "synchronizing nfts",
|
|
383
383
|
},
|
|
384
|
+
NFT_CURRENCIES: {
|
|
385
|
+
def: "ethereum",
|
|
386
|
+
parser: stringParser,
|
|
387
|
+
desc: "set the currencies where NFT is active",
|
|
388
|
+
},
|
|
384
389
|
NFT_ETH_METADATA_SERVICE: {
|
|
385
390
|
// FIXME LL-8001
|
|
386
391
|
def: "https://nft.staging.aws.ledger.fr/v1/ethereum/1/contracts/tokens/infos",
|
|
@@ -20,6 +20,7 @@ export async function getAccountNetworkInfo(
|
|
|
20
20
|
): Promise<NetworkInfo> {
|
|
21
21
|
const walletAccount = getWalletAccount(account);
|
|
22
22
|
const rawFees = await walletAccount.xpub.explorer.getFees();
|
|
23
|
+
const relayFee = await walletAccount.xpub.explorer.getRelayFee();
|
|
23
24
|
// Convoluted logic to convert from:
|
|
24
25
|
// { "2": 2435, "3": 1241, "6": 1009, "last_updated": 1627973170 }
|
|
25
26
|
// to:
|
|
@@ -44,7 +45,12 @@ export async function getAccountNetworkInfo(
|
|
|
44
45
|
if (feesPerByte.length !== 3) {
|
|
45
46
|
throw new Error("cardinality of feesPerByte should be exactly 3");
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
// Fix fees if suggested fee is too low
|
|
49
|
+
if (feesPerByte[2].toNumber() < Math.ceil(relayFee * 100000)) {
|
|
50
|
+
feesPerByte[2] = new BigNumber(Math.ceil(relayFee * 100000)).plus(1);
|
|
51
|
+
feesPerByte[1] = feesPerByte[2].plus(1);
|
|
52
|
+
feesPerByte[0] = feesPerByte[1].plus(1);
|
|
53
|
+
}
|
|
48
54
|
const feeItems = {
|
|
49
55
|
items: feesPerByte.map((feePerByte, i) => ({
|
|
50
56
|
key: String(i),
|
|
@@ -53,6 +59,7 @@ export async function getAccountNetworkInfo(
|
|
|
53
59
|
})),
|
|
54
60
|
defaultFeePerByte:
|
|
55
61
|
feesPerByte[Math.floor(feesPerByte.length / 2)] || new BigNumber(0),
|
|
62
|
+
relayFee,
|
|
56
63
|
};
|
|
57
64
|
return {
|
|
58
65
|
family: "bitcoin",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DatasetTest } from "../../types";
|
|
2
2
|
import type { Transaction } from "./types";
|
|
3
|
-
import bitcoin_cash from "./datasets/bitcoin_cash";
|
|
3
|
+
// import bitcoin_cash from "./datasets/bitcoin_cash";
|
|
4
4
|
// import bitcoin_gold from "./datasets/bitcoin_gold";
|
|
5
5
|
import bitcoin from "./datasets/bitcoin";
|
|
6
6
|
import dash from "./datasets/dash";
|
|
@@ -21,7 +21,7 @@ const dataset: DatasetTest<Transaction> = {
|
|
|
21
21
|
implementations: ["js", "libcore", "mock"],
|
|
22
22
|
currencies: {
|
|
23
23
|
bitcoin,
|
|
24
|
-
bitcoin_cash,
|
|
24
|
+
// bitcoin_cash,
|
|
25
25
|
// bitcoin_gold,
|
|
26
26
|
dash,
|
|
27
27
|
// decred, // BACK-2443
|
|
@@ -168,6 +168,13 @@ class BitcoinLikeExplorer extends EventEmitter implements IExplorer {
|
|
|
168
168
|
return fees;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
async getRelayFee() {
|
|
172
|
+
const client = await this.client.acquire();
|
|
173
|
+
const fees = (await client.client.get(`/network`)).data;
|
|
174
|
+
await this.client.release(client);
|
|
175
|
+
return parseFloat(fees["relay_fee"]);
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
async getPendings(address: Address, nbMax?: number) {
|
|
172
179
|
const params: {
|
|
173
180
|
no_token?: string;
|
|
@@ -9,6 +9,7 @@ export interface IExplorer {
|
|
|
9
9
|
getTxHex(txId: string): Promise<string>;
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
11
|
getFees(): Promise<any>;
|
|
12
|
+
getRelayFee(): Promise<number>;
|
|
12
13
|
getCurrentBlock(): Promise<Block | null>;
|
|
13
14
|
getBlockByHeight(height: number): Promise<Block | null>;
|
|
14
15
|
getPendings(address: Address, nbMax?: number): Promise<TX[]>;
|
|
@@ -24,11 +24,16 @@ import {
|
|
|
24
24
|
estimateGasLimit,
|
|
25
25
|
} from "../transaction";
|
|
26
26
|
import { getAccountShape } from "../synchronisation";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
preload,
|
|
29
|
+
hydrate,
|
|
30
|
+
prepareTransaction as prepareTransactionModules,
|
|
31
|
+
} from "../modules";
|
|
28
32
|
import { signOperation } from "../signOperation";
|
|
29
33
|
import { modes } from "../modules";
|
|
30
34
|
import postSyncPatch from "../postSyncPatch";
|
|
31
35
|
import { inferDynamicRange } from "../../../range";
|
|
36
|
+
|
|
32
37
|
const receive = makeAccountBridgeReceive();
|
|
33
38
|
|
|
34
39
|
const broadcast = async ({
|
|
@@ -173,6 +178,8 @@ const prepareTransaction = async (a, t: Transaction): Promise<Transaction> => {
|
|
|
173
178
|
t.estimatedGasLimit = estimatedGasLimit;
|
|
174
179
|
}
|
|
175
180
|
|
|
181
|
+
t = await prepareTransactionModules(a, t);
|
|
182
|
+
|
|
176
183
|
return t;
|
|
177
184
|
};
|
|
178
185
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { validateRecipient } from "../transaction";
|
|
10
10
|
import type { ModeModule, Transaction } from "../types";
|
|
11
11
|
import type { Account } from "../../../types";
|
|
12
|
+
import { prepareTransaction } from "./erc721";
|
|
12
13
|
|
|
13
14
|
const notOwnedNft = createCustomErrorClass("NotOwnedNft");
|
|
14
15
|
const notEnoughNftOwned = createCustomErrorClass("NotEnoughNftOwned");
|
|
@@ -75,25 +76,37 @@ const erc1155Transfer: ModeModule = {
|
|
|
75
76
|
fields.push({
|
|
76
77
|
type: "text",
|
|
77
78
|
label: "Type",
|
|
78
|
-
value: `
|
|
79
|
+
value: `NFT Transfer`,
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
fields.push({
|
|
82
83
|
type: "text",
|
|
83
|
-
label: "
|
|
84
|
-
value: input.transaction.
|
|
84
|
+
label: "To",
|
|
85
|
+
value: input.transaction.recipient ?? "",
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
fields.push({
|
|
88
89
|
type: "text",
|
|
89
|
-
label: "
|
|
90
|
-
value: input.transaction.
|
|
90
|
+
label: "Collection Name",
|
|
91
|
+
value: input.transaction.collectionName || "",
|
|
91
92
|
});
|
|
92
93
|
|
|
93
94
|
fields.push({
|
|
94
95
|
type: "text",
|
|
95
|
-
label: "
|
|
96
|
-
value: input.transaction.quantities?.
|
|
96
|
+
label: "Quantity",
|
|
97
|
+
value: input.transaction.quantities?.[0]?.toFixed() ?? "",
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
fields.push({
|
|
101
|
+
type: "address",
|
|
102
|
+
label: "NFT Address",
|
|
103
|
+
address: input.transaction.collection ?? "",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
fields.push({
|
|
107
|
+
type: "text",
|
|
108
|
+
label: "NFT ID",
|
|
109
|
+
value: input.transaction.tokenIds?.[0] ?? "",
|
|
97
110
|
});
|
|
98
111
|
},
|
|
99
112
|
|
|
@@ -107,6 +120,8 @@ const erc1155Transfer: ModeModule = {
|
|
|
107
120
|
approving: true, // workaround to track the status ENABLING
|
|
108
121
|
};
|
|
109
122
|
},
|
|
123
|
+
|
|
124
|
+
prepareTransaction,
|
|
110
125
|
};
|
|
111
126
|
|
|
112
127
|
function serializeTransactionData(
|
|
@@ -9,11 +9,35 @@ import {
|
|
|
9
9
|
import { validateRecipient } from "../transaction";
|
|
10
10
|
import type { ModeModule, Transaction } from "../types";
|
|
11
11
|
import type { Account } from "../../../types";
|
|
12
|
+
import { apiForCurrency } from "../../../api/Ethereum";
|
|
12
13
|
|
|
13
14
|
const notOwnedNft = createCustomErrorClass("NotOwnedNft");
|
|
14
15
|
|
|
15
16
|
export type Modes = "erc721.transfer";
|
|
16
17
|
|
|
18
|
+
export async function prepareTransaction(
|
|
19
|
+
account: Account,
|
|
20
|
+
transaction: Transaction
|
|
21
|
+
): Promise<Transaction> {
|
|
22
|
+
let t = transaction;
|
|
23
|
+
const { collection, collectionName, tokenIds } = transaction;
|
|
24
|
+
if (collection && tokenIds && typeof collectionName === "undefined") {
|
|
25
|
+
const api = apiForCurrency(account.currency);
|
|
26
|
+
const [{ status, result }] = await api.getNFTMetadata([
|
|
27
|
+
{
|
|
28
|
+
contract: collection,
|
|
29
|
+
tokenId: tokenIds[0],
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
let collectionName = ""; // default value fallback if issue
|
|
33
|
+
if (status === 200) {
|
|
34
|
+
collectionName = result?.tokenName || "";
|
|
35
|
+
}
|
|
36
|
+
t = { ...t, collectionName };
|
|
37
|
+
}
|
|
38
|
+
return Promise.resolve(t);
|
|
39
|
+
}
|
|
40
|
+
|
|
17
41
|
const erc721Transfer: ModeModule = {
|
|
18
42
|
/**
|
|
19
43
|
* Tx data is filled during the buildEthereumTx
|
|
@@ -52,6 +76,8 @@ const erc721Transfer: ModeModule = {
|
|
|
52
76
|
}
|
|
53
77
|
},
|
|
54
78
|
|
|
79
|
+
prepareTransaction,
|
|
80
|
+
|
|
55
81
|
/**
|
|
56
82
|
* This will only be used by LLM & LLD, not the HW.
|
|
57
83
|
*/
|
|
@@ -59,18 +85,30 @@ const erc721Transfer: ModeModule = {
|
|
|
59
85
|
fields.push({
|
|
60
86
|
type: "text",
|
|
61
87
|
label: "Type",
|
|
62
|
-
value: `
|
|
88
|
+
value: `NFT Transfer`,
|
|
63
89
|
});
|
|
64
90
|
|
|
65
91
|
fields.push({
|
|
66
92
|
type: "text",
|
|
67
|
-
label: "
|
|
68
|
-
value: input.transaction.
|
|
93
|
+
label: "To",
|
|
94
|
+
value: input.transaction.recipient ?? "",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
fields.push({
|
|
98
|
+
type: "text",
|
|
99
|
+
label: "Collection Name",
|
|
100
|
+
value: input.transaction.collectionName || "",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
fields.push({
|
|
104
|
+
type: "address",
|
|
105
|
+
label: "NFT Address",
|
|
106
|
+
address: input.transaction.collection ?? "",
|
|
69
107
|
});
|
|
70
108
|
|
|
71
109
|
fields.push({
|
|
72
110
|
type: "text",
|
|
73
|
-
label: "
|
|
111
|
+
label: "NFT ID",
|
|
74
112
|
value: input.transaction.tokenIds?.[0] ?? "",
|
|
75
113
|
});
|
|
76
114
|
},
|
|
@@ -90,6 +90,14 @@ export type ModeModule = {
|
|
|
90
90
|
arg1: Transaction,
|
|
91
91
|
arg2: Operation
|
|
92
92
|
) => void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* hook to resolve a transaction like the prepareTransaction of the bridge
|
|
96
|
+
*/
|
|
97
|
+
prepareTransaction?: (
|
|
98
|
+
account: Account,
|
|
99
|
+
transaction: Transaction
|
|
100
|
+
) => Promise<Transaction>;
|
|
93
101
|
};
|
|
94
102
|
export const modes: Record<TransactionMode, ModeModule> = {} as Record<
|
|
95
103
|
TransactionMode,
|
|
@@ -137,6 +145,18 @@ export function hydrate(value: unknown, currency: CryptoCurrency): void {
|
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
147
|
}
|
|
148
|
+
export const prepareTransaction = (
|
|
149
|
+
account: Account,
|
|
150
|
+
transaction: Transaction
|
|
151
|
+
): Promise<Transaction> =>
|
|
152
|
+
values(modules)
|
|
153
|
+
// @ts-expect-error some module implement it
|
|
154
|
+
.map((m) => m.prepareTransaction)
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.reduce(
|
|
157
|
+
(p, fn) => p.then((t) => fn(account, t)),
|
|
158
|
+
Promise.resolve(transaction)
|
|
159
|
+
);
|
|
140
160
|
export const prepareTokenAccounts = (
|
|
141
161
|
currency: CryptoCurrency,
|
|
142
162
|
subAccounts: TokenAccount[],
|