edge-currency-accountbased 2.2.1 → 2.2.3

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.
@@ -14,8 +14,7 @@ var _biggystring = require('biggystring');
14
14
 
15
15
 
16
16
 
17
-
18
- var _types3 = require('edge-core-js/types');
17
+ var _types = require('edge-core-js/types');
19
18
  var _rfc4648 = require('rfc4648');
20
19
 
21
20
  var _CurrencyEngine = require('../common/CurrencyEngine');
@@ -42,7 +41,6 @@ var _utils = require('../common/utils');
42
41
 
43
42
 
44
43
 
45
-
46
44
  var _polkadotTypes = require('./polkadotTypes');
47
45
 
48
46
  const ACCOUNT_POLL_MILLISECONDS = 5000
@@ -115,10 +113,14 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
115
113
  }
116
114
 
117
115
  async queryBalance() {
118
- const queryArray = [
119
- [this.api.query.system.account, this.walletInfo.keys.publicKey] // returns FrameSystemAccountInfo
120
- ]
121
- const edgeTokenArray = []
116
+ const accountBalanceRes = await this.api.query.system.account(
117
+ this.walletInfo.keys.publicKey
118
+ )
119
+ this.nonce = accountBalanceRes.nonce.toNumber()
120
+ this.updateBalance(
121
+ this.currencyInfo.currencyCode,
122
+ accountBalanceRes.data.free.toString()
123
+ )
122
124
 
123
125
  for (const tokenId of this.enabledTokenIds) {
124
126
  const token = this.allTokensMap[tokenId]
@@ -126,41 +128,16 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
126
128
  const networkLocation = _tokenHelpers.asMaybeContractLocation.call(void 0, token.networkLocation)
127
129
  if (networkLocation == null) continue
128
130
 
129
- queryArray.push([
130
- this.api.query.assets.account,
131
- [networkLocation.contractAddress, this.walletInfo.keys.publicKey]
132
- ]) // returns Option<PalletAssetsAssetAccount>
133
- edgeTokenArray.push(token)
134
- }
131
+ const tokenBalanceRes = await this.api.query.assets.account
135
132
 
136
- const unsubscribe = await this.api.queryMulti(queryArray, balances => {
137
- if (balances.length === 0) {
138
- throw new Error('No balances returned')
139
- }
133
+ (networkLocation.contractAddress, this.walletInfo.keys.publicKey)
140
134
 
141
- // Mainnet
142
- const accountBalance = balances.shift()
143
- this.nonce = accountBalance.nonce.toNumber()
144
- this.updateBalance(
145
- this.currencyInfo.currencyCode,
146
- accountBalance.data.free.toString()
147
- )
148
-
149
- // Assets
150
- for (const [i, assetBalanceRaw] of balances.entries()) {
151
- const token = edgeTokenArray[i]
152
- const assetBalance = _polkadotTypes.asMaybeAssetsPalletBalance.call(void 0,
153
- assetBalanceRaw.toPrimitive()
154
- )
155
- if (assetBalance == null) {
156
- this.updateBalance(token.currencyCode, '0')
157
- return
158
- }
159
-
160
- this.updateBalance(token.currencyCode, assetBalance.balance.toString())
135
+ let tokenBalance = '0'
136
+ if (tokenBalanceRes.isSome) {
137
+ tokenBalance = tokenBalanceRes.unwrap().balance.toString()
161
138
  }
162
- })
163
- unsubscribe() // queryMulti sets up a subscription but we only need to call it once
139
+ this.updateBalance(token.currencyCode, tokenBalance)
140
+ }
164
141
  }
165
142
 
166
143
  async queryBlockheight() {
@@ -417,7 +394,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
417
394
 
418
395
  if (publicAddress == null)
419
396
  throw new Error('makeSpend Missing publicAddress')
420
- if (nativeAmount == null) throw new (0, _types3.NoAmountSpecifiedError)()
397
+ if (nativeAmount == null) throw new (0, _types.NoAmountSpecifiedError)()
421
398
 
422
399
  const balance = this.getBalance({
423
400
  currencyCode
@@ -433,7 +410,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
433
410
  )
434
411
 
435
412
  if (_biggystring.gt.call(void 0, nativeAmount, spendableBalance)) {
436
- throw new (0, _types3.InsufficientFundsError)()
413
+ throw new (0, _types.InsufficientFundsError)()
437
414
  }
438
415
 
439
416
  const transfer = await this.api.tx.balances.transferKeepAlive(
@@ -457,11 +434,11 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
457
434
  totalTxAmount = _biggystring.add.call(void 0, nativeAmount, nativeNetworkFee)
458
435
 
459
436
  if (_biggystring.gt.call(void 0, totalTxAmount, spendableBalance)) {
460
- throw new (0, _types3.InsufficientFundsError)()
437
+ throw new (0, _types.InsufficientFundsError)()
461
438
  }
462
439
  } else {
463
440
  if (_biggystring.gt.call(void 0, nativeAmount, balance)) {
464
- throw new (0, _types3.InsufficientFundsError)()
441
+ throw new (0, _types.InsufficientFundsError)()
465
442
  }
466
443
  totalTxAmount = nativeAmount
467
444
  const transfer = await this.api.tx.assets.transfer(
@@ -491,7 +468,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
491
468
  this.api.consts.balances.existentialDeposit.toString()
492
469
  )
493
470
  if (_biggystring.gt.call(void 0, nativeNetworkFee, spendableFeeBalance)) {
494
- throw new (0, _types3.InsufficientFundsError)({
471
+ throw new (0, _types.InsufficientFundsError)({
495
472
  currencyCode: this.currencyInfo.currencyCode,
496
473
  networkFee: nativeNetworkFee
497
474
  })
@@ -13,15 +13,6 @@ var _cleaners = require('cleaners');
13
13
 
14
14
  var _types = require('../common/types');
15
15
 
16
- const asMaybeAssetsPalletBalance = _cleaners.asMaybe.call(void 0,
17
- _cleaners.asObject.call(void 0, {
18
- balance: _cleaners.asNumber
19
- // status: 'Liquid',
20
- // reason: { sufficient: null },
21
- // extra: null
22
- })
23
- ); exports.asMaybeAssetsPalletBalance = asMaybeAssetsPalletBalance
24
-
25
16
 
26
17
 
27
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {