Skip to content

Commit 677cbd3

Browse files
authored
Fix derive.balances.account detection for system vs balances (#5373)
* Fix derive.balances.account detection for system vs balances * Adjust balances.all * 9.10.2
1 parent f95edc5 commit 677cbd3

File tree

20 files changed

+176
-168
lines changed

20 files changed

+176
-168
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 9.10.2 Dec 9, 2022
4+
5+
Changes:
6+
7+
- Fix `derive.balances.account` detection for system vs balances
8+
9+
310
## 9.10.1 Dec 4, 2022
411

512
- **Important** Since [9.2.1](https://github.com/polkadot-js/api/releases/tag/v9.2.1) the recommended way of accessing `WellKnownChain` for light clients is via `ScProvider.WellKnownChain`. This release removes the explicit export from the `ScProvider` root.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"sideEffects": false,
1313
"type": "module",
14-
"version": "9.10.2-3-x",
14+
"version": "9.10.2",
1515
"versions": {
1616
"git": "9.10.2-3-x",
1717
"npm": "9.10.1"

packages/api-augment/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/api-base": "9.10.2-3-x",
28-
"@polkadot/rpc-augment": "9.10.2-3-x",
29-
"@polkadot/types": "9.10.2-3-x",
30-
"@polkadot/types-augment": "9.10.2-3-x",
31-
"@polkadot/types-codec": "9.10.2-3-x",
27+
"@polkadot/api-base": "9.10.2",
28+
"@polkadot/rpc-augment": "9.10.2",
29+
"@polkadot/types": "9.10.2",
30+
"@polkadot/types-augment": "9.10.2",
31+
"@polkadot/types-codec": "9.10.2",
3232
"@polkadot/util": "^10.2.1"
3333
},
3434
"devDependencies": {
35-
"@polkadot/types-support": "9.10.2-3-x"
35+
"@polkadot/types-support": "9.10.2"
3636
}
3737
}

packages/api-base/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/rpc-core": "9.10.2-3-x",
28-
"@polkadot/types": "9.10.2-3-x",
27+
"@polkadot/rpc-core": "9.10.2",
28+
"@polkadot/types": "9.10.2",
2929
"@polkadot/util": "^10.2.1",
3030
"rxjs": "^7.6.0"
3131
}

packages/api-contract/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/api": "9.10.2-3-x",
28-
"@polkadot/types": "9.10.2-3-x",
29-
"@polkadot/types-codec": "9.10.2-3-x",
30-
"@polkadot/types-create": "9.10.2-3-x",
27+
"@polkadot/api": "9.10.2",
28+
"@polkadot/types": "9.10.2",
29+
"@polkadot/types-codec": "9.10.2",
30+
"@polkadot/types-create": "9.10.2",
3131
"@polkadot/util": "^10.2.1",
3232
"@polkadot/util-crypto": "^10.2.1",
3333
"rxjs": "^7.6.0"
3434
},
3535
"devDependencies": {
36-
"@polkadot/api-augment": "9.10.2-3-x",
36+
"@polkadot/api-augment": "9.10.2",
3737
"@polkadot/keyring": "^10.2.1"
3838
}
3939
}

packages/api-derive/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/api": "9.10.2-3-x",
28-
"@polkadot/api-augment": "9.10.2-3-x",
29-
"@polkadot/api-base": "9.10.2-3-x",
30-
"@polkadot/rpc-core": "9.10.2-3-x",
31-
"@polkadot/types": "9.10.2-3-x",
32-
"@polkadot/types-codec": "9.10.2-3-x",
27+
"@polkadot/api": "9.10.2",
28+
"@polkadot/api-augment": "9.10.2",
29+
"@polkadot/api-base": "9.10.2",
30+
"@polkadot/rpc-core": "9.10.2",
31+
"@polkadot/types": "9.10.2",
32+
"@polkadot/types-codec": "9.10.2",
3333
"@polkadot/util": "^10.2.1",
3434
"@polkadot/util-crypto": "^10.2.1",
3535
"rxjs": "^7.6.0"
3636
},
3737
"devDependencies": {
38-
"@polkadot/api": "9.10.2-3-x",
39-
"@polkadot/api-augment": "9.10.2-3-x",
40-
"@polkadot/rpc-augment": "9.10.2-3-x",
41-
"@polkadot/rpc-provider": "9.10.2-3-x",
42-
"@polkadot/types-support": "9.10.2-3-x"
38+
"@polkadot/api": "9.10.2",
39+
"@polkadot/api-augment": "9.10.2",
40+
"@polkadot/rpc-augment": "9.10.2",
41+
"@polkadot/rpc-provider": "9.10.2",
42+
"@polkadot/types-support": "9.10.2"
4343
}
4444
}

