@subwallet/extension-base 1.2.26-0 → 1.2.27-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.
@@ -3,33 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports._getAssetsPalletLockedBalance = _getAssetsPalletLockedBalance;
6
+ exports._getAssetsPalletLocked = _getAssetsPalletLocked;
7
+ exports._getAssetsPalletLockedWithStatus = _getAssetsPalletLockedWithStatus;
8
+ exports._getAssetsPalletLockedWithoutStatus = _getAssetsPalletLockedWithoutStatus;
7
9
  exports._getAssetsPalletTransferable = _getAssetsPalletTransferable;
10
+ exports._getAssetsPalletTransferableWithStatus = _getAssetsPalletTransferableWithStatus;
11
+ exports._getAssetsPalletTransferableWithoutStatus = _getAssetsPalletTransferableWithoutStatus;
8
12
  var _types = require("@subwallet/extension-base/core/substrate/types");
9
13
  var _utils = require("@subwallet/extension-base/core/utils");
10
14
  // Copyright 2019-2022 @subwallet/extension-base
11
15
  // SPDX-License-Identifier: Apache-2.0
12
16
 
17
+ function isWithStatus(accountInfo) {
18
+ return accountInfo.status !== undefined && accountInfo.isFrozen === undefined;
19
+ }
13
20
  function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
21
  const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
15
- const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
16
- let bnTransferable = BigInt(0);
17
- if (!accountInfo) {
18
- return BigInt(0);
19
- }
20
- if (['Liquid'].includes(accountInfo.status)) {
21
- bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
22
+ if (isWithStatus(accountInfo)) {
23
+ return _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode);
24
+ } else {
25
+ return _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode);
22
26
  }
23
- return bnTransferable;
24
27
  }
25
- function _getAssetsPalletLockedBalance(accountInfo) {
26
- let bnLocked = BigInt(0);
27
- if (!accountInfo) {
28
- return bnLocked;
28
+ function _getAssetsPalletLocked(accountInfo) {
29
+ if (isWithStatus(accountInfo)) {
30
+ return _getAssetsPalletLockedWithStatus(accountInfo);
31
+ } else {
32
+ return _getAssetsPalletLockedWithoutStatus(accountInfo);
29
33
  }
30
- if (!['Liquid'].includes(accountInfo.status)) {
31
- // todo: check case accountInfo has isFrozen?
32
- bnLocked = BigInt(accountInfo.balance);
33
- }
34
- return bnLocked;
34
+ }
35
+
36
+ // ----------------------------------------------------------------------
37
+
38
+ function _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode) {
39
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
40
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
41
+ }
42
+ function _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode) {
43
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
44
+ return !accountInfo.isFrozen ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
45
+ }
46
+ function _getAssetsPalletLockedWithStatus(accountInfo) {
47
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
48
+ }
49
+ function _getAssetsPalletLockedWithoutStatus(accountInfo) {
50
+ return accountInfo.isFrozen ? BigInt(accountInfo.balance) : BigInt(0);
35
51
  }
@@ -12,15 +12,8 @@ var _utils = require("@subwallet/extension-base/core/utils");
12
12
 
13
13
  function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
14
  const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
15
- if (!accountInfo || accountInfo.status !== 'Liquid') {
16
- return BigInt(0);
17
- }
18
- const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
19
- return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
15
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode) : BigInt(0);
20
16
  }
21
17
  function _getForeignAssetPalletLockedBalance(accountInfo) {
22
- if (!accountInfo || accountInfo.status === 'Liquid') {
23
- return BigInt(0);
24
- }
25
- return BigInt(accountInfo.balance);
18
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
26
19
  }
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.2.26-0'
16
+ version: '1.2.27-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -191,6 +191,16 @@ const subscribeForeignAssetBalance = async _ref2 => {
191
191
  const balances = rs[foreignAssetsAccountKey];
