@ledgerhq/coin-polkadot 0.1.7 → 0.2.0-next.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.
- package/.eslintrc.js +8 -46
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -7
- package/package.json +10 -19
- package/src/account.ts +10 -33
- package/src/address.ts +2 -6
- package/src/api/bisontrails.ts +14 -45
- package/src/api/common.ts +2 -8
- package/src/api/index.ts +22 -44
- package/src/api/sidecar.ts +58 -93
- package/src/api/sidecar.unit.test.ts +48 -0
- package/src/bridge/js.ts +4 -7
- package/src/bridge.integration.test.ts +11 -17
- package/src/cli-transaction.ts +52 -82
- package/src/deviceTransactionConfig.ts +3 -9
- package/src/errors.ts +13 -33
- package/src/js-buildTransaction.ts +8 -18
- package/src/js-getFeesForTransaction.ts +2 -11
- package/src/js-getTransactionStatus.ts +26 -53
- package/src/js-prepareTransaction.ts +1 -2
- package/src/js-signOperation.ts +16 -32
- package/src/js-synchronisation.ts +3 -9
- package/src/logic.ts +13 -32
- package/src/platformAdapter.ts +2 -4
- package/src/preload.ts +39 -59
- package/src/serialization.ts +11 -16
- package/src/specs.ts +20 -52
- package/src/speculos-deviceActions.ts +81 -84
- package/src/transaction.ts +2 -4
- package/src/types.ts +2 -8
package/.eslintrc.js
CHANGED
|
@@ -1,57 +1,19 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
parser: "@typescript-eslint/parser",
|
|
3
2
|
env: {
|
|
4
3
|
browser: true,
|
|
5
4
|
es6: true,
|
|
6
|
-
node: true,
|
|
7
|
-
jest: true,
|
|
8
5
|
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
overrides: [
|
|
7
|
+
{
|
|
8
|
+
files: ["src/**/*.test.{ts,tsx}"],
|
|
9
|
+
env: {
|
|
10
|
+
"jest/globals": true,
|
|
11
|
+
},
|
|
12
|
+
plugins: ["jest"],
|
|
13
|
+
},
|
|
14
14
|
],
|
|
15
|
-
globals: {
|
|
16
|
-
Atomics: "readonly",
|
|
17
|
-
SharedArrayBuffer: "readonly",
|
|
18
|
-
},
|
|
19
|
-
plugins: ["@typescript-eslint", "prettier"],
|
|
20
15
|
rules: {
|
|
21
16
|
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
22
|
-
"linebreak-style": ["error", "unix"],
|
|
23
|
-
semi: ["error", "always"],
|
|
24
|
-
"no-unused-vars": "off",
|
|
25
|
-
"import/prefer-default-export": 0,
|
|
26
|
-
"no-plusplus": 0,
|
|
27
|
-
"no-underscore-dangle": 0,
|
|
28
|
-
"prefer-template": 0,
|
|
29
|
-
"no-await-in-loop": 0,
|
|
30
|
-
"no-restricted-syntax": 0,
|
|
31
|
-
"consistent-return": 0,
|
|
32
|
-
"no-lonely-if": 0,
|
|
33
|
-
"no-use-before-define": 0,
|
|
34
|
-
"no-nested-ternary": 0,
|
|
35
|
-
"import/no-cycle": 0,
|
|
36
|
-
"no-multi-assign": 0,
|
|
37
|
-
"guard-for-in": 0,
|
|
38
|
-
"no-continue": 0,
|
|
39
|
-
"lines-between-class-members": 0,
|
|
40
|
-
"prefer-destructuring": 0,
|
|
41
|
-
"prettier/prettier": "error",
|
|
42
|
-
"@typescript-eslint/no-use-before-define": "off",
|
|
43
|
-
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
|
44
17
|
"@typescript-eslint/no-empty-function": "off",
|
|
45
|
-
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
|
|
46
|
-
"@typescript-eslint/no-explicit-any": 0,
|
|
47
|
-
"@typescript-eslint/ban-types": [
|
|
48
|
-
"error",
|
|
49
|
-
{
|
|
50
|
-
extendDefaults: true,
|
|
51
|
-
types: {
|
|
52
|
-
"{}": false,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
18
|
},
|
|
57
19
|
};
|
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# @ledgerhq/coin-polkadot
|
|
2
2
|
|
|
3
|
-
## 0.1
|
|
3
|
+
## 0.2.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3660](https://github.com/LedgerHQ/ledger-live/pull/3660) [`895205e898`](https://github.com/LedgerHQ/ledger-live/commit/895205e8981612616d3147de9261d19051dbc0b2) Thanks [@live-github-bot](https://github.com/apps/live-github-bot)! - Update lockedbalance retrieval polkadot
|
|
8
|
+
|
|
9
|
+
## 0.1.7-next.0
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
6
12
|
|
|
7
|
-
- Updated dependencies [[`4a1454beb3`](https://github.com/LedgerHQ/ledger-live/commit/4a1454beb3f86405ba2686e07879c12a7d35ad8e), [`809065c571`](https://github.com/LedgerHQ/ledger-live/commit/809065c57198646a49adea112b9d799e35a57d25), [`ebe5b07afe`](https://github.com/LedgerHQ/ledger-live/commit/ebe5b07afec441ea3e2d9103da9e1175972add47)]:
|
|
8
|
-
- @ledgerhq/
|
|
9
|
-
- @ledgerhq/
|
|
10
|
-
- @ledgerhq/types-
|
|
11
|
-
- @ledgerhq/
|
|
12
|
-
- @ledgerhq/
|
|
13
|
+
- Updated dependencies [[`9adc1862dd`](https://github.com/LedgerHQ/ledger-live/commit/9adc1862dda605a722d19f3b6895bd324834c914), [`4a1454beb3`](https://github.com/LedgerHQ/ledger-live/commit/4a1454beb3f86405ba2686e07879c12a7d35ad8e), [`809065c571`](https://github.com/LedgerHQ/ledger-live/commit/809065c57198646a49adea112b9d799e35a57d25), [`d1aa522db7`](https://github.com/LedgerHQ/ledger-live/commit/d1aa522db75f7ea850efe412abaa4dc7d37af6b7), [`ebe5b07afe`](https://github.com/LedgerHQ/ledger-live/commit/ebe5b07afec441ea3e2d9103da9e1175972add47)]:
|
|
14
|
+
- @ledgerhq/errors@6.12.7-next.0
|
|
15
|
+
- @ledgerhq/cryptoassets@9.8.0-next.0
|
|
16
|
+
- @ledgerhq/types-cryptoassets@7.2.1-next.0
|
|
17
|
+
- @ledgerhq/types-live@6.35.1-next.0
|
|
18
|
+
- @ledgerhq/coin-framework@0.3.6-next.0
|
|
19
|
+
- @ledgerhq/devices@8.0.4-next.0
|
|
20
|
+
- @ledgerhq/hw-app-polkadot@6.27.16-next.0
|
|
21
|
+
- @ledgerhq/live-portfolio@0.0.8-next.0
|
|
13
22
|
|
|
14
23
|
## 0.1.6
|
|
15
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-polkadot",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.0-next.1",
|
|
4
4
|
"description": "Ledger Polkadot Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -54,32 +54,23 @@
|
|
|
54
54
|
"invariant": "^2.2.2",
|
|
55
55
|
"lodash": "^4.17.21",
|
|
56
56
|
"rxjs": "^6.6.7",
|
|
57
|
-
"@ledgerhq/coin-framework": "^0.3.6",
|
|
58
|
-
"@ledgerhq/cryptoassets": "^9.8.0",
|
|
59
|
-
"@ledgerhq/devices": "^8.0.
|
|
60
|
-
"@ledgerhq/errors": "^6.12.
|
|
61
|
-
"@ledgerhq/hw-app-polkadot": "^6.27.
|
|
57
|
+
"@ledgerhq/coin-framework": "^0.3.6-next.0",
|
|
58
|
+
"@ledgerhq/cryptoassets": "^9.8.0-next.0",
|
|
59
|
+
"@ledgerhq/devices": "^8.0.4-next.0",
|
|
60
|
+
"@ledgerhq/errors": "^6.12.7-next.0",
|
|
61
|
+
"@ledgerhq/hw-app-polkadot": "^6.27.16-next.0",
|
|
62
62
|
"@ledgerhq/live-env": "^0.3.0",
|
|
63
|
-
"@ledgerhq/live-portfolio": "^0.0.8",
|
|
63
|
+
"@ledgerhq/live-portfolio": "^0.0.8-next.0",
|
|
64
64
|
"@ledgerhq/live-promise": "^0.0.1",
|
|
65
65
|
"@ledgerhq/logs": "^6.10.1",
|
|
66
|
-
"@ledgerhq/types-cryptoassets": "^7.2.1",
|
|
67
|
-
"@ledgerhq/types-live": "^6.35.1"
|
|
66
|
+
"@ledgerhq/types-cryptoassets": "^7.2.1-next.0",
|
|
67
|
+
"@ledgerhq/types-live": "^6.35.1-next.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/invariant": "^2.2.2",
|
|
71
71
|
"@types/jest": "^29.2.4",
|
|
72
72
|
"@types/lodash": "^4.14.191",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
74
|
-
"@typescript-eslint/parser": "^5.46.1",
|
|
75
|
-
"eslint": "^7.32.0",
|
|
76
|
-
"eslint-config-prettier": "^8.3.0",
|
|
77
|
-
"eslint-config-typescript": "^3.0.0",
|
|
78
|
-
"eslint-formatter-pretty": "^3.0.1",
|
|
79
|
-
"eslint-plugin-prettier": "^3.4.0",
|
|
80
|
-
"eslint-plugin-typescript": "^0.14.0",
|
|
81
73
|
"jest": "^28.1.1",
|
|
82
|
-
"prettier": "^2.8.1",
|
|
83
74
|
"ts-jest": "^28.0.5"
|
|
84
75
|
},
|
|
85
76
|
"scripts": {
|
|
@@ -88,7 +79,7 @@
|
|
|
88
79
|
"prewatch": "pnpm build",
|
|
89
80
|
"watch": "tsc --watch",
|
|
90
81
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
91
|
-
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
82
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
92
83
|
"lint:fix": "pnpm lint --fix",
|
|
93
84
|
"test": "jest"
|
|
94
85
|
}
|
package/src/account.ts
CHANGED
|
@@ -6,10 +6,7 @@ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
|
6
6
|
import { PolkadotAccount, PolkadotResources } from "./types";
|
|
7
7
|
import type { Unit } from "@ledgerhq/types-cryptoassets";
|
|
8
8
|
|
|
9
|
-
function formatOperationSpecifics(
|
|
10
|
-
op: Operation,
|
|
11
|
-
unit: Unit | null | undefined
|
|
12
|
-
): string {
|
|
9
|
+
function formatOperationSpecifics(op: Operation, unit: Unit | null | undefined): string {
|
|
13
10
|
const {
|
|
14
11
|
validators,
|
|
15
12
|
bondedAmount,
|
|
@@ -27,15 +24,11 @@ function formatOperationSpecifics(
|
|
|
27
24
|
str +=
|
|
28
25
|
bondedAmount && !bondedAmount.isNaN()
|
|
29
26
|
? `\n bondedAmount: ${
|
|
30
|
-
unit
|
|
31
|
-
? formatCurrencyUnit(unit, bondedAmount, formatConfig)
|
|
32
|
-
: bondedAmount
|
|
27
|
+
unit ? formatCurrencyUnit(unit, bondedAmount, formatConfig) : bondedAmount
|
|
33
28
|
}`
|
|
34
29
|
: unbondedAmount && !unbondedAmount.isNaN()
|
|
35
30
|
? `\n unbondedAmount: ${
|
|
36
|
-
unit
|
|
37
|
-
? formatCurrencyUnit(unit, unbondedAmount, formatConfig)
|
|
38
|
-
: unbondedAmount
|
|
31
|
+
unit ? formatCurrencyUnit(unit, unbondedAmount, formatConfig) : unbondedAmount
|
|
39
32
|
}`
|
|
40
33
|
: withdrawUnbondedAmount && !withdrawUnbondedAmount.isNaN()
|
|
41
34
|
? `\n withdrawUnbondedAmount: ${
|
|
@@ -46,9 +39,7 @@ function formatOperationSpecifics(
|
|
|
46
39
|
: "";
|
|
47
40
|
str += validatorStash ? `\n validatorStash: ${validatorStash}` : "";
|
|
48
41
|
str += amount
|
|
49
|
-
? `\n amount: ${
|
|
50
|
-
unit ? formatCurrencyUnit(unit, amount, formatConfig) : amount
|
|
51
|
-
}`
|
|
42
|
+
? `\n amount: ${unit ? formatCurrencyUnit(unit, amount, formatConfig) : amount}`
|
|
52
43
|
: "";
|
|
53
44
|
return str;
|
|
54
45
|
}
|
|
@@ -63,23 +54,15 @@ function formatAccountSpecifics(account: PolkadotAccount): string {
|
|
|
63
54
|
showCode: true,
|
|
64
55
|
};
|
|
65
56
|
let str = " ";
|
|
66
|
-
str +=
|
|
67
|
-
formatCurrencyUnit(unit, account.spendableBalance, formatConfig) +
|
|
68
|
-
" spendable. ";
|
|
57
|
+
str += formatCurrencyUnit(unit, account.spendableBalance, formatConfig) + " spendable. ";
|
|
69
58
|
|
|
70
59
|
if (polkadotResources.lockedBalance.gt(0)) {
|
|
71
|
-
str +=
|
|
72
|
-
formatCurrencyUnit(unit, polkadotResources.lockedBalance, formatConfig) +
|
|
73
|
-
" locked. ";
|
|
60
|
+
str += formatCurrencyUnit(unit, polkadotResources.lockedBalance, formatConfig) + " locked. ";
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
if (polkadotResources.unlockedBalance.gt(0)) {
|
|
77
64
|
str +=
|
|
78
|
-
formatCurrencyUnit(
|
|
79
|
-
unit,
|
|
80
|
-
polkadotResources.unlockedBalance,
|
|
81
|
-
formatConfig
|
|
82
|
-
) + " unlocked. ";
|
|
65
|
+
formatCurrencyUnit(unit, polkadotResources.unlockedBalance, formatConfig) + " unlocked. ";
|
|
83
66
|
}
|
|
84
67
|
|
|
85
68
|
if (polkadotResources.stash) {
|
|
@@ -92,17 +75,13 @@ function formatAccountSpecifics(account: PolkadotAccount): string {
|
|
|
92
75
|
|
|
93
76
|
if (polkadotResources.nominations?.length) {
|
|
94
77
|
str += "\nNominations\n";
|
|
95
|
-
str += (polkadotResources.nominations as any[])
|
|
96
|
-
.map((v) => ` to ${v.address}`)
|
|
97
|
-
.join("\n");
|
|
78
|
+
str += (polkadotResources.nominations as any[]).map(v => ` to ${v.address}`).join("\n");
|
|
98
79
|
}
|
|
99
80
|
|
|
100
81
|
return str;
|
|
101
82
|
}
|
|
102
83
|
|
|
103
|
-
export function fromOperationExtraRaw(
|
|
104
|
-
extra: Record<string, any> | null | undefined
|
|
105
|
-
) {
|
|
84
|
+
export function fromOperationExtraRaw(extra: Record<string, any> | null | undefined) {
|
|
106
85
|
if (extra && extra.transferAmount) {
|
|
107
86
|
extra = { ...extra, transferAmount: extra.transferAmount.toString() };
|
|
108
87
|
}
|
|
@@ -129,9 +108,7 @@ export function fromOperationExtraRaw(
|
|
|
129
108
|
|
|
130
109
|
return extra;
|
|
131
110
|
}
|
|
132
|
-
export function toOperationExtraRaw(
|
|
133
|
-
extra: Record<string, any> | null | undefined
|
|
134
|
-
) {
|
|
111
|
+
export function toOperationExtraRaw(extra: Record<string, any> | null | undefined) {
|
|
135
112
|
if (extra && extra.transferAmount) {
|
|
136
113
|
extra = { ...extra, transferAmount: extra.transferAmount.toString() };
|
|
137
114
|
}
|
package/src/address.ts
CHANGED
|
@@ -11,16 +11,12 @@ const POLKADOT_SS58_PREFIX = 0;
|
|
|
11
11
|
// TODO Cache this to improve perf
|
|
12
12
|
export const isValidAddress = (
|
|
13
13
|
address: string,
|
|
14
|
-
ss58Format: number = POLKADOT_SS58_PREFIX
|
|
14
|
+
ss58Format: number = POLKADOT_SS58_PREFIX,
|
|
15
15
|
): boolean => {
|
|
16
16
|
if (!address) return false;
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
-
encodeAddress(
|
|
20
|
-
isHex(address)
|
|
21
|
-
? hexToU8a(address)
|
|
22
|
-
: decodeAddress(address, false, ss58Format)
|
|
23
|
-
);
|
|
19
|
+
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address, false, ss58Format));
|
|
24
20
|
return true;
|
|
25
21
|
} catch (err) {
|
|
26
22
|
return false;
|
package/src/api/bisontrails.ts
CHANGED
|
@@ -30,7 +30,7 @@ const getAccountOperationUrl = (
|
|
|
30
30
|
addr: string,
|
|
31
31
|
offset: number,
|
|
32
32
|
startAt: number,
|
|
33
|
-
limit: number = LIMIT
|
|
33
|
+
limit: number = LIMIT,
|
|
34
34
|
): string =>
|
|
35
35
|
`${getBaseApiUrl()}/accounts/${addr}/operations?${querystring.stringify({
|
|
36
36
|
limit,
|
|
@@ -41,9 +41,7 @@ const getAccountOperationUrl = (
|
|
|
41
41
|
const getWithdrawUnbondedAmount = (extrinsic: any) => {
|
|
42
42
|
return (
|
|
43
43
|
extrinsic?.staking?.eventStaking.reduce((acc: any, curr: any) => {
|
|
44
|
-
return curr.method === "Withdrawn"
|
|
45
|
-
? new BigNumber(acc).plus(curr.value)
|
|
46
|
-
: new BigNumber(0);
|
|
44
|
+
return curr.method === "Withdrawn" ? new BigNumber(acc).plus(curr.value) : new BigNumber(0);
|
|
47
45
|
}, new BigNumber(0)) || new BigNumber(0)
|
|
48
46
|
);
|
|
49
47
|
};
|
|
@@ -146,9 +144,7 @@ const getExtra = (type: OperationType, extrinsic: any): Record<string, any> => {
|
|
|
146
144
|
*/
|
|
147
145
|
const getValue = (extrinsic: any, type: OperationType): BigNumber => {
|
|
148
146
|
if (!extrinsic.isSuccess) {
|
|
149
|
-
return type === "IN"
|
|
150
|
-
? new BigNumber(0)
|
|
151
|
-
: new BigNumber(extrinsic.partialFee || 0);
|
|
147
|
+
return type === "IN" ? new BigNumber(0) : new BigNumber(extrinsic.partialFee || 0);
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
switch (type) {
|
|
@@ -178,15 +174,11 @@ const getValue = (extrinsic: any, type: OperationType): BigNumber => {
|
|
|
178
174
|
const extrinsicToOperation = (
|
|
179
175
|
addr: string,
|
|
180
176
|
accountId: string,
|
|
181
|
-
extrinsic: any
|
|
177
|
+
extrinsic: any,
|
|
182
178
|
): Partial<Operation> | null => {
|
|
183
179
|
let type = getOperationType(extrinsic.section, extrinsic.method);
|
|
184
180
|
|
|
185
|
-
if (
|
|
186
|
-
type === "OUT" &&
|
|
187
|
-
extrinsic.affectedAddress1 === addr &&
|
|
188
|
-
extrinsic.signer !== addr
|
|
189
|
-
) {
|
|
181
|
+
if (type === "OUT" && extrinsic.affectedAddress1 === addr && extrinsic.signer !== addr) {
|
|
190
182
|
type = "IN";
|
|
191
183
|
}
|
|
192
184
|
|
|
@@ -208,8 +200,7 @@ const extrinsicToOperation = (
|
|
|
208
200
|
recipients: [extrinsic.affectedAddress1, extrinsic.affectedAddress2]
|
|
209
201
|
.filter(Boolean)
|
|
210
202
|
.filter(isValidAddress),
|
|
211
|
-
transactionSequenceNumber:
|
|
212
|
-
extrinsic.signer === addr ? extrinsic.nonce : undefined,
|
|
203
|
+
transactionSequenceNumber: extrinsic.signer === addr ? extrinsic.nonce : undefined,
|
|
213
204
|
hasFailed: !extrinsic.isSuccess,
|
|
214
205
|
};
|
|
215
206
|
};
|
|
@@ -223,11 +214,7 @@ const extrinsicToOperation = (
|
|
|
223
214
|
*
|
|
224
215
|
* @returns {Operation | null}
|
|
225
216
|
*/
|
|
226
|
-
const rewardToOperation = (
|
|
227
|
-
addr: string,
|
|
228
|
-
accountId: string,
|
|
229
|
-
reward: any
|
|
230
|
-
): Partial<Operation> => {
|
|
217
|
+
const rewardToOperation = (addr: string, accountId: string, reward: any): Partial<Operation> => {
|
|
231
218
|
const hash = reward.extrinsicHash;
|
|
232
219
|
const type = "REWARD_PAYOUT";
|
|
233
220
|
return {
|
|
@@ -254,11 +241,7 @@ const rewardToOperation = (
|
|
|
254
241
|
*
|
|
255
242
|
* @returns {Operation | null}
|
|
256
243
|
*/
|
|
257
|
-
const slashToOperation = (
|
|
258
|
-
addr: string,
|
|
259
|
-
accountId: string,
|
|
260
|
-
slash: any
|
|
261
|
-
): Partial<Operation> => {
|
|
244
|
+
const slashToOperation = (addr: string, accountId: string, slash: any): Partial<Operation> => {
|
|
262
245
|
const hash = `${slash.blockNumber}`;
|
|
263
246
|
const type = "SLASH";
|
|
264
247
|
return {
|
|
@@ -293,38 +276,24 @@ const fetchOperationList =
|
|
|
293
276
|
addr: string,
|
|
294
277
|
startAt: number,
|
|
295
278
|
offset = 0,
|
|
296
|
-
prevOperations: Operation[] = []
|
|
279
|
+
prevOperations: Operation[] = [],
|
|
297
280
|
): Promise<Operation[]> => {
|
|
298
281
|
const { data } = await network({
|
|
299
282
|
method: "GET",
|
|
300
283
|
url: getAccountOperationUrl(addr, offset, startAt),
|
|
301
284
|
});
|
|
302
285
|
const operations = data.extrinsics.map((extrinsic: any) =>
|
|
303
|
-
extrinsicToOperation(addr, accountId, extrinsic)
|
|
304
|
-
);
|
|
305
|
-
const rewards = data.rewards.map((reward: any) =>
|
|
306
|
-
rewardToOperation(addr, accountId, reward)
|
|
307
|
-
);
|
|
308
|
-
const slashes = data.slashes.map((slash: any) =>
|
|
309
|
-
slashToOperation(addr, accountId, slash)
|
|
286
|
+
extrinsicToOperation(addr, accountId, extrinsic),
|
|
310
287
|
);
|
|
288
|
+
const rewards = data.rewards.map((reward: any) => rewardToOperation(addr, accountId, reward));
|
|
289
|
+
const slashes = data.slashes.map((slash: any) => slashToOperation(addr, accountId, slash));
|
|
311
290
|
const mergedOp = [...prevOperations, ...operations, ...rewards, ...slashes];
|
|
312
291
|
|
|
313
|
-
if (
|
|
314
|
-
operations.length < LIMIT &&
|
|
315
|
-
rewards.length < LIMIT &&
|
|
316
|
-
slashes.length < LIMIT
|
|
317
|
-
) {
|
|
292
|
+
if (operations.length < LIMIT && rewards.length < LIMIT && slashes.length < LIMIT) {
|
|
318
293
|
return mergedOp.filter(Boolean).sort((a, b) => b.date - a.date);
|
|
319
294
|
}
|
|
320
295
|
|
|
321
|
-
return await fetchOperationList(network)(
|
|
322
|
-
accountId,
|
|
323
|
-
addr,
|
|
324
|
-
startAt,
|
|
325
|
-
offset + LIMIT,
|
|
326
|
-
mergedOp
|
|
327
|
-
);
|
|
296
|
+
return await fetchOperationList(network)(accountId, addr, startAt, offset + LIMIT, mergedOp);
|
|
328
297
|
};
|
|
329
298
|
|
|
330
299
|
/**
|
package/src/api/common.ts
CHANGED
|
@@ -10,10 +10,7 @@ import type { OperationType } from "@ledgerhq/types-live";
|
|
|
10
10
|
*
|
|
11
11
|
* @returns {string} - OperationType
|
|
12
12
|
*/
|
|
13
|
-
export const getOperationType = (
|
|
14
|
-
pallet: string,
|
|
15
|
-
palletMethod: string
|
|
16
|
-
): OperationType => {
|
|
13
|
+
export const getOperationType = (pallet: string, palletMethod: string): OperationType => {
|
|
17
14
|
switch (palletMethod) {
|
|
18
15
|
case "transfer":
|
|
19
16
|
case "transferKeepAlive":
|
|
@@ -43,10 +40,7 @@ export const getOperationType = (
|
|
|
43
40
|
return "FEES";
|
|
44
41
|
|
|
45
42
|
default:
|
|
46
|
-
log(
|
|
47
|
-
"polkadot/api",
|
|
48
|
-
`Unknown operation type ${pallet}.${palletMethod} - fallback to FEES`
|
|
49
|
-
);
|
|
43
|
+
log("polkadot/api", `Unknown operation type ${pallet}.${palletMethod} - fallback to FEES`);
|
|
50
44
|
return "FEES";
|
|
51
45
|
}
|
|
52
46
|
};
|
package/src/api/index.ts
CHANGED
|
@@ -91,9 +91,7 @@ export class PolkadotAPI {
|
|
|
91
91
|
|
|
92
92
|
private getMinimumBondBalanceFn: CacheRes<Array<void>, BigNumber> | undefined;
|
|
93
93
|
private getRegistryFn: CacheRes<Array<void>, Registry> | undefined;
|
|
94
|
-
private getTransactionParamsFn:
|
|
95
|
-
| CacheRes<Array<void>, Record<string, any>>
|
|
96
|
-
| undefined;
|
|
94
|
+
private getTransactionParamsFn: CacheRes<Array<void>, Record<string, any>> | undefined;
|
|
97
95
|
private isControllerAddressFn: CacheRes<Array<string>, boolean> | undefined;
|
|
98
96
|
private isElectionClosedFn: CacheRes<Array<void>, boolean> | undefined;
|
|
99
97
|
private isNewAccountFn: CacheRes<Array<string>, boolean> | undefined;
|
|
@@ -110,26 +108,20 @@ export class PolkadotAPI {
|
|
|
110
108
|
return sidecardGetAccount(this.network, this.cache)(address);
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
async getOperations(
|
|
114
|
-
accountId: string,
|
|
115
|
-
addr: string,
|
|
116
|
-
startA = 0
|
|
117
|
-
): Promise<Operation[]> {
|
|
111
|
+
async getOperations(accountId: string, addr: string, startA = 0): Promise<Operation[]> {
|
|
118
112
|
return bisonGetOperations(this.network)(accountId, addr, startA);
|
|
119
113
|
}
|
|
120
114
|
|
|
121
115
|
async getMinimumBondBalance(): Promise<BigNumber> {
|
|
122
|
-
if (this.getMinimumBondBalanceFn !== undefined)
|
|
123
|
-
return this.getMinimumBondBalanceFn();
|
|
116
|
+
if (this.getMinimumBondBalanceFn !== undefined) return this.getMinimumBondBalanceFn();
|
|
124
117
|
|
|
125
118
|
this.getMinimumBondBalanceFn = this.cache(
|
|
126
|
-
async (): Promise<BigNumber> =>
|
|
127
|
-
sidecarGetMinimumBondBalance(this.network)(),
|
|
119
|
+
async (): Promise<BigNumber> => sidecarGetMinimumBondBalance(this.network)(),
|
|
128
120
|
() => "polkadot",
|
|
129
121
|
{
|
|
130
122
|
max: 1, // Store only one object since we only have polkadot.
|
|
131
123
|
ttl: 60 * 60 * 1000, // 1 hour
|
|
132
|
-
}
|
|
124
|
+
},
|
|
133
125
|
);
|
|
134
126
|
|
|
135
127
|
return this.getMinimumBondBalanceFn();
|
|
@@ -145,7 +137,7 @@ export class PolkadotAPI {
|
|
|
145
137
|
() => "polkadot",
|
|
146
138
|
{
|
|
147
139
|
ttl: 60 * 60 * 1000, // 1 hour - could be Infinity
|
|
148
|
-
}
|
|
140
|
+
},
|
|
149
141
|
);
|
|
150
142
|
|
|
151
143
|
return this.getRegistryFn();
|
|
@@ -156,37 +148,30 @@ export class PolkadotAPI {
|
|
|
156
148
|
}
|
|
157
149
|
|
|
158
150
|
async getValidators(
|
|
159
|
-
stashes:
|
|
160
|
-
| SidecarValidatorsParamStatus
|
|
161
|
-
| SidecarValidatorsParamAddresses = "elected"
|
|
151
|
+
stashes: SidecarValidatorsParamStatus | SidecarValidatorsParamAddresses = "elected",
|
|
162
152
|
): Promise<PolkadotValidator[]> {
|
|
163
153
|
return sidecarGetValidators(this.network)(stashes);
|
|
164
154
|
}
|
|
165
155
|
|
|
166
156
|
async getTransactionParams(
|
|
167
|
-
{ force }: CacheOpts = { force: false }
|
|
157
|
+
{ force }: CacheOpts = { force: false },
|
|
168
158
|
): Promise<Record<string, any>> {
|
|
169
159
|
if (this.getTransactionParamsFn !== undefined) {
|
|
170
|
-
return force
|
|
171
|
-
? this.getTransactionParamsFn.force()
|
|
172
|
-
: this.getTransactionParamsFn();
|
|
160
|
+
return force ? this.getTransactionParamsFn.force() : this.getTransactionParamsFn();
|
|
173
161
|
}
|
|
174
162
|
|
|
175
163
|
this.getTransactionParamsFn = this.cache(
|
|
176
|
-
async (): Promise<Record<string, any>> =>
|
|
177
|
-
sidecarGetTransactionParams(this.network)(),
|
|
164
|
+
async (): Promise<Record<string, any>> => sidecarGetTransactionParams(this.network)(),
|
|
178
165
|
() => "polkadot",
|
|
179
166
|
{
|
|
180
167
|
ttl: 5 * 60 * 1000, // 5 minutes
|
|
181
|
-
}
|
|
168
|
+
},
|
|
182
169
|
);
|
|
183
170
|
|
|
184
171
|
return this.getTransactionParamsFn();
|
|
185
172
|
}
|
|
186
173
|
|
|
187
|
-
async getPaymentInfo(
|
|
188
|
-
data: PaymentInfoParams
|
|
189
|
-
): Promise<Pick<SidecarPaymentInfo, "partialFee">> {
|
|
174
|
+
async getPaymentInfo(data: PaymentInfoParams): Promise<Pick<SidecarPaymentInfo, "partialFee">> {
|
|
190
175
|
if (this.paymentInfoFn !== undefined) return this.paymentInfoFn(data);
|
|
191
176
|
|
|
192
177
|
this.paymentInfoFn = this.cache(
|
|
@@ -200,23 +185,21 @@ export class PolkadotAPI {
|
|
|
200
185
|
({ a, t, signedTx }) => hashTransactionParams(a, t, signedTx),
|
|
201
186
|
{
|
|
202
187
|
ttl: 5 * 60 * 1000, // 5 minutes
|
|
203
|
-
}
|
|
188
|
+
},
|
|
204
189
|
);
|
|
205
190
|
|
|
206
191
|
return this.paymentInfoFn(data);
|
|
207
192
|
}
|
|
208
193
|
|
|
209
194
|
async isControllerAddress(address: string): Promise<boolean> {
|
|
210
|
-
if (this.isControllerAddressFn !== undefined)
|
|
211
|
-
return this.isControllerAddressFn(address);
|
|
195
|
+
if (this.isControllerAddressFn !== undefined) return this.isControllerAddressFn(address);
|
|
212
196
|
|
|
213
197
|
this.isControllerAddressFn = this.cache(
|
|
214
|
-
async (address): Promise<boolean> =>
|
|
215
|
-
|
|
216
|
-
(address) => address,
|
|
198
|
+
async (address): Promise<boolean> => sidecarIsControllerAddress(this.network)(address),
|
|
199
|
+
address => address,
|
|
217
200
|
{
|
|
218
201
|
ttl: 5 * 60 * 1000, // 5 minutes
|
|
219
|
-
}
|
|
202
|
+
},
|
|
220
203
|
);
|
|
221
204
|
|
|
222
205
|
return this.isControllerAddressFn(address);
|
|
@@ -230,7 +213,7 @@ export class PolkadotAPI {
|
|
|
230
213
|
() => "",
|
|
231
214
|
{
|
|
232
215
|
ttl: 60 * 1000, // 1 minute
|
|
233
|
-
}
|
|
216
|
+
},
|
|
234
217
|
);
|
|
235
218
|
|
|
236
219
|
return this.isElectionClosedFn();
|
|
@@ -240,12 +223,11 @@ export class PolkadotAPI {
|
|
|
240
223
|
if (this.isNewAccountFn !== undefined) return this.isNewAccountFn(address);
|
|
241
224
|
|
|
242
225
|
this.isNewAccountFn = this.cache(
|
|
243
|
-
async (address): Promise<boolean> =>
|
|
244
|
-
|
|
245
|
-
(address) => address,
|
|
226
|
+
async (address): Promise<boolean> => sidecarIsNewAccount(this.network)(address),
|
|
227
|
+
address => address,
|
|
246
228
|
{
|
|
247
229
|
ttl: 60 * 1000, // 1 minute
|
|
248
|
-
}
|
|
230
|
+
},
|
|
249
231
|
);
|
|
250
232
|
|
|
251
233
|
return this.isNewAccountFn(address);
|
|
@@ -268,11 +250,7 @@ export class PolkadotAPI {
|
|
|
268
250
|
*
|
|
269
251
|
* @returns {string} hash
|
|
270
252
|
*/
|
|
271
|
-
const hashTransactionParams = (
|
|
272
|
-
a: PolkadotAccount,
|
|
273
|
-
t: Transaction,
|
|
274
|
-
signedTx: string
|
|
275
|
-
) => {
|
|
253
|
+
const hashTransactionParams = (a: PolkadotAccount, t: Transaction, signedTx: string) => {
|
|
276
254
|
// Nonce is added to discard previous estimation when account is synced.
|
|
277
255
|
const prefix = `${a.id}_${a.polkadotResources?.nonce || 0}_${t.mode}`;
|
|
278
256
|
// Fees depends on extrinsic bytesize
|