edge-currency-accountbased 1.2.3 → 1.2.4

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +6 -0
  3. package/android/src/main/assets/edge-currency-accountbased/{244.chunk.js → 215.chunk.js} +1 -1
  4. package/android/src/main/assets/edge-currency-accountbased/387.chunk.js +2 -2
  5. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +1 -1
  6. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +2 -2
  7. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -2
  8. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +2 -2
  9. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +5 -5
  10. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  11. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +1 -1
  12. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  13. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +4 -4
  14. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +2 -2
  15. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +1 -1
  16. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +1 -1
  17. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  18. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
  19. package/android/src/main/assets/piratesaplingtree/mainnet/2390000.json +7 -0
  20. package/android/src/main/assets/saplingtree/mainnet/2080000.json +7 -0
  21. package/lib/algorand/AlgorandEngine.js +2 -2
  22. package/lib/binance/{bnbEngine.js → BinanceEngine.js} +10 -10
  23. package/lib/binance/{bnbPlugin.js → BinanceTools.js} +1 -1
  24. package/lib/binance/{bnbInfo.js → binanceInfo.js} +1 -1
  25. package/lib/eos/{eosEngine.js → EosEngine.js} +11 -11
  26. package/lib/eos/{eosPlugin.js → EosTools.js} +1 -1
  27. package/lib/eos/info/eosInfo.js +1 -1
  28. package/lib/eos/info/telosInfo.js +1 -1
  29. package/lib/eos/info/waxInfo.js +1 -1
  30. package/lib/ethereum/{ethEngine.js → EthereumEngine.js} +24 -24
  31. package/lib/ethereum/{ethNetwork.js → EthereumNetwork.js} +22 -22
  32. package/lib/ethereum/{ethPlugin.js → EthereumTools.js} +3 -3
  33. package/lib/ethereum/ethereumInfos.js +35 -0
  34. package/lib/ethereum/fees/feeProviders.js +19 -19
  35. package/lib/ethereum/info/{avaxInfo.js → avalancheInfo.js} +1 -1
  36. package/lib/ethereum/info/{bscInfo.js → binancesmartchainInfo.js} +1 -1
  37. package/lib/ethereum/info/celoInfo.js +1 -1
  38. package/lib/ethereum/info/ethDevInfo.js +1 -1
  39. package/lib/ethereum/info/{ethInfo.js → ethereumInfo.js} +1 -1
  40. package/lib/ethereum/info/{etcInfo.js → ethereumclassicInfo.js} +1 -1
  41. package/lib/ethereum/info/{ethwInfo.js → ethereumpowInfo.js} +1 -1
  42. package/lib/ethereum/info/{ftmInfo.js → fantomInfo.js} +1 -1
  43. package/lib/ethereum/info/goerliInfo.js +1 -1
  44. package/lib/ethereum/info/kovanInfo.js +1 -1
  45. package/lib/ethereum/info/optimismInfo.js +1 -1
  46. package/lib/ethereum/info/{maticInfo.js → polygonInfo.js} +1 -1
  47. package/lib/ethereum/info/rinkebyInfo.js +1 -1
  48. package/lib/ethereum/info/ropstenInfo.js +1 -1
  49. package/lib/ethereum/info/rskInfo.js +1 -1
  50. package/lib/ethereum/info/zksyncInfo.js +1 -1
  51. package/lib/fio/{fioEngine.js → FioEngine.js} +6 -5
  52. package/lib/fio/{fioPlugin.js → FioTools.js} +1 -1
  53. package/lib/fio/fioInfo.js +1 -1
  54. package/lib/hedera/{hederaEngine.js → HederaEngine.js} +2 -2
  55. package/lib/hedera/{hederaPlugin.js → HederaTools.js} +2 -2
  56. package/lib/hedera/hederaInfo.js +1 -1
  57. package/lib/hedera/hederaTestnetInfo.js +1 -1
  58. package/lib/index.js +10 -11
  59. package/lib/polkadot/{polkadotEngine.js → PolkadotEngine.js} +2 -2
  60. package/lib/polkadot/{polkadotPlugin.js → PolkadotTools.js} +1 -1
  61. package/lib/polkadot/polkadotInfo.js +1 -1
  62. package/lib/{xrp/xrpEngine.js → ripple/RippleEngine.js} +15 -15
  63. package/lib/{xrp/xrpPlugin.js → ripple/RippleTools.js} +5 -5
  64. package/lib/{xrp/xrpInfo.js → ripple/rippleInfo.js} +1 -1
  65. package/lib/solana/{solanaEngine.js → SolanaEngine.js} +2 -2
  66. package/lib/solana/{solanaPlugin.js → SolanaTools.js} +1 -1
  67. package/lib/solana/solanaInfo.js +1 -1
  68. package/lib/stellar/{stellarEngine.js → StellarEngine.js} +2 -2
  69. package/lib/stellar/{stellarPlugin.js → StellarTools.js} +1 -1
  70. package/lib/stellar/stellarInfo.js +1 -1
  71. package/lib/tezos/{tezosEngine.js → TezosEngine.js} +3 -3
  72. package/lib/tezos/{tezosPlugin.js → TezosTools.js} +1 -1
  73. package/lib/tezos/tezosInfo.js +1 -1
  74. package/lib/tron/{tronEngine.js → TronEngine.js} +2 -2
  75. package/lib/tron/{tronPlugin.js → TronTools.js} +1 -1
  76. package/lib/tron/tronInfo.js +1 -1
  77. package/lib/zcash/{zecEngine.js → ZcashEngine.js} +8 -8
  78. package/lib/zcash/{zecPlugin.js → ZcashTools.js} +25 -7
  79. package/lib/zcash/{arrrInfo.js → piratechainInfo.js} +1 -1
  80. package/lib/zcash/{zecInfo.js → zcashInfo.js} +1 -1
  81. package/package.json +1 -1
  82. package/lib/ethereum/ethInfos.js +0 -35
  83. /package/lib/binance/{bnbTypes.js → binanceTypes.js} +0 -0
  84. /package/lib/common/{engine.js → CurrencyEngine.js} +0 -0
  85. /package/lib/ethereum/{ethConsts.js → ethereumConsts.js} +0 -0
  86. /package/lib/ethereum/{ethSchema.js → ethereumSchema.js} +0 -0
  87. /package/lib/ethereum/{ethTypes.js → ethereumTypes.js} +0 -0
  88. /package/lib/{xrp/xrpTypes.js → ripple/rippleTypes.js} +0 -0
  89. /package/lib/{xrp/xrpUtils.js → ripple/rippleUtils.js} +0 -0
  90. /package/lib/zcash/{zecTypes.js → zcashTypes.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # edge-currency-accountbased
2
2
 
3
+ ## 1.2.4 (2023-05-09)
4
+
5
+ - ZEC/ARR: Add import private key birthdayHeight option handling
6
+ - FIO: Replace public key with recipient public key
7
+ - Rename files to the network name, not the currency code
8
+ - Use uppercase names for files that export classes and use loweracse names for files that export types and utilities
9
+
3
10
  ## 1.2.3 (2023-05-08)
4
11
 
5
12
  - Fix: Precision bug in min gas price checks for EVM currencies
package/README.md CHANGED
@@ -89,6 +89,12 @@ Please note that our team considers (but does not guarantee) PR's to add new cur
89
89
  - Rebase of your branch upon this repo's `master` branch. For more info:
90
90
  https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request
91
91
 
92
+ ### Naming Convention
93
+
94
+ Plugins take their names from the network, not the currency. For instance, the "ripple" plugin supports the Ripple network. There are many currencies on the Ripple network, including XRP, tokens, and bank-backed currencies, so naming the Ripple plugin "xrp" would be too narrow.
95
+
96
+ The same principle applies to all the plugins in this repository, with a few unfortunate exceptions.
97
+
92
98
  ## License
93
99
 
94
100
  BSD 3
@@ -1 +1 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[244],{50244:function(G,R,I){I.d(R,{P:function(){return F}});var x=I(77591),U=I(94935),k=I(82448),f=I(76714);const A=(0,k.su)({currencyCode:(0,k.Zz)(k.XC)});function S(D){try{j(D)}catch(t){throw new TypeError(`Invalid EdgeSpendInfo: ${(0,f.HY)(t)}`)}}function J(D){try{Y(D)}catch(t){throw new TypeError(`Invalid CustomToken: ${(0,f.HY)(t)}`)}}const j=(0,k.su)({currencyCode:(0,k.Zz)(k.XC),networkFeeOption:(0,k.Zz)(k.XC),spendTargets:(0,k._2)((0,k.su)({currencyCode:(0,k.Zz)(k.XC),publicAddress:k.XC,nativeAmount:(0,k.Zz)(k.XC,"0")}))}),Y=(0,k.su)({currencyCode:k.XC,currencyName:k.XC,multiplier:k.XC,contractAddress:k.XC});var z=I(20918),w=I(62177),Z=Object.defineProperty,_=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,H=(D,t,e)=>t in D?Z(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,P=(D,t)=>{for(var e in t||(t={}))N.call(t,e)&&H(D,e,t[e]);if(_)for(var e of _(t))W.call(t,e)&&H(D,e,t[e]);return D},p=(D,t,e)=>new Promise((s,o)=>{var l=h=>{try{y(e.next(h))}catch(C){o(C)}},r=h=>{try{y(e.throw(h))}catch(C){o(C)}},y=h=>h.done?s(h.value):Promise.resolve(h.value).then(l,r);y((e=e.apply(D,t)).next())});const Q=1e4,K=1e3,$=3600*24;class F{constructor(t,e,s,o){const{io:l,currencyInfo:r}=e,{currencyCode:y}=r,{walletLocalDisklet:h,callbacks:C,customTokens:v}=o;this.tools=e,this.io=l,this.log=o.log,this.warn=(E,L)=>this.log.warn(E+(0,f.HY)(L)),this.error=(E,L)=>this.log.error(E+(0,f.HY)(L)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.transactionsChangedArray=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=s,this.walletId=s.id,this.currencyInfo=r,this.allTokens=r.metaTokens.slice(0),this.enabledTokens=[],this.customTokens=[],this.allTokensMap=P(P({},v),t.builtinTokens),this.timers={},this.otherData=void 0,this.minimumAddressBalance="0",this.transactionList[y]=[],this.txIdMap[y]={},this.txIdList[y]=[],o.userSettings!=null?this.currentSettings=o.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=C,this.walletLocalDisklet=h,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=s.keys.publicKey),this.walletLocalData={blockHeight:0,lastAddressQueryHeight:0,lastTransactionQueryHeight:{},lastTransactionDate:{},publicKey:"",totalBalances:{},lastCheckedTxsDropped:0,numUnconfirmedSpendTxs:0,numTransactions:{},unactivatedTokenIds:[],otherData:void 0},this.log(`Created Wallet Type ${this.walletInfo.type} for Currency Plugin ${this.currencyInfo.pluginId}`)}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,x.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const s of t.ourReceiveAddresses)s===this.walletLocalData.publicKey&&(e=!1);return e}setOtherData(t){throw new Error(`Unimplemented setOtherData for ${this.walletInfo.type}`)}loadTransactions(){return p(this,null,function*(){if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const t=this.walletLocalDisklet;let e,s,o;try{const r=yield t.getText(w.TD);e=JSON.parse(r)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield t.setText(w.TD,JSON.stringify(this.txIdList))}try{const r=yield t.getText(w.DZ);s=JSON.parse(r)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield t.setText(w.DZ,JSON.stringify(this.txIdMap))}try{const r=yield t.getText(w.tC);o=JSON.parse(r)}catch(r){r.code==="ENOENT"?(this.log("Could not load transactionList file. Failure is ok on new device"),yield t.setText(w.tC,JSON.stringify(this.transactionList))):this.log.crash(r,this.walletLocalData)}let l=!0;for(const r of Object.keys(this.transactionList))if(this.transactionList[r]!=null&&this.transactionList[r].length>0){l=!1;break}if(l)this.transactionList=o!=null?o:this.transactionList,this.txIdList=e!=null?e:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;else if(o!=null)for(const r of Object.keys(o))for(const y of o[r])this.addTransaction(r,y);for(const r in this.transactionList)this.walletLocalData.numTransactions[r]=this.transactionList[r].length})}loadEngine(t,e,s){return p(this,null,function*(){var o;const{currencyCode:l}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const r=this.walletLocalDisklet;try{const L=yield r.getText(w.Pe);this.walletLocalData=(0,w.O2)(JSON.parse(L)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,w.O2)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield r.setText(w.Pe,JSON.stringify(this.walletLocalData))}catch(g){throw this.error("Error writing to localDataStore. Engine not started: ",g),g}}this.setOtherData((o=this.walletLocalData.otherData)!=null?o:{}),this.walletLocalDataDirty=!(0,f.dQ)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[l]=0,this.tokenCheckTransactionsStatus[l]=0,this.enabledTokens.push(l);const{customTokens:y={},enabledTokenIds:h=[]}=s;for(const L of Object.keys(y)){const g=y[L];try{(0,z.Rp)(g)}catch{this.log.warn(`Dropping custom token "${g.currencyCode}" / ${L}`);continue}const{currencyCode:B,denominations:n,displayName:i,networkLocation:a={}}=g;this.addCustomToken({currencyCode:B,currencyName:i,denominations:n,displayName:i,multiplier:n[0].multiplier,networkLocation:a,contractAddress:a==null?void 0:a.contractAddress}).catch(c=>this.log(c.message))}const C={},v=h.reduce((L,g)=>(L[g]=!0,L),C),E=this.allTokens.map(L=>p(this,[L],function*({currencyCode:g,contractAddress:B="",currencyName:n,denominations:i}){var a,c;return yield(c=(a=this.tools).getTokenId)==null?void 0:c.call(a,{currencyCode:g,displayName:n,denominations:i,networkLocation:{contractAddress:B}}).then(d=>{v[d]&&!this.enabledTokens.includes(g)&&(this.enabledTokens.push(g),this.walletLocalData.totalBalances[g]="0",this.tokenCheckBalanceStatus[g]=0,this.tokenCheckTransactionsStatus[g]=0)}).catch()}));yield Promise.all(E),this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback()})}findTransaction(t,e){if(this.txIdMap[t]!=null){const s=this.txIdMap[t][e];if(typeof s=="number")return s}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,s){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=s!=null?s:Math.round(Date.now()/1e3));const o=(0,f.f0)(e.txid),l=this.findTransaction(t,o);let r=!1;if(l===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),r=!0,typeof this.transactionList[t]>"u")this.transactionList[t]=[];else if(this.transactionList[t].length>=K)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0,this.transactionsChangedArray.push(e),this.warn(`addTransaction new tx: ${e.txid}`)}else{const h=this.transactionList[t][l],{otherParams:C={}}=h,{otherParams:v={}}=e;(h.blockHeight<e.blockHeight||h.blockHeight===0&&e.blockHeight<0||h.blockHeight===e.blockHeight&&(h.networkFee!==e.networkFee||h.nativeAmount!==e.nativeAmount||C.lastSeenTime!==v.lastSeenTime||h.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&h.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,h.date!==e.date&&(r=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,l))}r&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let s=0;for(const o of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,f.f0)(o.txid)]=s,e.push((0,f.f0)(o.txid)),s++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>$&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]))}checkDroppedTransactions(t){let e=0;for(const s in this.transactionList)for(let o=0;o<this.transactionList[s].length;o++){const l=this.transactionList[s][o];if(l.blockHeight===0){const{otherParams:r={}}=l,y=r.lastSeenTime;t-y>$?(l.blockHeight=-1,l.nativeAmount="0",this.transactionsChangedArray.push(l)):this.isSpendTx(l)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const s=this.walletLocalData.totalBalances[t];this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),(s==null||!(0,x.eq)(e,s))&&(this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`),this.currencyEngineCallbacks.onBalanceChanged(t,e)),this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,s){this.transactionList[t][s]=e,this.transactionListDirty=!0,this.transactionsChangedArray.push(e),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return p(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let s=JSON.stringify(this.transactionList);e.push(t.setText(w.tC,s).catch(o=>{this.error("Error saving transactionList ",o)})),s=JSON.stringify(this.txIdList),e.push(t.setText(w.TD,s).catch(o=>{this.error("Error saving txIdList ",o)})),s=JSON.stringify(this.txIdMap),e.push(t.setText(w.DZ,s).catch(o=>{this.error("Error saving txIdMap ",o)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const s=JSON.stringify(this.walletLocalData);yield t.setText(w.Pe,s).then(()=>{this.walletLocalDataDirty=!1}).catch(o=>{this.error("Error saving walletLocalData ",o)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{this.currencyEngineCallbacks.onBalanceChanged(e,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(s){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,s)}}doInitialUnactivatedTokenIdsCallback(){try{this.walletLocalData.unactivatedTokenIds!=null&&this.walletLocalData.unactivatedTokenIds.length>0&&this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds)}catch(t){this.error("doInitialUnactivatedTokenIdsCallback Error",t)}}addToLoop(t,e){return p(this,null,function*(){try{yield this[t]()}catch(s){this.error(`Error in Loop: ${t} `,s)}return this.engineOn&&(this.timers[t]=setTimeout(()=>{this.engineOn&&this.addToLoop(t,e).catch(s=>this.log(s.message))},e)),!0})}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const s=this.enabledTokens,o=1/s.length;let l=0,r=0;for(const y of s){const h=(t=this.tokenCheckBalanceStatus[y])!=null?t:0,C=(e=this.tokenCheckTransactionsStatus[y])!=null?e:0;l+=(h+C)/2*o,h===1&&C===1&&r++}r===s.length&&(l=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${l}`),this.currencyEngineCallbacks.onAddressesChecked(l)}startEngine(){return p(this,null,function*(){this.addToLoop("saveWalletLoop",Q).catch(()=>{})})}killEngine(){return p(this,null,function*(){this.engineOn=!1;for(const t in this.timers)clearTimeout(this.timers[t]);this.timers={}})}changeUserSettings(t){return p(this,null,function*(){this.currentSettings=t})}clearBlockchainCache(){return p(this,null,function*(){this.walletLocalData=(0,w.O2)({publicKey:this.walletLocalData.publicKey}),this.walletLocalDataDirty=!0,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.transactionList={},this.txIdList={},this.txIdMap={},this.transactionListDirty=!0,this.setOtherData({}),yield this.saveWalletLoop()})}getBlockHeight(){return this.walletLocalData.blockHeight}enableTokensSync(t){const e={},s=t.reduce((o,l)=>(o[l]=!0,o),e);for(const o of this.allTokens){const{currencyCode:l}=o;if(s[l]&&!this.enabledTokens.includes(l)){this.enabledTokens.push(l);const r="0";this.walletLocalData.totalBalances[l]=r,this.currencyEngineCallbacks.onBalanceChanged(l,r)}}for(const o of Object.values(this.allTokensMap)){const{currencyCode:l}=o;if(s[l]&&!this.enabledTokens.includes(l)){this.enabledTokens.push(l);const r="0";this.walletLocalData.totalBalances[l]=r,this.currencyEngineCallbacks.onBalanceChanged(l,r)}}}enableTokens(t){return p(this,null,function*(){this.enableTokensSync(t)})}disableTokensSync(t){for(const e of t){if(e===this.currencyInfo.currencyCode)continue;const s=this.enabledTokens.indexOf(e);s!==-1&&this.enabledTokens.splice(s,1)}}disableTokens(t){return p(this,null,function*(){this.disableTokensSync(t)})}getEnabledTokens(){return p(this,null,function*(){return this.enabledTokens})}addCustomToken(t,e){return p(this,null,function*(){J(t);const s=t;for(const r of this.currencyInfo.metaTokens)if(r.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||r.currencyName.toLowerCase()===s.currencyName.toLowerCase())throw new Error("ErrorCannotModifyToken");for(const r of this.customTokens)if(r.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||r.currencyName.toLowerCase()===s.currencyName.toLowerCase()){const y=this.customTokens.findIndex(h=>h.currencyCode===s.currencyCode);y!==-1&&this.customTokens.splice(y,1)}const o={name:s.currencyCode,multiplier:s.multiplier},l={currencyCode:s.currencyCode,currencyName:s.currencyName,denominations:[o],contractAddress:e!=null?e:s.contractAddress};if(this.customTokens.push(l),this.allTokens=this.currencyInfo.metaTokens.concat(this.customTokens),this.tools.getTokenId!=null){const r=yield this.tools.getTokenId(t);this.allTokensMap=P({[r]:t},this.allTokensMap)}this.enableTokensSync([l.currencyCode])})}getTokenStatus(t){return this.enabledTokens.includes(t)}getBalance(t){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e,o=this.walletLocalData.totalBalances[s];return o==null?"0":o}getNumTransactions(t){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e;return this.walletLocalData.numTransactions[s]==null?0:this.walletLocalData.numTransactions[s]}getTransactions(t){return p(this,null,function*(){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e;if(yield this.loadTransactions(),this.transactionList[s]==null)return[];let o=0,l=0;if(t===null)return this.transactionList[s].slice(0);t.startIndex!=null&&t.startIndex>0&&(o=t.startIndex,o>=this.transactionList[s].length&&(o=this.transactionList[s].length-1)),t.startEntries!=null&&t.startEntries>0&&(l=t.startEntries,l+o>this.transactionList[s].length&&(l=this.transactionList[s].length-o));let r=[];return l!==0?r=this.transactionList[s].slice(o,l+o):r=this.transactionList[s].slice(o),r})}getFreshAddress(t){return p(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return p(this,null,function*(){})}isAddressUsed(t){return p(this,null,function*(){return!1})}dumpData(){return p(this,null,function*(){return{walletId:this.walletId.split(" - ")[0],walletType:this.walletInfo.type,data:{pluginType:{pluginId:this.currencyInfo.pluginId},walletLocalData:this.walletLocalData}}})}makeSpendCheck(t){var e,s,o;const{skipChecks:l=!1}=t;S(t);for(const v of t.spendTargets)if(!l&&v.publicAddress===this.walletLocalData.publicKey)throw new U.l0;let r="";if(typeof t.currencyCode=="string"){if(r=t.currencyCode,r!==this.currencyInfo.currencyCode&&!this.getTokenStatus(r))throw new Error("Error: Token not supported or enabled")}else r=this.currencyInfo.currencyCode;const y=(e=this.walletLocalData.totalBalances[r])!=null?e:"0",h={};for(const v of t.spendTargets){const{nativeAmount:E}=v;E!=null&&(h[r]=(s=h[r])!=null?s:"0",h[r]=(0,x.add)(h[r],E))}for(const[v,E]of Object.entries(h)){const L=(o=this.walletLocalData.totalBalances[v])!=null?o:"0";if(!l&&(0,x.lt)(L,E))throw new U.C_}t.currencyCode=r;const C=(0,f.cp)(this.currencyInfo,r,this.customTokens,this.allTokensMap);if(C==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:y,currencyCode:r,denom:C,skipChecks:l}}checkRecipientMinimumBalance(t,e,s){return p(this,null,function*(){if((0,x.gte)(e,this.minimumAddressBalance))return;const o=yield t(s);if((0,x.lt)((0,x.add)(e,o),this.minimumAddressBalance)){const l=this.currencyInfo.denominations.find(y=>y.name===this.currencyInfo.currencyCode);if(l==null)throw new Error("Unknown denom");const r=(0,x.div)(this.minimumAddressBalance,l.multiplier);throw new Error(`Recipient address not activated. A minimum ${r} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return p(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionsChangedArray.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,f.oX)(e)}`)),this.transactionsChangedArray.length>0&&this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray)})}getDisplayPrivateSeed(t){throw new Error("not implemented")}getDisplayPublicSeed(){throw new Error("not implemented")}resyncBlockchain(){return p(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return p(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return p(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return p(this,null,function*(){throw new Error("not implemented")})}}},76714:function(G,R,I){I.d(R,{$9:function(){return P},EE:function(){return y},HB:function(){return K},HY:function(){return C},KT:function(){return N},NC:function(){return w},QJ:function(){return t},Sy:function(){return j},Vs:function(){return D},Wp:function(){return $},X0:function(){return H},Xp:function(){return s},Y7:function(){return E},Z8:function(){return W},ah:function(){return Z},cp:function(){return p},dQ:function(){return g},f0:function(){return J},gc:function(){return _},jT:function(){return o},ml:function(){return F},nu:function(){return v},oX:function(){return r},sD:function(){return e},vq:function(){return z},zR:function(){return h}});var x=I(77591),U=I.n(x),k=I(48764),f=I(82448),A=I(20918),S=(n,i,a)=>new Promise((c,d)=>{var m=T=>{try{b(a.next(T))}catch(O){d(O)}},u=T=>{try{b(a.throw(T))}catch(O){d(O)}},b=T=>T.done?c(T.value):Promise.resolve(T.value).then(m,u);b((a=a.apply(n,i)).next())});function J(n){return n.toLowerCase().replace("0x","")}function j(n){let i=n.length,a,c;for(;i!==0;)c=Math.floor(Math.random()*i),i-=1,a=n[i],n[i]=n[c],n[c]=a;return n}function Y(n){return Object.keys(n).length!==0}function z(n){return/^[0-9A-F]+$/i.test(N(n))}function w(n){return(0,x.add)(n,"0",16)}function Z(n){const i=n.replace("0x","");return k.Buffer.from(i,"hex")}function _(n,i){return 2*i-n.length>0?n.padStart(2*i,"0"):n}function N(n){return n.indexOf("0x")===0?n.substring(2):n}function W(n){const i=n.toLowerCase(),a=i.startsWith("0x")?i:`0x${i}`;return(0,x.add)(a,"0",10)}function H(n){return(0,x.add)(n,"0",16)}function P(n){return"0x"+k.Buffer.from(n).toString("hex")}function p(n,i,a,c){let d=n.denominations.find(m=>m.name===i);if(c!=null){const m=(0,A.dK)(i,c);m!=null&&(d=c[m].denominations.find(u=>u.name===i))}if(d==null){for(const m of n.metaTokens)if(d=m.denominations.find(u=>u.name===i),d!=null)break}if(d==null&&a!=null){for(const m of a)if(d=m.denominations.find(u=>u.name===i),d!=null)break}return d}const Q=n=>S(void 0,null,function*(){return yield new Promise((i,a)=>setTimeout(a,n))}),K=n=>S(void 0,null,function*(){return yield new Promise(i=>setTimeout(i,n))});function $(n){return S(this,null,function*(){return yield new Promise((i,a)=>{let c=n.length;for(const d of n)d.then(m=>{i(m)},m=>{--c===0&&a(m)})})})}function F(n,i){return S(this,arguments,function*(a,c,d=a.length){const m={};return yield new Promise((u,b)=>{let T=0,O=0,V=!1;for(const q of a)q.then(X=>{const M=c(X);M!==void 0?(T++,m[M]!==void 0?m[M]++:m[M]=1,!V&&m[M]>=d&&(V=!0,u(X))):++O+T===a.length&&b(Error(`Could not resolve ${d} promises`))},X=>{++O+T===a.length&&b(X)})})})}function D(n,i){return S(this,arguments,function*(a,c,d=new Error(`Timeout of ${c}ms exceeded`)){return yield new Promise((m,u)=>{const b=setTimeout(()=>u(d),c);a.then(T=>{m(T),clearTimeout(b)},T=>{u(T),clearTimeout(b)})})})}function t(n,i=5e3){return S(this,null,function*(){let a=n.length;const c=[];for(const d of n){const m=c.length;c.push(d().catch(u=>{throw u.index=m,u})),a>1&&c.push(new Promise(u=>{K(i).then(()=>{u("async_waterfall_timed_out")})}));try{const u=yield Promise.race(c);if(u==="async_waterfall_timed_out"){const b=c.pop();b==null||b.then().catch(),--a}else return u}catch(u){const b=u.index;c.splice(b,1);const T=c.pop();if(T==null||T.then().catch(),--a,a===0)throw u}}})}function e(n,i){if(n.length<=i)return n;const a=[];for(let c=0;c<n.length&&a.length<i;++c){const d=(i-a.length)/(n.length-c);Math.random()<=d&&a.push(n[c])}return a}function s(n){const i=n.otherParams;if(i==null)throw new TypeError("Transaction is missing otherParams");return i}function o(){let n=!1;const i=[];return function(c){return S(this,null,function*(){n&&(yield new Promise(d=>i.push(()=>d(void 0))));try{return n=!0,yield c()}finally{n=!1;const d=i.shift();d!=null&&d()}})}}const l=(0,f.su)({txid:f.XC,spendTargets:(0,f.Zz)((0,f._2)((0,f.su)({currencyCode:f.XC,nativeAmount:f.XC,publicAddress:f.XC,uniqueIdentifier:(0,f.Zz)(f.XC)}))),signedTx:f.XC,otherParams:(0,f.Zz)((0,f.su)({gas:(0,f.Zz)(f.XC),gasPrice:(0,f.Zz)(f.XC),nonceUsed:(0,f.Zz)(f.XC)}))});function r(n){return JSON.stringify(l(n),null,2)}function y(n){const[i,a]=n.split("e");return a==null?n:(0,x.mul)(i,"1"+"0".repeat(parseInt(a))).toString()}function h(n){var i;return(i=n.io.fetchCors)!=null?i:n.io.fetch}function C(n){let i="";return n!=null&&(n.name!=null&&(i+=`${n.name} `),n.message!=null&&(i+=n.message)),i}function v(...n){const i={};for(const a of n)if(a!=null)for(const c of Object.keys(a))a[c]!=null&&(i[c]=i[c]!=null&&typeof a[c]=="object"?v(i[c],a[c]):a[c]);return i}function E(n){const[i,a]=n.split(".");return a==null?i:parseInt(a[0])>=5?(0,x.add)(i,"1"):i}const L=n=>console.log(JSON.stringify(n,null,2));function g(n,i){if(typeof n!="object"||typeof i!="object"||n==null||i==null)return n===i;const a=Array.isArray(n),c=Array.isArray(i);if(a!==c)return!1;if(a){if(n.length!==i.length)return!1;for(let u=0;u<n.length;++u)if(!g(n[u],i[u]))return!1;return!0}const d=Object.getOwnPropertyNames(n).filter(u=>n[u]!==void 0),m=Object.getOwnPropertyNames(i).filter(u=>i[u]!==void 0);if(d.length!==m.length)return!1;for(const u of d)if(!Object.prototype.hasOwnProperty.call(i,u)||!g(n[u],i[u]))return!1;return!0}const B=(n,i)=>{for(const a of Object.keys(n)){if(typeof n[a]=="object"){if(typeof i[a]!="object"||!B(n[a],i[a]))return!1;continue}if(n[a]!==i[a])return!1}return!0}}}]);
1
+ "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[215],{50215:function(G,R,I){I.d(R,{P:function(){return F}});var x=I(77591),U=I(94935),k=I(82448),f=I(76714);const A=(0,k.su)({currencyCode:(0,k.Zz)(k.XC)});function S(D){try{j(D)}catch(t){throw new TypeError(`Invalid EdgeSpendInfo: ${(0,f.HY)(t)}`)}}function J(D){try{Y(D)}catch(t){throw new TypeError(`Invalid CustomToken: ${(0,f.HY)(t)}`)}}const j=(0,k.su)({currencyCode:(0,k.Zz)(k.XC),networkFeeOption:(0,k.Zz)(k.XC),spendTargets:(0,k._2)((0,k.su)({currencyCode:(0,k.Zz)(k.XC),publicAddress:k.XC,nativeAmount:(0,k.Zz)(k.XC,"0")}))}),Y=(0,k.su)({currencyCode:k.XC,currencyName:k.XC,multiplier:k.XC,contractAddress:k.XC});var z=I(20918),w=I(62177),Z=Object.defineProperty,_=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,H=(D,t,e)=>t in D?Z(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,P=(D,t)=>{for(var e in t||(t={}))N.call(t,e)&&H(D,e,t[e]);if(_)for(var e of _(t))W.call(t,e)&&H(D,e,t[e]);return D},p=(D,t,e)=>new Promise((s,o)=>{var l=h=>{try{y(e.next(h))}catch(C){o(C)}},r=h=>{try{y(e.throw(h))}catch(C){o(C)}},y=h=>h.done?s(h.value):Promise.resolve(h.value).then(l,r);y((e=e.apply(D,t)).next())});const Q=1e4,K=1e3,$=3600*24;class F{constructor(t,e,s,o){const{io:l,currencyInfo:r}=e,{currencyCode:y}=r,{walletLocalDisklet:h,callbacks:C,customTokens:v}=o;this.tools=e,this.io=l,this.log=o.log,this.warn=(E,L)=>this.log.warn(E+(0,f.HY)(L)),this.error=(E,L)=>this.log.error(E+(0,f.HY)(L)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.transactionsChangedArray=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=s,this.walletId=s.id,this.currencyInfo=r,this.allTokens=r.metaTokens.slice(0),this.enabledTokens=[],this.customTokens=[],this.allTokensMap=P(P({},v),t.builtinTokens),this.timers={},this.otherData=void 0,this.minimumAddressBalance="0",this.transactionList[y]=[],this.txIdMap[y]={},this.txIdList[y]=[],o.userSettings!=null?this.currentSettings=o.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=C,this.walletLocalDisklet=h,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=s.keys.publicKey),this.walletLocalData={blockHeight:0,lastAddressQueryHeight:0,lastTransactionQueryHeight:{},lastTransactionDate:{},publicKey:"",totalBalances:{},lastCheckedTxsDropped:0,numUnconfirmedSpendTxs:0,numTransactions:{},unactivatedTokenIds:[],otherData:void 0},this.log(`Created Wallet Type ${this.walletInfo.type} for Currency Plugin ${this.currencyInfo.pluginId}`)}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,x.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const s of t.ourReceiveAddresses)s===this.walletLocalData.publicKey&&(e=!1);return e}setOtherData(t){throw new Error(`Unimplemented setOtherData for ${this.walletInfo.type}`)}loadTransactions(){return p(this,null,function*(){if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const t=this.walletLocalDisklet;let e,s,o;try{const r=yield t.getText(w.TD);e=JSON.parse(r)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield t.setText(w.TD,JSON.stringify(this.txIdList))}try{const r=yield t.getText(w.DZ);s=JSON.parse(r)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield t.setText(w.DZ,JSON.stringify(this.txIdMap))}try{const r=yield t.getText(w.tC);o=JSON.parse(r)}catch(r){r.code==="ENOENT"?(this.log("Could not load transactionList file. Failure is ok on new device"),yield t.setText(w.tC,JSON.stringify(this.transactionList))):this.log.crash(r,this.walletLocalData)}let l=!0;for(const r of Object.keys(this.transactionList))if(this.transactionList[r]!=null&&this.transactionList[r].length>0){l=!1;break}if(l)this.transactionList=o!=null?o:this.transactionList,this.txIdList=e!=null?e:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;else if(o!=null)for(const r of Object.keys(o))for(const y of o[r])this.addTransaction(r,y);for(const r in this.transactionList)this.walletLocalData.numTransactions[r]=this.transactionList[r].length})}loadEngine(t,e,s){return p(this,null,function*(){var o;const{currencyCode:l}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const r=this.walletLocalDisklet;try{const L=yield r.getText(w.Pe);this.walletLocalData=(0,w.O2)(JSON.parse(L)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,w.O2)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield r.setText(w.Pe,JSON.stringify(this.walletLocalData))}catch(g){throw this.error("Error writing to localDataStore. Engine not started: ",g),g}}this.setOtherData((o=this.walletLocalData.otherData)!=null?o:{}),this.walletLocalDataDirty=!(0,f.dQ)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[l]=0,this.tokenCheckTransactionsStatus[l]=0,this.enabledTokens.push(l);const{customTokens:y={},enabledTokenIds:h=[]}=s;for(const L of Object.keys(y)){const g=y[L];try{(0,z.Rp)(g)}catch{this.log.warn(`Dropping custom token "${g.currencyCode}" / ${L}`);continue}const{currencyCode:B,denominations:n,displayName:i,networkLocation:a={}}=g;this.addCustomToken({currencyCode:B,currencyName:i,denominations:n,displayName:i,multiplier:n[0].multiplier,networkLocation:a,contractAddress:a==null?void 0:a.contractAddress}).catch(c=>this.log(c.message))}const C={},v=h.reduce((L,g)=>(L[g]=!0,L),C),E=this.allTokens.map(L=>p(this,[L],function*({currencyCode:g,contractAddress:B="",currencyName:n,denominations:i}){var a,c;return yield(c=(a=this.tools).getTokenId)==null?void 0:c.call(a,{currencyCode:g,displayName:n,denominations:i,networkLocation:{contractAddress:B}}).then(d=>{v[d]&&!this.enabledTokens.includes(g)&&(this.enabledTokens.push(g),this.walletLocalData.totalBalances[g]="0",this.tokenCheckBalanceStatus[g]=0,this.tokenCheckTransactionsStatus[g]=0)}).catch()}));yield Promise.all(E),this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback()})}findTransaction(t,e){if(this.txIdMap[t]!=null){const s=this.txIdMap[t][e];if(typeof s=="number")return s}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,s){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=s!=null?s:Math.round(Date.now()/1e3));const o=(0,f.f0)(e.txid),l=this.findTransaction(t,o);let r=!1;if(l===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),r=!0,typeof this.transactionList[t]>"u")this.transactionList[t]=[];else if(this.transactionList[t].length>=K)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0,this.transactionsChangedArray.push(e),this.warn(`addTransaction new tx: ${e.txid}`)}else{const h=this.transactionList[t][l],{otherParams:C={}}=h,{otherParams:v={}}=e;(h.blockHeight<e.blockHeight||h.blockHeight===0&&e.blockHeight<0||h.blockHeight===e.blockHeight&&(h.networkFee!==e.networkFee||h.nativeAmount!==e.nativeAmount||C.lastSeenTime!==v.lastSeenTime||h.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&h.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,h.date!==e.date&&(r=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,l))}r&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let s=0;for(const o of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,f.f0)(o.txid)]=s,e.push((0,f.f0)(o.txid)),s++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>$&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[]))}checkDroppedTransactions(t){let e=0;for(const s in this.transactionList)for(let o=0;o<this.transactionList[s].length;o++){const l=this.transactionList[s][o];if(l.blockHeight===0){const{otherParams:r={}}=l,y=r.lastSeenTime;t-y>$?(l.blockHeight=-1,l.nativeAmount="0",this.transactionsChangedArray.push(l)):this.isSpendTx(l)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const s=this.walletLocalData.totalBalances[t];this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),(s==null||!(0,x.eq)(e,s))&&(this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`),this.currencyEngineCallbacks.onBalanceChanged(t,e)),this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,s){this.transactionList[t][s]=e,this.transactionListDirty=!0,this.transactionsChangedArray.push(e),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return p(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let s=JSON.stringify(this.transactionList);e.push(t.setText(w.tC,s).catch(o=>{this.error("Error saving transactionList ",o)})),s=JSON.stringify(this.txIdList),e.push(t.setText(w.TD,s).catch(o=>{this.error("Error saving txIdList ",o)})),s=JSON.stringify(this.txIdMap),e.push(t.setText(w.DZ,s).catch(o=>{this.error("Error saving txIdMap ",o)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const s=JSON.stringify(this.walletLocalData);yield t.setText(w.Pe,s).then(()=>{this.walletLocalDataDirty=!1}).catch(o=>{this.error("Error saving walletLocalData ",o)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{this.currencyEngineCallbacks.onBalanceChanged(e,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(s){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,s)}}doInitialUnactivatedTokenIdsCallback(){try{this.walletLocalData.unactivatedTokenIds!=null&&this.walletLocalData.unactivatedTokenIds.length>0&&this.currencyEngineCallbacks.onUnactivatedTokenIdsChanged(this.walletLocalData.unactivatedTokenIds)}catch(t){this.error("doInitialUnactivatedTokenIdsCallback Error",t)}}addToLoop(t,e){return p(this,null,function*(){try{yield this[t]()}catch(s){this.error(`Error in Loop: ${t} `,s)}return this.engineOn&&(this.timers[t]=setTimeout(()=>{this.engineOn&&this.addToLoop(t,e).catch(s=>this.log(s.message))},e)),!0})}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const s=this.enabledTokens,o=1/s.length;let l=0,r=0;for(const y of s){const h=(t=this.tokenCheckBalanceStatus[y])!=null?t:0,C=(e=this.tokenCheckTransactionsStatus[y])!=null?e:0;l+=(h+C)/2*o,h===1&&C===1&&r++}r===s.length&&(l=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${l}`),this.currencyEngineCallbacks.onAddressesChecked(l)}startEngine(){return p(this,null,function*(){this.addToLoop("saveWalletLoop",Q).catch(()=>{})})}killEngine(){return p(this,null,function*(){this.engineOn=!1;for(const t in this.timers)clearTimeout(this.timers[t]);this.timers={}})}changeUserSettings(t){return p(this,null,function*(){this.currentSettings=t})}clearBlockchainCache(){return p(this,null,function*(){this.walletLocalData=(0,w.O2)({publicKey:this.walletLocalData.publicKey}),this.walletLocalDataDirty=!0,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.transactionList={},this.txIdList={},this.txIdMap={},this.transactionListDirty=!0,this.setOtherData({}),yield this.saveWalletLoop()})}getBlockHeight(){return this.walletLocalData.blockHeight}enableTokensSync(t){const e={},s=t.reduce((o,l)=>(o[l]=!0,o),e);for(const o of this.allTokens){const{currencyCode:l}=o;if(s[l]&&!this.enabledTokens.includes(l)){this.enabledTokens.push(l);const r="0";this.walletLocalData.totalBalances[l]=r,this.currencyEngineCallbacks.onBalanceChanged(l,r)}}for(const o of Object.values(this.allTokensMap)){const{currencyCode:l}=o;if(s[l]&&!this.enabledTokens.includes(l)){this.enabledTokens.push(l);const r="0";this.walletLocalData.totalBalances[l]=r,this.currencyEngineCallbacks.onBalanceChanged(l,r)}}}enableTokens(t){return p(this,null,function*(){this.enableTokensSync(t)})}disableTokensSync(t){for(const e of t){if(e===this.currencyInfo.currencyCode)continue;const s=this.enabledTokens.indexOf(e);s!==-1&&this.enabledTokens.splice(s,1)}}disableTokens(t){return p(this,null,function*(){this.disableTokensSync(t)})}getEnabledTokens(){return p(this,null,function*(){return this.enabledTokens})}addCustomToken(t,e){return p(this,null,function*(){J(t);const s=t;for(const r of this.currencyInfo.metaTokens)if(r.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||r.currencyName.toLowerCase()===s.currencyName.toLowerCase())throw new Error("ErrorCannotModifyToken");for(const r of this.customTokens)if(r.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||r.currencyName.toLowerCase()===s.currencyName.toLowerCase()){const y=this.customTokens.findIndex(h=>h.currencyCode===s.currencyCode);y!==-1&&this.customTokens.splice(y,1)}const o={name:s.currencyCode,multiplier:s.multiplier},l={currencyCode:s.currencyCode,currencyName:s.currencyName,denominations:[o],contractAddress:e!=null?e:s.contractAddress};if(this.customTokens.push(l),this.allTokens=this.currencyInfo.metaTokens.concat(this.customTokens),this.tools.getTokenId!=null){const r=yield this.tools.getTokenId(t);this.allTokensMap=P({[r]:t},this.allTokensMap)}this.enableTokensSync([l.currencyCode])})}getTokenStatus(t){return this.enabledTokens.includes(t)}getBalance(t){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e,o=this.walletLocalData.totalBalances[s];return o==null?"0":o}getNumTransactions(t){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e;return this.walletLocalData.numTransactions[s]==null?0:this.walletLocalData.numTransactions[s]}getTransactions(t){return p(this,null,function*(){const e=A(t),{currencyCode:s=this.currencyInfo.currencyCode}=e;if(yield this.loadTransactions(),this.transactionList[s]==null)return[];let o=0,l=0;if(t===null)return this.transactionList[s].slice(0);t.startIndex!=null&&t.startIndex>0&&(o=t.startIndex,o>=this.transactionList[s].length&&(o=this.transactionList[s].length-1)),t.startEntries!=null&&t.startEntries>0&&(l=t.startEntries,l+o>this.transactionList[s].length&&(l=this.transactionList[s].length-o));let r=[];return l!==0?r=this.transactionList[s].slice(o,l+o):r=this.transactionList[s].slice(o),r})}getFreshAddress(t){return p(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return p(this,null,function*(){})}isAddressUsed(t){return p(this,null,function*(){return!1})}dumpData(){return p(this,null,function*(){return{walletId:this.walletId.split(" - ")[0],walletType:this.walletInfo.type,data:{pluginType:{pluginId:this.currencyInfo.pluginId},walletLocalData:this.walletLocalData}}})}makeSpendCheck(t){var e,s,o;const{skipChecks:l=!1}=t;S(t);for(const v of t.spendTargets)if(!l&&v.publicAddress===this.walletLocalData.publicKey)throw new U.l0;let r="";if(typeof t.currencyCode=="string"){if(r=t.currencyCode,r!==this.currencyInfo.currencyCode&&!this.getTokenStatus(r))throw new Error("Error: Token not supported or enabled")}else r=this.currencyInfo.currencyCode;const y=(e=this.walletLocalData.totalBalances[r])!=null?e:"0",h={};for(const v of t.spendTargets){const{nativeAmount:E}=v;E!=null&&(h[r]=(s=h[r])!=null?s:"0",h[r]=(0,x.add)(h[r],E))}for(const[v,E]of Object.entries(h)){const L=(o=this.walletLocalData.totalBalances[v])!=null?o:"0";if(!l&&(0,x.lt)(L,E))throw new U.C_}t.currencyCode=r;const C=(0,f.cp)(this.currencyInfo,r,this.customTokens,this.allTokensMap);if(C==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:y,currencyCode:r,denom:C,skipChecks:l}}checkRecipientMinimumBalance(t,e,s){return p(this,null,function*(){if((0,x.gte)(e,this.minimumAddressBalance))return;const o=yield t(s);if((0,x.lt)((0,x.add)(e,o),this.minimumAddressBalance)){const l=this.currencyInfo.denominations.find(y=>y.name===this.currencyInfo.currencyCode);if(l==null)throw new Error("Unknown denom");const r=(0,x.div)(this.minimumAddressBalance,l.multiplier);throw new Error(`Recipient address not activated. A minimum ${r} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return p(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionsChangedArray.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,f.oX)(e)}`)),this.transactionsChangedArray.length>0&&this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray)})}getDisplayPrivateSeed(t){throw new Error("not implemented")}getDisplayPublicSeed(){throw new Error("not implemented")}resyncBlockchain(){return p(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return p(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return p(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return p(this,null,function*(){throw new Error("not implemented")})}}},76714:function(G,R,I){I.d(R,{$9:function(){return P},EE:function(){return y},HB:function(){return K},HY:function(){return C},KT:function(){return N},NC:function(){return w},QJ:function(){return t},Sy:function(){return j},Vs:function(){return D},Wp:function(){return $},X0:function(){return H},Xp:function(){return s},Y7:function(){return E},Z8:function(){return W},ah:function(){return Z},cp:function(){return p},dQ:function(){return g},f0:function(){return J},gc:function(){return _},jT:function(){return o},ml:function(){return F},nu:function(){return v},oX:function(){return r},sD:function(){return e},vq:function(){return z},zR:function(){return h}});var x=I(77591),U=I.n(x),k=I(48764),f=I(82448),A=I(20918),S=(n,i,a)=>new Promise((c,d)=>{var m=T=>{try{b(a.next(T))}catch(O){d(O)}},u=T=>{try{b(a.throw(T))}catch(O){d(O)}},b=T=>T.done?c(T.value):Promise.resolve(T.value).then(m,u);b((a=a.apply(n,i)).next())});function J(n){return n.toLowerCase().replace("0x","")}function j(n){let i=n.length,a,c;for(;i!==0;)c=Math.floor(Math.random()*i),i-=1,a=n[i],n[i]=n[c],n[c]=a;return n}function Y(n){return Object.keys(n).length!==0}function z(n){return/^[0-9A-F]+$/i.test(N(n))}function w(n){return(0,x.add)(n,"0",16)}function Z(n){const i=n.replace("0x","");return k.Buffer.from(i,"hex")}function _(n,i){return 2*i-n.length>0?n.padStart(2*i,"0"):n}function N(n){return n.indexOf("0x")===0?n.substring(2):n}function W(n){const i=n.toLowerCase(),a=i.startsWith("0x")?i:`0x${i}`;return(0,x.add)(a,"0",10)}function H(n){return(0,x.add)(n,"0",16)}function P(n){return"0x"+k.Buffer.from(n).toString("hex")}function p(n,i,a,c){let d=n.denominations.find(m=>m.name===i);if(c!=null){const m=(0,A.dK)(i,c);m!=null&&(d=c[m].denominations.find(u=>u.name===i))}if(d==null){for(const m of n.metaTokens)if(d=m.denominations.find(u=>u.name===i),d!=null)break}if(d==null&&a!=null){for(const m of a)if(d=m.denominations.find(u=>u.name===i),d!=null)break}return d}const Q=n=>S(void 0,null,function*(){return yield new Promise((i,a)=>setTimeout(a,n))}),K=n=>S(void 0,null,function*(){return yield new Promise(i=>setTimeout(i,n))});function $(n){return S(this,null,function*(){return yield new Promise((i,a)=>{let c=n.length;for(const d of n)d.then(m=>{i(m)},m=>{--c===0&&a(m)})})})}function F(n,i){return S(this,arguments,function*(a,c,d=a.length){const m={};return yield new Promise((u,b)=>{let T=0,O=0,V=!1;for(const q of a)q.then(X=>{const M=c(X);M!==void 0?(T++,m[M]!==void 0?m[M]++:m[M]=1,!V&&m[M]>=d&&(V=!0,u(X))):++O+T===a.length&&b(Error(`Could not resolve ${d} promises`))},X=>{++O+T===a.length&&b(X)})})})}function D(n,i){return S(this,arguments,function*(a,c,d=new Error(`Timeout of ${c}ms exceeded`)){return yield new Promise((m,u)=>{const b=setTimeout(()=>u(d),c);a.then(T=>{m(T),clearTimeout(b)},T=>{u(T),clearTimeout(b)})})})}function t(n,i=5e3){return S(this,null,function*(){let a=n.length;const c=[];for(const d of n){const m=c.length;c.push(d().catch(u=>{throw u.index=m,u})),a>1&&c.push(new Promise(u=>{K(i).then(()=>{u("async_waterfall_timed_out")})}));try{const u=yield Promise.race(c);if(u==="async_waterfall_timed_out"){const b=c.pop();b==null||b.then().catch(),--a}else return u}catch(u){const b=u.index;c.splice(b,1);const T=c.pop();if(T==null||T.then().catch(),--a,a===0)throw u}}})}function e(n,i){if(n.length<=i)return n;const a=[];for(let c=0;c<n.length&&a.length<i;++c){const d=(i-a.length)/(n.length-c);Math.random()<=d&&a.push(n[c])}return a}function s(n){const i=n.otherParams;if(i==null)throw new TypeError("Transaction is missing otherParams");return i}function o(){let n=!1;const i=[];return function(c){return S(this,null,function*(){n&&(yield new Promise(d=>i.push(()=>d(void 0))));try{return n=!0,yield c()}finally{n=!1;const d=i.shift();d!=null&&d()}})}}const l=(0,f.su)({txid:f.XC,spendTargets:(0,f.Zz)((0,f._2)((0,f.su)({currencyCode:f.XC,nativeAmount:f.XC,publicAddress:f.XC,uniqueIdentifier:(0,f.Zz)(f.XC)}))),signedTx:f.XC,otherParams:(0,f.Zz)((0,f.su)({gas:(0,f.Zz)(f.XC),gasPrice:(0,f.Zz)(f.XC),nonceUsed:(0,f.Zz)(f.XC)}))});function r(n){return JSON.stringify(l(n),null,2)}function y(n){const[i,a]=n.split("e");return a==null?n:(0,x.mul)(i,"1"+"0".repeat(parseInt(a))).toString()}function h(n){var i;return(i=n.io.fetchCors)!=null?i:n.io.fetch}function C(n){let i="";return n!=null&&(n.name!=null&&(i+=`${n.name} `),n.message!=null&&(i+=n.message)),i}function v(...n){const i={};for(const a of n)if(a!=null)for(const c of Object.keys(a))a[c]!=null&&(i[c]=i[c]!=null&&typeof a[c]=="object"?v(i[c],a[c]):a[c]);return i}function E(n){const[i,a]=n.split(".");return a==null?i:parseInt(a[0])>=5?(0,x.add)(i,"1"):i}const L=n=>console.log(JSON.stringify(n,null,2));function g(n,i){if(typeof n!="object"||typeof i!="object"||n==null||i==null)return n===i;const a=Array.isArray(n),c=Array.isArray(i);if(a!==c)return!1;if(a){if(n.length!==i.length)return!1;for(let u=0;u<n.length;++u)if(!g(n[u],i[u]))return!1;return!0}const d=Object.getOwnPropertyNames(n).filter(u=>n[u]!==void 0),m=Object.getOwnPropertyNames(i).filter(u=>i[u]!==void 0);if(d.length!==m.length)return!1;for(const u of d)if(!Object.prototype.hasOwnProperty.call(i,u)||!g(n[u],i[u]))return!1;return!0}const B=(n,i)=>{for(const a of Object.keys(n)){if(typeof n[a]=="object"){if(typeof i[a]!="object"||!B(n[a],i[a]))return!1;continue}if(n[a]!==i[a])return!1}return!0}}}]);