192
192
  const items = balances.map((_balance, index) => {
193
193
  const balanceInfo = _balance;
194
+ if (!balanceInfo) {
195
+ // no balance info response
196
+ return {
197
+ address: addresses[index],
198
+ tokenSlug: tokenInfo.slug,
199
+ free: '0',
200
+ locked: '0',
201
+ state: _KoniTypes.APIItemState.READY
202
+ };
203
+ }
194
204
  const transferableBalance = (0, _foreignAssetPallet._getForeignAssetPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
195
205
  const totalLockedFromTransfer = (0, _foreignAssetPallet._getForeignAssetPalletLockedBalance)(balanceInfo);
196
206
  return {
@@ -365,8 +375,18 @@ const subscribeAssetsAccountPallet = async _ref6 => {
365
375
  const balances = rs[assetsAccountKey];
366
376
  const items = balances.map((_balance, index) => {
367
377
  const balanceInfo = _balance;
378
+ if (!balanceInfo) {
379
+ // no balance info response
380
+ return {
381
+ address: addresses[index],
382
+ tokenSlug: tokenInfo.slug,
383
+ free: '0',
384
+ locked: '0',
385
+ state: _KoniTypes.APIItemState.READY
386
+ };
387
+ }
368
388
  const transferableBalance = (0, _assetsPallet._getAssetsPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
369
- const totalLockedFromTransfer = (0, _assetsPallet._getAssetsPalletLockedBalance)(balanceInfo);
389
+ const totalLockedFromTransfer = (0, _assetsPallet._getAssetsPalletLocked)(balanceInfo);
370
390
  return {
371
391
  address: addresses[index],
372
392
  tokenSlug: tokenInfo.slug,
@@ -1,4 +1,8 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
- export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
- export declare function _getAssetsPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
2
+ import { PalletAssetsAssetAccount, PalletAssetsAssetAccountWithoutStatus, PalletAssetsAssetAccountWithStatus } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getAssetsPalletLocked(accountInfo: PalletAssetsAssetAccount): bigint;
5
+ export declare function _getAssetsPalletTransferableWithStatus(accountInfo: PalletAssetsAssetAccountWithStatus, existentialDeposit: string, strictMode?: boolean): bigint;
6
+ export declare function _getAssetsPalletTransferableWithoutStatus(accountInfo: PalletAssetsAssetAccountWithoutStatus, existentialDeposit: string, strictMode?: boolean): bigint;
7
+ export declare function _getAssetsPalletLockedWithStatus(accountInfo: PalletAssetsAssetAccountWithStatus): bigint;
8
+ export declare function _getAssetsPalletLockedWithoutStatus(accountInfo: PalletAssetsAssetAccountWithoutStatus): bigint;
@@ -3,26 +3,38 @@
3
3
 
4
4
  import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
5
  import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ function isWithStatus(accountInfo) {
7
+ return accountInfo.status !== undefined && accountInfo.isFrozen === undefined;
8
+ }
6
9
  export function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
10
  const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
- const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
9
- let bnTransferable = BigInt(0);
10
- if (!accountInfo) {
11
- return BigInt(0);
12
- }
13
- if (['Liquid'].includes(accountInfo.status)) {
14
- bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
11
+ if (isWithStatus(accountInfo)) {
12
+ return _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode);
13
+ } else {
14
+ return _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode);
15
15
  }
16
- return bnTransferable;
17
16
  }
18
- export function _getAssetsPalletLockedBalance(accountInfo) {
19
- let bnLocked = BigInt(0);
20
- if (!accountInfo) {
21
- return bnLocked;
17
+ export function _getAssetsPalletLocked(accountInfo) {
18
+ if (isWithStatus(accountInfo)) {
19
+ return _getAssetsPalletLockedWithStatus(accountInfo);
20
+ } else {
21
+ return _getAssetsPalletLockedWithoutStatus(accountInfo);
22
22
  }
23
- if (!['Liquid'].includes(accountInfo.status)) {
24
- // todo: check case accountInfo has isFrozen?
25
- bnLocked = BigInt(accountInfo.balance);
26
- }
27
- return bnLocked;
23
+ }
24
+
25
+ // ----------------------------------------------------------------------
26
+
27
+ export function _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode) {
28
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
29
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
30
+ }
31
+ export function _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode) {
32
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
33
+ return !accountInfo.isFrozen ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
34
+ }
35
+ export function _getAssetsPalletLockedWithStatus(accountInfo) {
36
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
37
+ }
38
+ export function _getAssetsPalletLockedWithoutStatus(accountInfo) {
39
+ return accountInfo.isFrozen ? BigInt(accountInfo.balance) : BigInt(0);
28
40
  }
@@ -1,4 +1,4 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
- export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
- export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
2
+ import { PalletAssetsAssetAccountWithStatus } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccountWithStatus, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccountWithStatus): bigint;
@@ -5,15 +5,8 @@ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/typ
5
5
  import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
6
  export function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
7
  const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
- if (!accountInfo || accountInfo.status !== 'Liquid') {
9
- return BigInt(0);
10
- }
11
- const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
12
- return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
8
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - _getAppliedExistentialDeposit(existentialDeposit, strictMode) : BigInt(0);
13
9
  }
14
10
  export function _getForeignAssetPalletLockedBalance(accountInfo) {
15
- if (!accountInfo || accountInfo.status === 'Liquid') {
16
- return BigInt(0);
17
- }
18
- return BigInt(accountInfo.balance);
11
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
19
12
  }
@@ -24,12 +24,16 @@ export declare type OrmlTokensAccountData = {
24
24
  reserved: number;
25
25
  frozen: number;
26
26
  };
27
- export declare type PalletAssetsAssetAccount = {
27
+ export declare type PalletAssetsAssetAccountWithStatus = {
28
28
  balance: number | string;
29
29
  status: 'Frozen' | 'Liquid' | 'Blocked';
30
30
  reason: Record<string, unknown>;
31
31
  extra: unknown;
32
32
  };
33
+ export declare type PalletAssetsAssetAccountWithoutStatus = Omit<PalletAssetsAssetAccountWithStatus, 'status'> & {
34
+ isFrozen: boolean;
35
+ };
36
+ export declare type PalletAssetsAssetAccount = PalletAssetsAssetAccountWithStatus | PalletAssetsAssetAccountWithoutStatus;
33
37
  export declare type PalletNominationPoolsPoolMember = {
34
38
  poolId: number;
35
39
  points: number;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.2.26-0",
20
+ "version": "1.2.27-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -2069,11 +2069,11 @@
2069
2069
  "@reduxjs/toolkit": "^1.9.1",
2070
2070
  "@sora-substrate/type-definitions": "^1.17.7",
2071
2071
  "@substrate/connect": "^0.8.9",
2072
- "@subwallet/chain-list": "0.2.82",
2073
- "@subwallet/extension-base": "^1.2.26-0",
2074
- "@subwallet/extension-chains": "^1.2.26-0",
2075
- "@subwallet/extension-dapp": "^1.2.26-0",
2076
- "@subwallet/extension-inject": "^1.2.26-0",
2072
+ "@subwallet/chain-list": "0.2.83",
2073
+ "@subwallet/extension-base": "^1.2.27-0",
2074
+ "@subwallet/extension-chains": "^1.2.27-0",
2075
+ "@subwallet/extension-dapp": "^1.2.27-0",
2076
+ "@subwallet/extension-inject": "^1.2.27-0",
2077
2077
  "@subwallet/keyring": "^0.1.5",
2078
2078
  "@subwallet/ui-keyring": "^0.1.5",
2079
2079
  "@walletconnect/keyvaluestorage": "^1.1.1",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.2.26-0'
10
+ version: '1.2.27-0'
11
11
  };
@@ -4,7 +4,7 @@
4
4
  import { _AssetType } from '@subwallet/chain-list/types';
5
5
  import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
7
- import { _getAssetsPalletLockedBalance, _getAssetsPalletTransferable } from '@subwallet/extension-base/core/substrate/assets-pallet';
7
+ import { _getAssetsPalletLocked, _getAssetsPalletTransferable } from '@subwallet/extension-base/core/substrate/assets-pallet';
8
8
  import { _getForeignAssetPalletLockedBalance, _getForeignAssetPalletTransferable } from '@subwallet/extension-base/core/substrate/foreign-asset-pallet';
9
9
  import { _getTotalStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
10
10
  import { _getOrmlTokensPalletLockedBalance, _getOrmlTokensPalletTransferable } from '@subwallet/extension-base/core/substrate/ormlTokens-pallet';
@@ -181,6 +181,16 @@ const subscribeForeignAssetBalance = async ({
181
181
  const balances = rs[foreignAssetsAccountKey];
182
182
  const items = balances.map((_balance, index) => {
183
183
  const balanceInfo = _balance;
184
+ if (!balanceInfo) {
185
+ // no balance info response
186
+ return {
187
+ address: addresses[index],
188
+ tokenSlug: tokenInfo.slug,
189
+ free: '0',
190
+ locked: '0',
191
+ state: APIItemState.READY
192
+ };
193
+ }
184
194
  const transferableBalance = _getForeignAssetPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
185
195
  const totalLockedFromTransfer = _getForeignAssetPalletLockedBalance(balanceInfo);
186
196
  return {
@@ -351,8 +361,18 @@ const subscribeAssetsAccountPallet = async ({
351
361
  const balances = rs[assetsAccountKey];
352
362
  const items = balances.map((_balance, index) => {
353
363
  const balanceInfo = _balance;
364
+ if (!balanceInfo) {
365
+ // no balance info response
366
+ return {
367
+ address: addresses[index],
368
+ tokenSlug: tokenInfo.slug,
369
+ free: '0',
370
+ locked: '0',
371
+ state: APIItemState.READY
372
+ };
373
+ }
354
374
  const transferableBalance = _getAssetsPalletTransferable(balanceInfo, _getAssetExistentialDeposit(tokenInfo), extrinsicType);
355
- const totalLockedFromTransfer = _getAssetsPalletLockedBalance(balanceInfo);
375
+ const totalLockedFromTransfer = _getAssetsPalletLocked(balanceInfo);
356
376
  return {
357
377
  address: addresses[index],
358
378
  tokenSlug: tokenInfo.slug,