packages/api-derive/src/balances/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
150150
*/
151151
export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
152152
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName, 'balances');
153-
const nonDefaultBalances = balanceInstances && (balanceInstances.length !== 1 || balanceInstances[0] !== 'balances');
153+
const nonDefaultBalances = balanceInstances && balanceInstances[0] !== 'balances';
154154

155155
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
156156
api.derive.accounts.accountId(address).pipe(

packages/api-derive/src/balances/all.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalanc
5858
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
5959

6060
return objectSpread({}, data, {
61-
availableBalance: api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data.freeBalance.sub(lockedBalance))),
61+
availableBalance: api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data?.freeBalance ? data.freeBalance.sub(lockedBalance) : new BN(0))),
6262
lockedBalance,
6363
lockedBreakdown,
6464
vestingLocked
@@ -98,7 +98,8 @@ function calcVesting (bestNumber: BlockNumber, shared: DeriveBalancesAllAccountD
9898
};
9999
}
100100

101-
function calcBalances (api: DeriveApi, [data, [vesting, allLocks, namedReserves], bestNumber]: Result): DeriveBalancesAll {
101+
function calcBalances (api: DeriveApi, result: Result): DeriveBalancesAll {
102+
const [data, [vesting, allLocks, namedReserves], bestNumber] = result;
102103
const shared = calcShared(api, bestNumber, data, allLocks[0]);
103104

104105
return objectSpread(shared, calcVesting(bestNumber, shared, vesting), {

packages/api/package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/api-augment": "9.10.2-3-x",
28-
"@polkadot/api-base": "9.10.2-3-x",
29-
"@polkadot/api-derive": "9.10.2-3-x",
27+
"@polkadot/api-augment": "9.10.2",
28+
"@polkadot/api-base": "9.10.2",
29+
"@polkadot/api-derive": "9.10.2",
3030
"@polkadot/keyring": "^10.2.1",
31-
"@polkadot/rpc-augment": "9.10.2-3-x",
32-
"@polkadot/rpc-core": "9.10.2-3-x",
33-
"@polkadot/rpc-provider": "9.10.2-3-x",
34-
"@polkadot/types": "9.10.2-3-x",
35-
"@polkadot/types-augment": "9.10.2-3-x",
36-
"@polkadot/types-codec": "9.10.2-3-x",
37-
"@polkadot/types-create": "9.10.2-3-x",
38-
"@polkadot/types-known": "9.10.2-3-x",
31+
"@polkadot/rpc-augment": "9.10.2",
32+
"@polkadot/rpc-core": "9.10.2",
33+
"@polkadot/rpc-provider": "9.10.2",
34+
"@polkadot/types": "9.10.2",
35+
"@polkadot/types-augment": "9.10.2",
36+
"@polkadot/types-codec": "9.10.2",
37+
"@polkadot/types-create": "9.10.2",
38+
"@polkadot/types-known": "9.10.2",
3939
"@polkadot/util": "^10.2.1",
4040
"@polkadot/util-crypto": "^10.2.1",
4141
"eventemitter3": "^4.0.7",
4242
"rxjs": "^7.6.0"
4343
},
4444
"devDependencies": {
45-
"@polkadot/api-augment": "9.10.2-3-x",
46-
"@polkadot/types-support": "9.10.2-3-x"
45+
"@polkadot/api-augment": "9.10.2",
46+
"@polkadot/types-support": "9.10.2"
4747
}
4848
}

packages/rpc-augment/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"./detectPackage.cjs"
2121
],
2222
"type": "module",
23-
"version": "9.10.2-3-x",
23+
"version": "9.10.2",
2424
"main": "index.js",
2525
"dependencies": {
2626
"@babel/runtime": "^7.20.6",
27-
"@polkadot/rpc-core": "9.10.2-3-x",
28-
"@polkadot/types": "9.10.2-3-x",
29-
"@polkadot/types-codec": "9.10.2-3-x",
27+
"@polkadot/rpc-core": "9.10.2",
28+
"@polkadot/types": "9.10.2",
29+
"@polkadot/types-codec": "9.10.2",
3030
"@polkadot/util": "^10.2.1"
3131
}
3232
}

0 commit comments

Comments
 (0)