edge-currency-accountbased 0.22.21 → 0.23.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.
- package/CHANGELOG.md +7 -0
- package/android/src/main/assets/edge-currency-accountbased/{645.chunk.js → 216.chunk.js} +6 -6
- package/android/src/main/assets/edge-currency-accountbased/244.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/387.chunk.js +9 -0
- package/android/src/main/assets/edge-currency-accountbased/491.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/549.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/94.chunk.js +8 -9
- package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +3 -3
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +11 -11
- package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +9 -9
- package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -4
- package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +3 -3
- package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +6 -6
- package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +3 -3
- package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +2 -2
- package/lib/binance/bnbEngine.js +28 -16
- package/lib/binance/bnbTypes.js +11 -0
- package/lib/common/engine.js +47 -3
- package/lib/common/types.js +20 -0
- package/lib/declare-modules.d.js +0 -22
- package/lib/eos/eosEngine.js +32 -21
- package/lib/eos/eosTypes.js +16 -0
- package/lib/eos/info/eosInfo.js +3 -1
- package/lib/ethereum/ethEngine.js +90 -140
- package/lib/ethereum/ethTypes.js +64 -0
- package/lib/fio/fioConst.js +26 -55
- package/lib/fio/fioEngine.js +830 -609
- package/lib/fio/fioError.js +15 -22
- package/lib/fio/fioInfo.js +13 -23
- package/lib/fio/fioPlugin.js +85 -94
- package/lib/fio/fioTypes.js +180 -1
- package/lib/hedera/hederaEngine.js +24 -12
- package/lib/hedera/hederaTypes.js +37 -0
- package/lib/polkadot/polkadotEngine.js +30 -10
- package/lib/polkadot/polkadotTypes.js +37 -0
- package/lib/solana/solanaEngine.js +25 -27
- package/lib/solana/solanaTypes.js +37 -0
- package/lib/stellar/stellarEngine.js +21 -19
- package/lib/stellar/stellarTypes.js +10 -0
- package/lib/tezos/tezosEngine.js +23 -18
- package/lib/tezos/tezosTypes.js +16 -0
- package/lib/tron/tronEngine.js +14 -7
- package/lib/tron/tronPlugin.js +1 -1
- package/lib/tron/tronTypes.js +15 -11
- package/lib/xrp/xrpEngine.js +86 -59
- package/lib/xrp/xrpTypes.js +16 -0
- package/lib/zcash/zecEngine.js +33 -27
- package/lib/zcash/zecInfo.js +4 -1
- package/lib/zcash/zecPlugin.js +20 -6
- package/lib/zcash/zecTypes.js +57 -1
- package/package.json +3 -3
- package/android/src/main/assets/edge-currency-accountbased/206.chunk.js +0 -8
|
@@ -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),m=I(82448),f=I(76714);const A=(0,m.su)({currencyCode:(0,m.Zz)(m.XC)});function E(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,m.su)({currencyCode:(0,m.Zz)(m.XC),networkFeeOption:(0,m.Zz)(m.XC),spendTargets:(0,m._2)((0,m.su)({currencyCode:(0,m.Zz)(m.XC),publicAddress:m.XC,nativeAmount:(0,m.Zz)(m.XC,"0")}))}),Y=(0,m.su)({currencyCode:m.XC,currencyName:m.XC,multiplier:m.XC,contractAddress:m.XC});var z=I(20918),C=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},k=(D,t,e)=>new Promise((s,o)=>{var l=h=>{try{y(e.next(h))}catch(L){o(L)}},a=h=>{try{y(e.throw(h))}catch(L){o(L)}},y=h=>h.done?s(h.value):Promise.resolve(h.value).then(l,a);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:a}=e,{currencyCode:y}=a,{walletLocalDisklet:h,callbacks:L,customTokens:v}=o;this.tools=e,this.io=l,this.log=o.log,this.warn=(O,g)=>this.log.warn(O+(0,f.HY)(g)),this.error=(O,g)=>this.log.error(O+(0,f.HY)(g)),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=a,this.allTokens=a.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=L,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 k(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 a=yield t.getText(C.TD);e=JSON.parse(a)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield t.setText(C.TD,JSON.stringify(this.txIdList))}try{const a=yield t.getText(C.DZ);s=JSON.parse(a)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield t.setText(C.DZ,JSON.stringify(this.txIdMap))}try{const a=yield t.getText(C.tC);o=JSON.parse(a)}catch(a){a.code==="ENOENT"?(this.log("Could not load transactionList file. Failure is ok on new device"),yield t.setText(C.tC,JSON.stringify(this.transactionList))):this.log.crash(a,this.walletLocalData)}let l=!0;for(const a of Object.keys(this.transactionList))if(this.transactionList[a]!=null&&this.transactionList[a].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 a of Object.keys(o))for(const y of o[a])this.addTransaction(a,y);for(const a in this.transactionList)this.walletLocalData.numTransactions[a]=this.transactionList[a].length})}loadEngine(t,e,s){return k(this,null,function*(){var o;const{currencyCode:l}=this.currencyInfo;if(this.walletInfo.keys.publicKey==null){const g=yield this.tools.derivePublicKey(this.walletInfo);this.walletInfo.keys.publicKey=g.publicKey}const a=this.walletLocalDisklet;try{const g=yield a.getText(C.Pe);this.walletLocalData=(0,C.O2)(JSON.parse(g)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,C.O2)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield a.setText(C.Pe,JSON.stringify(this.walletLocalData))}catch(T){throw this.error("Error writing to localDataStore. Engine not started: ",T),T}}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 g of Object.keys(y)){const T=y[g];try{(0,z.Rp)(T)}catch{this.log.warn(`Dropping custom token "${T.currencyCode}" / ${g}`);continue}const{currencyCode:B,denominations:n,displayName:i,networkLocation:r={}}=T;this.addCustomToken({currencyCode:B,currencyName:i,denominations:n,displayName:i,multiplier:n[0].multiplier,networkLocation:r,contractAddress:r==null?void 0:r.contractAddress}).catch(c=>this.log(c.message))}const L={},v=h.reduce((g,T)=>(g[T]=!0,g),L),O=this.allTokens.map(g=>k(this,[g],function*({currencyCode:T,contractAddress:B="",currencyName:n,denominations:i}){var r,c;return yield(c=(r=this.tools).getTokenId)==null?void 0:c.call(r,{currencyCode:T,displayName:n,denominations:i,networkLocation:{contractAddress:B}}).then(d=>{v[d]&&!this.enabledTokens.includes(T)&&(this.enabledTokens.push(T),this.walletLocalData.totalBalances[T]="0",this.tokenCheckBalanceStatus[T]=0,this.tokenCheckTransactionsStatus[T]=0)}).catch()}));yield Promise.all(O),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 a=!1;if(l===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),a=!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:L={}}=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||L.lastSeenTime!==v.lastSeenTime||h.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&h.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,h.date!==e.date&&(a=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,l))}a&&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:a={}}=l,y=a.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 k(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(C.tC,s).catch(o=>{this.error("Error saving transactionList ",o)})),s=JSON.stringify(this.txIdList),e.push(t.setText(C.TD,s).catch(o=>{this.error("Error saving txIdList ",o)})),s=JSON.stringify(this.txIdMap),e.push(t.setText(C.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(C.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 k(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,a=0;for(const y of s){const h=(t=this.tokenCheckBalanceStatus[y])!=null?t:0,L=(e=this.tokenCheckTransactionsStatus[y])!=null?e:0;l+=(h+L)/2*o,h===1&&L===1&&a++}a===s.length&&(l=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${l}`),this.currencyEngineCallbacks.onAddressesChecked(l)}startEngine(){return k(this,null,function*(){this.addToLoop("saveWalletLoop",Q).catch(()=>{})})}killEngine(){return k(this,null,function*(){this.engineOn=!1;for(const t in this.timers)clearTimeout(this.timers[t]);this.timers={}})}changeUserSettings(t){return k(this,null,function*(){this.currentSettings=t})}clearBlockchainCache(){return k(this,null,function*(){this.walletLocalData=(0,C.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 a="0";this.walletLocalData.totalBalances[l]=a,this.currencyEngineCallbacks.onBalanceChanged(l,a)}}for(const o of Object.values(this.allTokensMap)){const{currencyCode:l}=o;if(s[l]&&!this.enabledTokens.includes(l)){this.enabledTokens.push(l);const a="0";this.walletLocalData.totalBalances[l]=a,this.currencyEngineCallbacks.onBalanceChanged(l,a)}}}enableTokens(t){return k(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 k(this,null,function*(){this.disableTokensSync(t)})}getEnabledTokens(){return k(this,null,function*(){return this.enabledTokens})}addCustomToken(t,e){return k(this,null,function*(){J(t);const s=t;for(const a of this.currencyInfo.metaTokens)if(a.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||a.currencyName.toLowerCase()===s.currencyName.toLowerCase())throw new Error("ErrorCannotModifyToken");for(const a of this.customTokens)if(a.currencyCode.toLowerCase()===s.currencyCode.toLowerCase()||a.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 a=yield this.tools.getTokenId(t);this.allTokensMap=P({[a]: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 k(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 a=[];return l!==0?a=this.transactionList[s].slice(o,l+o):a=this.transactionList[s].slice(o),a})}getFreshAddress(t){return k(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return k(this,null,function*(){})}isAddressUsed(t){return k(this,null,function*(){return!1})}dumpData(){return k(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;E(t);for(const v of t.spendTargets)if(v.publicAddress===this.walletLocalData.publicKey)throw new U.l0;let a="";if(typeof t.currencyCode=="string"){if(a=t.currencyCode,a!==this.currencyInfo.currencyCode&&!this.getTokenStatus(a))throw new Error("Error: Token not supported or enabled")}else a=this.currencyInfo.currencyCode;const y=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",h={};for(const v of t.spendTargets){const{nativeAmount:O}=v;O!=null&&(h[a]=(s=h[a])!=null?s:"0",h[a]=(0,x.add)(h[a],O))}for(const[v,O]of Object.entries(h)){const g=(o=this.walletLocalData.totalBalances[v])!=null?o:"0";if(!l&&(0,x.lt)(g,O))throw new U.C_}t.currencyCode=a;const L=(0,f.cp)(this.currencyInfo,a,this.customTokens,this.allTokensMap);if(L==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:y,currencyCode:a,denom:L,skipChecks:l}}checkRecipientMinimumBalance(t,e,s){return k(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 a=(0,x.div)(this.minimumAddressBalance,l.multiplier);throw new Error(`Recipient address not activated. A minimum ${a} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return k(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)})}}},76714:function(G,R,I){I.d(R,{$9:function(){return P},EE:function(){return y},HB:function(){return K},HY:function(){return L},KT:function(){return N},NC:function(){return C},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 O},Z8:function(){return W},ah:function(){return Z},cp:function(){return k},dQ:function(){return T},f0:function(){return J},gc:function(){return _},jT:function(){return o},ml:function(){return F},nu:function(){return v},oX:function(){return a},sD:function(){return e},vq:function(){return z},zR:function(){return h}});var x=I(77591),U=I.n(x),m=I(48764),f=I(82448),A=I(20918),E=(n,i,r)=>new Promise((c,d)=>{var p=w=>{try{b(r.next(w))}catch(S){d(S)}},u=w=>{try{b(r.throw(w))}catch(S){d(S)}},b=w=>w.done?c(w.value):Promise.resolve(w.value).then(p,u);b((r=r.apply(n,i)).next())});function J(n){return n.toLowerCase().replace("0x","")}function j(n){let i=n.length,r,c;for(;i!==0;)c=Math.floor(Math.random()*i),i-=1,r=n[i],n[i]=n[c],n[c]=r;return n}function Y(n){return Object.keys(n).length!==0}function z(n){return/^[0-9A-F]+$/i.test(N(n))}function C(n){return(0,x.add)(n,"0",16)}function Z(n){const i=n.replace("0x","");return m.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(),r=i.startsWith("0x")?i:`0x${i}`;return(0,x.add)(r,"0",10)}function H(n){return(0,x.add)(n,"0",16)}function P(n){return"0x"+m.Buffer.from(n).toString("hex")}function k(n,i,r,c){let d=n.denominations.find(p=>p.name===i);if(c!=null){const p=(0,A.dK)(i,c);p!=null&&(d=c[p].denominations.find(u=>u.name===i))}if(d==null){for(const p of n.metaTokens)if(d=p.denominations.find(u=>u.name===i),d!=null)break}if(d==null&&r!=null){for(const p of r)if(d=p.denominations.find(u=>u.name===i),d!=null)break}return d}const Q=n=>E(void 0,null,function*(){return yield new Promise((i,r)=>setTimeout(r,n))}),K=n=>E(void 0,null,function*(){return yield new Promise(i=>setTimeout(i,n))});function $(n){return E(this,null,function*(){return yield new Promise((i,r)=>{let c=n.length;for(const d of n)d.then(p=>{i(p)},p=>{--c===0&&r(p)})})})}function F(n,i){return E(this,arguments,function*(r,c,d=r.length){const p={};return yield new Promise((u,b)=>{let w=0,S=0,V=!1;for(const q of r)q.then(X=>{const M=c(X);M!==void 0?(w++,p[M]!==void 0?p[M]++:p[M]=1,!V&&p[M]>=d&&(V=!0,u(X))):++S+w===r.length&&b(Error(`Could not resolve ${d} promises`))},X=>{++S+w===r.length&&b(X)})})})}function D(n,i){return E(this,arguments,function*(r,c,d=new Error(`Timeout of ${c}ms exceeded`)){return yield new Promise((p,u)=>{const b=setTimeout(()=>u(d),c);r.then(w=>{p(w),clearTimeout(b)},w=>{u(w),clearTimeout(b)})})})}function t(n,i=5e3){return E(this,null,function*(){let r=n.length;const c=[];for(const d of n){const p=c.length;c.push(d().catch(u=>{throw u.index=p,u})),r>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(),--r}else return u}catch(u){const b=u.index;c.splice(b,1);const w=c.pop();if(w==null||w.then().catch(),--r,r===0)throw u}}})}function e(n,i){if(n.length<=i)return n;const r=[];for(let c=0;c<n.length&&r.length<i;++c){const d=(i-r.length)/(n.length-c);Math.random()<=d&&r.push(n[c])}return r}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 E(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 a(n){return JSON.stringify(l(n),null,2)}function y(n){const[i,r]=n.split("e");return r==null?n:(0,x.mul)(i,"1"+"0".repeat(parseInt(r))).toString()}function h(n){var i;return(i=n.io.fetchCors)!=null?i:n.io.fetch}function L(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 r of n)if(r!=null)for(const c of Object.keys(r))r[c]!=null&&(i[c]=i[c]!=null&&typeof r[c]=="object"?v(i[c],r[c]):r[c]);return i}function O(n){const[i,r]=n.split(".");return r==null?i:parseInt(r[0])>=5?(0,x.add)(i,"1"):i}const g=n=>console.log(JSON.stringify(n,null,2));function T(n,i){if(typeof n!="object"||typeof i!="object"||n==null||i==null)return n===i;const r=Array.isArray(n),c=Array.isArray(i);if(r!==c)return!1;if(r){if(n.length!==i.length)return!1;for(let u=0;u<n.length;++u)if(!T(n[u],i[u]))return!1;return!0}const d=Object.getOwnPropertyNames(n).filter(u=>n[u]!==void 0),p=Object.getOwnPropertyNames(i).filter(u=>i[u]!==void 0);if(d.length!==p.length)return!1;for(const u of d)if(!Object.prototype.hasOwnProperty.call(i,u)||!T(n[u],i[u]))return!1;return!0}const B=(n,i)=>{for(const r of Object.keys(n)){if(typeof n[r]=="object"){if(typeof i[r]!="object"||!B(n[r],i[r]))return!1;continue}if(n[r]!==i[r])return!1}return!0}}}]);
|
|
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(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}}}]);
|