edge-currency-accountbased 4.36.0 → 4.36.2

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 CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.36.2 (2025-02-12)
6
+
7
+ - fixed: (Solana) Fix priority fee for undefined `networkFeeOption`
8
+
9
+ ## 4.36.1 (2025-02-04)
10
+
11
+ - fixed: Correctly issue notifications for new incoming transactions.
12
+
13
+ ## 4.35.4 (2025-02-04)
14
+
15
+ - fixed: Correctly issue notifications for new incoming transactions.
16
+
5
17
  ## 4.36.0 (2025-01-30)
6
18
 
7
19
  - added: Add eip681 chainId detection
@@ -1 +1 @@
1
- "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8330],{26277:function(R,$,m){m.d($,{k:function(){return w}});var y=m(66001),E=m(82671),I=m(14483),p=m(36856),D=m(44276),S=m(42704);function N(u,t){var e;const{memos:n=[]}=u,{displayName:s,memoOptions:i=[],multipleMemos:l=!1}=t,{memoName:a="memo"}=(e=i[0])!=null?e:{};for(const r of n){const f=i.filter(k=>r.type===k.type);if(f.length<1)throw new Error(`${s} ${a}: cannot be type ${r.type}`);const T=f.map(k=>O(r,k)).find(k=>k!=null);if(T!=null)throw new Error(`${s} ${a}: ${T}`)}if(!l&&n.length>1)throw new Error(`${s} only supports one ${a}`)}function O(u,t){if(t.type==="text"&&t.maxLength!=null&&u.value.length>t.maxLength)return`cannot be longer than ${t.maxLength} characters`;if(t.type==="number"){const e=(0,S.HS)(p.ym)(u.value);if(e==null)return"is not a valid number";if(t.maxValue!=null&&(0,y.gt)(e,t.maxValue))return`cannot be greater than ${t.maxValue}`}if(t.type==="hex"){const e=(0,S.HS)(p.zU)(u.value);if(e==null)return"is not valid hexadecimal";if(t.maxBytes!=null&&e.length>t.maxBytes)return`cannot be longer than ${t.maxBytes} bytes`;if(t.minBytes!=null&&e.length<t.minBytes)return`cannot be shorter than ${t.minBytes} bytes`}}var K=Object.defineProperty,A=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,B=(u,t,e)=>t in u?K(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))_.call(t,e)&&B(u,e,t[e]);if(A)for(var e of A(t))H.call(t,e)&&B(u,e,t[e]);return u},h=(u,t,e)=>new Promise((n,s)=>{var i=r=>{try{a(e.next(r))}catch(f){s(f)}},l=r=>{try{a(e.throw(r))}catch(f){s(f)}},a=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,l);a((e=e.apply(u,t)).next())});const c=1e4,d=2500,o=3600*24;class w{constructor(t,e,n,s){this.allTokens=[],this.allTokensMap={},this.builtinTokens={},this.customTokens={},this.enabledTokenIds=[],this.enabledTokens=[];const{builtinTokens:i,currencyInfo:l}=t,{callbacks:a,customTokens:r,enabledTokenIds:f,log:T,walletLocalDisklet:k}=s;this.tools=e,this.log=T,this.warn=(g,v)=>this.log.warn(g+(0,D.Jo)(v)),this.error=(g,v)=>this.log.error(g+(0,D.Jo)(v)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.seenTxCheckpoint=s.seenTxCheckpoint,this.transactionEvents=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=n,this.walletId=n.id,this.currencyInfo=l,this.timers={},this.otherData=void 0,this.minimumAddressBalance="0";const{currencyCode:L}=l;this.transactionList[L]=[],this.txIdMap[L]={},this.txIdList[L]=[],this.builtinTokens=i,this.changeCustomTokensSync(r),this.changeEnabledTokenIdsSync(f),s.userSettings!=null?this.currentSettings=s.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=a,this.walletLocalDisklet=k,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=n.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}`),this.checkBalances=(g,v)=>{var M,x;const{nativeAmount:C,parentNetworkFee:b}=g,U=this.currencyInfo.currencyCode,J=v!=null?this.allTokensMap[v].currencyCode:U,F=(M=this.walletLocalData.totalBalances[J])!=null?M:"0",W=U,V=(x=this.walletLocalData.totalBalances[W])!=null?x:"0";if((0,y.gt)((0,y.abs)(C),F))throw new E.k5({tokenId:v});if(b!=null&&(0,y.gt)(b,V))throw new E.k5({networkFee:b,tokenId:null})},this.makeEdgeTransactionAmounts=(g,v,M)=>{let x=`-${g}`,C=v,b;return M!=null?(b=C,C="0"):x=(0,y.sub)(x,C),{nativeAmount:x,networkFee:C,parentNetworkFee:b}}}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,y.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const n of t.ourReceiveAddresses)n===this.walletLocalData.publicKey&&(e=!1);return e}isTransactionNew(t){const e=this.getTxCheckpoint(t);return this.seenTxCheckpoint!=null&&e!==this.seenTxCheckpoint?this.selectSeenTxCheckpoint(e,this.seenTxCheckpoint)===e:!1}setOtherData(t){}loadTransactions(){return h(this,null,function*(){var t;if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const e=this.walletLocalDisklet;let n;try{const a=yield e.getText(p._6);n=JSON.parse(a)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield e.setText(p._6,JSON.stringify(this.txIdList))}let s;try{const a=yield e.getText(p.wV);s=JSON.parse(a)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield e.setText(p.wV,JSON.stringify(this.txIdMap))}let i;try{const a=yield e.getText(p.Kw);i=JSON.parse(a)}catch(a){a.code==="ENOENT"||((t=a.message)==null?void 0:t.includes("No such file"))===!0?(this.log("Could not load transactionList file. Failure is ok on new device"),yield e.setText(p.Kw,JSON.stringify(this.transactionList))):this.log.crash(a,{currencyPluginId:this.currencyInfo.pluginId})}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=i!=null?i:this.transactionList,this.txIdList=n!=null?n:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;else if(i!=null)for(const a of Object.keys(i))for(const r of i[a])this.addTransaction(a,r);for(const a in this.transactionList)this.walletLocalData.numTransactions[a]=this.transactionList[a].length})}loadEngine(){return h(this,null,function*(){var t;const{walletInfo:e}=this,{currencyCode:n}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const s=this.walletLocalDisklet;try{const i=yield s.getText(p.e1);this.walletLocalData=(0,p.TS)(JSON.parse(i)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,p.TS)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield s.setText(p.e1,JSON.stringify(this.walletLocalData))}catch(l){throw this.error("Error writing to localDataStore. Engine not started: ",l),l}}this.setOtherData((t=this.walletLocalData.otherData)!=null?t:{}),this.walletLocalDataDirty=!(0,D.AP)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[n]=0,this.tokenCheckTransactionsStatus[n]=0,this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback()})}findTransaction(t,e){if(this.txIdMap[t]!=null){const n=this.txIdMap[t][e];if(typeof n=="number")return n}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,n){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=n!=null?n:Math.round(Date.now()/1e3));const s=(0,D.Qh)(e.txid),i=this.findTransaction(t,s);let l=!1;if(i===-1){if(this.isSpendTx(e)&&e.blockHeight===0&&(this.walletLocalData.numUnconfirmedSpendTxs++,this.walletLocalDataDirty=!0),l=!0,typeof this.transactionList[t]>"u")this.transactionList[t]=[];else if(this.transactionList[t].length>=d)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0;const a=this.isTransactionNew(e);this.transactionEvents.push({isNew:a,transaction:e}),a&&this.updateSeenTxCheckpoint(this.getTxCheckpoint(e)),this.warn(`addTransaction new tx: ${e.txid}`)}else{const r=this.transactionList[t][i],{otherParams:f={}}=r,{otherParams:T={}}=e;(r.blockHeight<e.blockHeight||r.blockHeight===0&&e.blockHeight<0||r.blockHeight===e.blockHeight&&(r.networkFee!==e.networkFee||r.nativeAmount!==e.nativeAmount||f.lastSeenTime!==T.lastSeenTime||r.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&r.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,r.date!==e.date&&(l=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,i))}l&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let n=0;for(const s of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,D.Qh)(s.txid)]=n,e.push((0,D.Qh)(s.txid)),n++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>o&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[]))}checkDroppedTransactions(t){let e=0;for(const n in this.transactionList)for(let s=0;s<this.transactionList[n].length;s++){const i=this.transactionList[n][s];if(i.blockHeight===0){const{otherParams:l={}}=i,a=l.lastSeenTime;t-a>o?(i.blockHeight=-1,i.nativeAmount="0",this.transactionEvents.push({isNew:!1,transaction:i})):this.isSpendTx(i)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];if(this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),n==null||!(0,y.eq)(e,n)){this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`);const s=(0,I.jE)(t,this.currencyInfo.currencyCode,this.allTokensMap);if(s===void 0)return;this.currencyEngineCallbacks.onTokenBalanceChanged(s,e)}this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,n){this.transactionList[t][n]=e,this.transactionListDirty=!0,this.transactionEvents.push({isNew:!1,transaction:e}),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return h(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let n=JSON.stringify(this.transactionList);e.push(t.setText(p.Kw,n).catch(s=>{this.error("Error saving transactionList ",s)})),n=JSON.stringify(this.txIdList),e.push(t.setText(p._6,n).catch(s=>{this.error("Error saving txIdList ",s)})),n=JSON.stringify(this.txIdMap),e.push(t.setText(p.wV,n).catch(s=>{this.error("Error saving txIdMap ",s)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const n=JSON.stringify(this.walletLocalData);yield t.setText(p.e1,n).then(()=>{this.walletLocalDataDirty=!1}).catch(s=>{this.error("Error saving walletLocalData ",s)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{const n=(0,I.jE)(e,this.currencyInfo.currencyCode,this.allTokensMap);if(n===void 0)continue;this.currencyEngineCallbacks.onTokenBalanceChanged(n,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(n){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,n)}}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 h(this,null,function*(){try{yield this[t]()}catch(n){this.error(`Error in Loop: ${t} `,n)}return this.engineOn&&(this.timers[t]=setTimeout(()=>{this.engineOn&&this.addToLoop(t,e).catch(n=>this.log(n.message))},e)),!0})}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}getTxCheckpoint(t){return t.blockHeight.toString()}selectSeenTxCheckpoint(t,e){if(t!=null){if(e==null)return t;const n=parseInt(t),s=parseInt(e);if(n>s)return t}return e}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const n=this.enabledTokens,s=1/n.length;let i=0,l=0;for(const a of n){const r=(t=this.tokenCheckBalanceStatus[a])!=null?t:0,f=(e=this.tokenCheckTransactionsStatus[a])!=null?e:0;i+=(r+f)/2*s,r===1&&f===1&&l++}l===n.length&&(i=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${i}`),this.currencyEngineCallbacks.onAddressesChecked(i),this.updateSeenTxCheckpoint()}updateSeenTxCheckpoint(t){this.seenTxCheckpoint=this.selectSeenTxCheckpoint(t,this.seenTxCheckpoint),this.addressesChecked&&this.seenTxCheckpoint!=null&&this.currencyEngineCallbacks.onSeenTxCheckpoint(this.seenTxCheckpoint)}clearBlockchainCache(){return h(this,null,function*(){this.walletLocalData=(0,p.TS)({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()})}startEngine(){return h(this,null,function*(){this.addToLoop("saveWalletLoop",c).catch(()=>{})})}killEngine(){return h(this,null,function*(){this.engineOn=!1;for(const t in this.timers)clearTimeout(this.timers[t]);this.timers={}})}changeUserSettings(t){return h(this,null,function*(){this.currentSettings=t})}getBlockHeight(){return this.walletLocalData.blockHeight}changeCustomTokensSync(t){this.customTokens={};for(const e of Object.keys(t)){const n=t[e];try{(0,I.k9)(n)}catch{this.log.warn(`Dropping custom token "${n.currencyCode}" / ${e}`);continue}this.customTokens[e]=n}this.allTokensMap=P(P({},this.customTokens),this.builtinTokens),this.allTokens=(0,I.yQ)(this.allTokensMap)}changeCustomTokens(t){return h(this,null,function*(){this.changeCustomTokensSync(t)})}changeEnabledTokenIdsSync(t){const{currencyCode:e}=this.currencyInfo,n=new Set,s=new Set;for(const i of t){const l=this.allTokensMap[i];l!=null&&(n.add(l.currencyCode),s.add(i))}this.enabledTokens=[...n,e],this.enabledTokenIds=[...s]}changeEnabledTokenIds(t){return h(this,null,function*(){this.changeEnabledTokenIdsSync(t)})}getBalance(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e],s=this.walletLocalData.totalBalances[n];return s==null?"0":s}getNumTransactions(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e];return this.walletLocalData.numTransactions[n]==null?0:this.walletLocalData.numTransactions[n]}getTransactions(t){return h(this,null,function*(){const{startDate:e,endDate:n,tokenId:s}=t,{currencyCode:i}=s==null?this.currencyInfo:this.allTokensMap[s];return yield this.loadTransactions(),this.transactionList[i]==null?[]:this.transactionList[i].filter(a=>new Date(a.date)>=(e!=null?e:new Date(0))&&new Date(a.date)<=(n!=null?n:new Date))})}getFreshAddress(t){return h(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return h(this,null,function*(){})}isAddressUsed(t){return h(this,null,function*(){return!1})}dumpData(){return h(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,n,s;const{skipChecks:i=!1,tokenId:l}=t;N(t,this.currencyInfo);for(const k of t.spendTargets)if(!i&&k.publicAddress===this.walletLocalData.publicKey)throw new E.gw;if(l!=null&&!this.enabledTokenIds.includes(l))throw new Error("Error: Token not enabled");const{currencyCode:a}=l==null?this.currencyInfo:this.allTokensMap[l],r=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",f={};for(const k of t.spendTargets){const{nativeAmount:L}=k;L!=null&&(f[a]=(n=f[a])!=null?n:"0",f[a]=(0,y.add)(f[a],L))}for(const[k,L]of Object.entries(f)){const g=(s=this.walletLocalData.totalBalances[k])!=null?s:"0";if(!i&&(0,y.lt)(g,L))throw new E.k5({tokenId:l})}const T=(0,D._r)(a,this.currencyInfo,this.allTokensMap);if(T==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:r,currencyCode:a,denom:T,skipChecks:i}}checkRecipientMinimumBalance(t,e,n){return h(this,null,function*(){if((0,y.gte)(e,this.minimumAddressBalance))return;const s=yield t(n);if((0,y.lt)((0,y.add)(e,s),this.minimumAddressBalance)){const i=this.currencyInfo.denominations.find(a=>a.name===this.currencyInfo.currencyCode);if(i==null)throw new Error("Unknown denom");const l=(0,y.div)(this.minimumAddressBalance,i.multiplier);throw new Error(`Recipient address not activated. A minimum ${l} ${this.currencyInfo.currencyCode} transfer is required to send funds to this address`)}})}saveTx(t){return h(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionEvents.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,D.T5)(e.transaction)}`)),this.transactionEvents.length>0&&this.currencyEngineCallbacks.onTransactions(this.transactionEvents)})}resyncBlockchain(){return h(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return h(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return h(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return h(this,null,function*(){throw new Error("not implemented")})}}},96542:function(R,$,m){m.d($,{m:function(){return h},x:function(){return P}});var y=m(66001),E=m.n(y),I=m(63054),p=m(61160),D=m.n(p),S=m(44276),N=Object.defineProperty,O=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,_=(c,d,o)=>d in c?N(c,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[d]=o,H=(c,d)=>{for(var o in d||(d={}))K.call(d,o)&&_(c,o,d[o]);if(O)for(var o of O(d))A.call(d,o)&&_(c,o,d[o]);return c},B=(c,d,o)=>new Promise((w,u)=>{var t=s=>{try{n(o.next(s))}catch(i){u(i)}},e=s=>{try{n(o.throw(s))}catch(i){u(i)}},n=s=>s.done?w(s.value):Promise.resolve(s.value).then(t,e);n((o=o.apply(c,d)).next())});function P(c){return B(this,null,function*(){const{currencyInfo:d,uri:o,networks:w,builtinTokens:u,customTokens:t=[],testPrivateKeys:e}=c;let{currencyCode:n}=c;const s=H({},D()(o,{},!0)),i=o.startsWith(`${d.pluginId}://`);if(s.protocol!=null&&(s.protocol=s.protocol.replace(":","")),s.protocol!=null&&s.protocol!==""&&!w[s.protocol])throw new Error(`Uri protocol '${s.protocol}' is not supported for ${d.pluginId}.`);if(s.host===""&&s.pathname==="")throw new Error("Path and host not found in uri.");const a={publicAddress:s.host!==""?s.host:s.pathname.split("/")[0]},r=s.query.label,f=s.query.message,T=s.query.category;(r!=null||f!=null||T!=null||i)&&(a.metadata={},a.metadata.name=r,a.metadata.notes=f,a.metadata.category=T,a.metadata.gateway=i!=null?i:!1);const k=s.query.amount;if(k!=null&&typeof k=="string"){n==null&&(n=d.currencyCode);const L=(0,S.FQ)(n!=null?n:"",d,t,u);if(L==null)throw new Error("InternalErrorInvalidCurrencyCode");let g=(0,y.mul)(k,L.multiplier);g=(0,y.toFixed)(g,0,0),a.nativeAmount=g,a.currencyCode=n}if(e!=null)try{yield e(o),a.privateKeys=[o],a.publicAddress=void 0}catch{}return{edgeParsedUri:a,parsedUri:s}})}function h(c,d,o){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(o==null&&c.label==null&&c.message==null)return c.publicAddress;{let w="";o!=null&&(w+="amount="+o+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(w+="label="+c.label+"&"),typeof c.message=="string"&&(w+="message="+c.message+"&")),w=w.substr(0,w.length-1);const u={scheme:d,path:c.publicAddress,query:w};return(0,I.lK)(u)}}}}]);
1
+ "use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[8330],{26277:function(R,$,m){m.d($,{k:function(){return w}});var y=m(66001),S=m(82671),I=m(14483),p=m(36856),D=m(44276),E=m(42704);function N(u,t){var e;const{memos:n=[]}=u,{displayName:s,memoOptions:i=[],multipleMemos:r=!1}=t,{memoName:a="memo"}=(e=i[0])!=null?e:{};for(const l of n){const f=i.filter(k=>l.type===k.type);if(f.length<1)throw new Error(`${s} ${a}: cannot be type ${l.type}`);const T=f.map(k=>O(l,k)).find(k=>k!=null);if(T!=null)throw new Error(`${s} ${a}: ${T}`)}if(!r&&n.length>1)throw new Error(`${s} only supports one ${a}`)}function O(u,t){if(t.type==="text"&&t.maxLength!=null&&u.value.length>t.maxLength)return`cannot be longer than ${t.maxLength} characters`;if(t.type==="number"){const e=(0,E.HS)(p.ym)(u.value);if(e==null)return"is not a valid number";if(t.maxValue!=null&&(0,y.gt)(e,t.maxValue))return`cannot be greater than ${t.maxValue}`}if(t.type==="hex"){const e=(0,E.HS)(p.zU)(u.value);if(e==null)return"is not valid hexadecimal";if(t.maxBytes!=null&&e.length>t.maxBytes)return`cannot be longer than ${t.maxBytes} bytes`;if(t.minBytes!=null&&e.length<t.minBytes)return`cannot be shorter than ${t.minBytes} bytes`}}var K=Object.defineProperty,A=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,B=(u,t,e)=>t in u?K(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))_.call(t,e)&&B(u,e,t[e]);if(A)for(var e of A(t))H.call(t,e)&&B(u,e,t[e]);return u},h=(u,t,e)=>new Promise((n,s)=>{var i=l=>{try{a(e.next(l))}catch(f){s(f)}},r=l=>{try{a(e.throw(l))}catch(f){s(f)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(i,r);a((e=e.apply(u,t)).next())});const c=1e4,d=2500,o=3600*24;class w{constructor(t,e,n,s){this.allTokens=[],this.allTokensMap={},this.builtinTokens={},this.customTokens={},this.enabledTokenIds=[],this.enabledTokens=[];const{builtinTokens:i,currencyInfo:r}=t,{callbacks:a,customTokens:l,enabledTokenIds:f,log:T,walletLocalDisklet:k}=s;this.tools=e,this.log=T,this.warn=(g,v)=>this.log.warn(g+(0,D.Jo)(v)),this.error=(g,v)=>this.log.error(g+(0,D.Jo)(v)),this.engineOn=!1,this.addressesChecked=!1,this.tokenCheckBalanceStatus={},this.tokenCheckTransactionsStatus={},this.walletLocalDataDirty=!1,this.seenTxCheckpoint=s.seenTxCheckpoint,this.transactionEvents=[],this.transactionList={},this.transactionListDirty=!1,this.transactionsLoaded=!1,this.txIdMap={},this.txIdList={},this.walletInfo=n,this.walletId=n.id,this.currencyInfo=r,this.timers={},this.otherData=void 0,this.minimumAddressBalance="0";const{currencyCode:L}=r;this.transactionList[L]=[],this.txIdMap[L]={},this.txIdList[L]=[],this.builtinTokens=i,this.changeCustomTokensSync(l),this.changeEnabledTokenIdsSync(f),s.userSettings!=null?this.currentSettings=s.userSettings:this.currentSettings=this.currencyInfo.defaultSettings,this.currencyEngineCallbacks=a,this.walletLocalDisklet=k,typeof this.walletInfo.keys.publicKey!="string"&&(this.walletInfo.keys.publicKey=n.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}`),this.checkBalances=(g,v)=>{var M,x;const{nativeAmount:C,parentNetworkFee:b}=g,U=this.currencyInfo.currencyCode,J=v!=null?this.allTokensMap[v].currencyCode:U,F=(M=this.walletLocalData.totalBalances[J])!=null?M:"0",W=U,V=(x=this.walletLocalData.totalBalances[W])!=null?x:"0";if((0,y.gt)((0,y.abs)(C),F))throw new S.k5({tokenId:v});if(b!=null&&(0,y.gt)(b,V))throw new S.k5({networkFee:b,tokenId:null})},this.makeEdgeTransactionAmounts=(g,v,M)=>{let x=`-${g}`,C=v,b;return M!=null?(b=C,C="0"):x=(0,y.sub)(x,C),{nativeAmount:x,networkFee:C,parentNetworkFee:b}}}isSpendTx(t){if(t.nativeAmount!==""){if(t.nativeAmount.slice(0,1)==="-")return!0;if((0,y.gt)(t.nativeAmount,"0"))return!1}let e=!0;if(t.ourReceiveAddresses.length>0)for(const n of t.ourReceiveAddresses)n===this.walletLocalData.publicKey&&(e=!1);return e}isTransactionNew(t){const e=this.getTxCheckpoint(t);return this.seenTxCheckpoint!=null&&e!==this.seenTxCheckpoint?this.selectSeenTxCheckpoint(e,this.seenTxCheckpoint)===e:!1}setOtherData(t){}loadTransactions(){return h(this,null,function*(){var t;if(this.transactionsLoaded){this.log("Transactions already loaded");return}this.transactionsLoaded=!0;const e=this.walletLocalDisklet;let n;try{const a=yield e.getText(p._6);n=JSON.parse(a)}catch{this.log("Could not load txidList file. Failure is ok on new device"),yield e.setText(p._6,JSON.stringify(this.txIdList))}let s;try{const a=yield e.getText(p.wV);s=JSON.parse(a)}catch{this.log("Could not load txidMap file. Failure is ok on new device"),yield e.setText(p.wV,JSON.stringify(this.txIdMap))}let i;try{const a=yield e.getText(p.Kw);i=JSON.parse(a)}catch(a){a.code==="ENOENT"||((t=a.message)==null?void 0:t.includes("No such file"))===!0?(this.log("Could not load transactionList file. Failure is ok on new device"),yield e.setText(p.Kw,JSON.stringify(this.transactionList))):this.log.crash(a,{currencyPluginId:this.currencyInfo.pluginId})}let r=!0;for(const a of Object.keys(this.transactionList))if(this.transactionList[a]!=null&&this.transactionList[a].length>0){r=!1;break}if(r){this.transactionList=i!=null?i:this.transactionList,this.txIdList=n!=null?n:this.txIdList,this.txIdMap=s!=null?s:this.txIdMap;for(const a of Object.keys(this.transactionList))for(const l of this.transactionList[a])this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.highestSeenCheckpoint,this.getTxCheckpoint(l))}else if(i!=null)for(const a of Object.keys(i))for(const l of i[a])this.addTransaction(a,l);for(const a in this.transactionList)this.walletLocalData.numTransactions[a]=this.transactionList[a].length})}loadEngine(){return h(this,null,function*(){var t;const{walletInfo:e}=this,{currencyCode:n}=this.currencyInfo;this.walletInfo.keys.publicKey==null&&(this.walletInfo.keys.publicKey=e.keys.publicKey);const s=this.walletLocalDisklet;try{const i=yield s.getText(p.e1);this.walletLocalData=(0,p.TS)(JSON.parse(i)),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey}catch{try{this.log("No walletLocalData setup yet: Failure is ok"),this.walletLocalData=(0,p.TS)({}),this.walletLocalData.publicKey=this.walletInfo.keys.publicKey,yield s.setText(p.e1,JSON.stringify(this.walletLocalData))}catch(r){throw this.error("Error writing to localDataStore. Engine not started: ",r),r}}this.setOtherData((t=this.walletLocalData.otherData)!=null?t:{}),this.walletLocalDataDirty=!(0,D.AP)(this.otherData,this.walletLocalData.otherData),this.tokenCheckBalanceStatus[n]=0,this.tokenCheckTransactionsStatus[n]=0,this.doInitialBalanceCallback(),this.doInitialUnactivatedTokenIdsCallback(),this.seenTxCheckpoint==null&&(yield this.loadTransactions(),this.highestSeenCheckpoint==null&&(this.highestSeenCheckpoint="0"))})}findTransaction(t,e){if(this.txIdMap[t]!=null){const n=this.txIdMap[t][e];if(typeof n=="number")return n}return-1}sortTxByDate(t,e){return e.date-t.date}addTransaction(t,e,n){this.log("executing addTransaction: ",e.txid),e.otherParams==null&&(e.otherParams={}),e.blockHeight<1&&(e.otherParams.lastSeenTime=n!=null?n:Math.round(Date.now()/1e3));const s=(0,D.Qh)(e.txid),i=this.findTransaction(t,s);let r=!1;if(i===-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>=d)return;this.transactionList[t].push(e),this.walletLocalData.numTransactions[t]=this.transactionList[t].length,this.walletLocalDataDirty=!0,this.transactionListDirty=!0;const a=this.isTransactionNew(e);this.transactionEvents.push({isNew:a,transaction:e}),this.highestSeenCheckpoint=this.selectSeenTxCheckpoint(this.getTxCheckpoint(e),this.highestSeenCheckpoint),this.updateSeenTxCheckpoint(),this.warn(`addTransaction new tx: ${e.txid}`)}else{const l=this.transactionList[t][i],{otherParams:f={}}=l,{otherParams:T={}}=e;(l.blockHeight<e.blockHeight||l.blockHeight===0&&e.blockHeight<0||l.blockHeight===e.blockHeight&&(l.networkFee!==e.networkFee||l.nativeAmount!==e.nativeAmount||f.lastSeenTime!==T.lastSeenTime||l.date!==e.date))&&(this.isSpendTx(e)&&e.blockHeight!==0&&l.blockHeight===0&&this.walletLocalData.numUnconfirmedSpendTxs--,l.date!==e.date&&(r=!0),this.warn(`addTransaction: update ${e.txid} height:${e.blockHeight}`),this.walletLocalDataDirty=!0,this.updateTransaction(t,e,i))}r&&this.sortTransactions(t)}sortTransactions(t){this.transactionList[t].sort(this.sortTxByDate);const e=[];let n=0;for(const s of this.transactionList[t])this.txIdMap[t]==null&&(this.txIdMap[t]={}),this.txIdMap[t][(0,D.Qh)(s.txid)]=n,e.push((0,D.Qh)(s.txid)),n++;this.txIdList[t]=e}checkDroppedTransactionsThrottled(){const t=Date.now()/1e3;t-this.walletLocalData.lastCheckedTxsDropped>o&&(this.checkDroppedTransactions(t),this.walletLocalData.lastCheckedTxsDropped=t,this.walletLocalDataDirty=!0,this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[]))}checkDroppedTransactions(t){let e=0;for(const n in this.transactionList)for(let s=0;s<this.transactionList[n].length;s++){const i=this.transactionList[n][s];if(i.blockHeight===0){const{otherParams:r={}}=i,a=r.lastSeenTime;t-a>o?(i.blockHeight=-1,i.nativeAmount="0",this.transactionEvents.push({isNew:!1,transaction:i})):this.isSpendTx(i)&&e++}}this.walletLocalData.numUnconfirmedSpendTxs=e,this.walletLocalDataDirty=!0}updateBalance(t,e){const n=this.walletLocalData.totalBalances[t];if(this.walletLocalData.totalBalances[t]==null&&(this.walletLocalData.totalBalances[t]="0"),n==null||!(0,y.eq)(e,n)){this.walletLocalData.totalBalances[t]=e,this.walletLocalDataDirty=!0,this.warn(`${t}: token Address balance: ${e}`);const s=(0,I.jE)(t,this.currencyInfo.currencyCode,this.allTokensMap);if(s===void 0)return;this.currencyEngineCallbacks.onTokenBalanceChanged(s,e)}this.tokenCheckBalanceStatus[t]=1,this.updateOnAddressesChecked()}updateTransaction(t,e,n){this.transactionList[t][n]=e,this.transactionListDirty=!0,this.transactionEvents.push({isNew:!1,transaction:e}),this.warn(`updateTransaction: ${e.txid}`)}saveWalletLoop(){return h(this,null,function*(){const t=this.walletLocalDisklet,e=[];if(this.transactionListDirty){yield this.loadTransactions(),this.log("transactionListDirty. Saving...");let n=JSON.stringify(this.transactionList);e.push(t.setText(p.Kw,n).catch(s=>{this.error("Error saving transactionList ",s)})),n=JSON.stringify(this.txIdList),e.push(t.setText(p._6,n).catch(s=>{this.error("Error saving txIdList ",s)})),n=JSON.stringify(this.txIdMap),e.push(t.setText(p.wV,n).catch(s=>{this.error("Error saving txIdMap ",s)})),yield Promise.all(e),this.transactionListDirty=!1}if(this.walletLocalDataDirty){this.log("walletLocalDataDirty. Saving..."),this.walletLocalData.otherData=this.otherData;const n=JSON.stringify(this.walletLocalData);yield t.setText(p.e1,n).then(()=>{this.walletLocalDataDirty=!1}).catch(s=>{this.error("Error saving walletLocalData ",s)})}})}doInitialBalanceCallback(){var t;for(const e of this.enabledTokens)try{const n=(0,I.jE)(e,this.currencyInfo.currencyCode,this.allTokensMap);if(n===void 0)continue;this.currencyEngineCallbacks.onTokenBalanceChanged(n,(t=this.walletLocalData.totalBalances[e])!=null?t:"0")}catch(n){this.error(`doInitialBalanceCallback Error for currencyCode ${e}`,n)}}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 h(this,null,function*(){try{yield this[t]()}catch(n){this.error(`Error in Loop: ${t} `,n)}return this.engineOn&&(this.timers[t]=setTimeout(()=>{this.engineOn&&this.addToLoop(t,e).catch(n=>this.log(n.message))},e)),!0})}getTokenInfo(t){return this.allTokens.find(e=>e.currencyCode===t)}getTxCheckpoint(t){return t.blockHeight.toString()}selectSeenTxCheckpoint(t,e){if(t!=null){if(e==null)return t;const n=parseInt(t),s=parseInt(e);if(n>s)return t}return e}updateOnAddressesChecked(){var t,e;if(this.addressesChecked)return;const n=this.enabledTokens,s=1/n.length;let i=0,r=0;for(const a of n){const l=(t=this.tokenCheckBalanceStatus[a])!=null?t:0,f=(e=this.tokenCheckTransactionsStatus[a])!=null?e:0;i+=(l+f)/2*s,l===1&&f===1&&r++}r===n.length&&(i=1,this.addressesChecked=!0),this.log(`${this.walletId} syncRatio of: ${i}`),this.currencyEngineCallbacks.onAddressesChecked(i),this.updateSeenTxCheckpoint()}updateSeenTxCheckpoint(){this.addressesChecked&&this.highestSeenCheckpoint!=null&&this.highestSeenCheckpoint!==this.seenTxCheckpoint&&(this.seenTxCheckpoint=this.highestSeenCheckpoint,this.currencyEngineCallbacks.onSeenTxCheckpoint(this.seenTxCheckpoint))}clearBlockchainCache(){return h(this,null,function*(){this.walletLocalData=(0,p.TS)({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()})}startEngine(){return h(this,null,function*(){this.addToLoop("saveWalletLoop",c).catch(()=>{})})}killEngine(){return h(this,null,function*(){this.engineOn=!1;for(const t in this.timers)clearTimeout(this.timers[t]);this.timers={}})}changeUserSettings(t){return h(this,null,function*(){this.currentSettings=t})}getBlockHeight(){return this.walletLocalData.blockHeight}changeCustomTokensSync(t){this.customTokens={};for(const e of Object.keys(t)){const n=t[e];try{(0,I.k9)(n)}catch{this.log.warn(`Dropping custom token "${n.currencyCode}" / ${e}`);continue}this.customTokens[e]=n}this.allTokensMap=P(P({},this.customTokens),this.builtinTokens),this.allTokens=(0,I.yQ)(this.allTokensMap)}changeCustomTokens(t){return h(this,null,function*(){this.changeCustomTokensSync(t)})}changeEnabledTokenIdsSync(t){const{currencyCode:e}=this.currencyInfo,n=new Set,s=new Set;for(const i of t){const r=this.allTokensMap[i];r!=null&&(n.add(r.currencyCode),s.add(i))}this.enabledTokens=[...n,e],this.enabledTokenIds=[...s]}changeEnabledTokenIds(t){return h(this,null,function*(){this.changeEnabledTokenIdsSync(t)})}getBalance(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e],s=this.walletLocalData.totalBalances[n];return s==null?"0":s}getNumTransactions(t){const{tokenId:e}=t,{currencyCode:n}=e==null?this.currencyInfo:this.allTokensMap[e];return this.walletLocalData.numTransactions[n]==null?0:this.walletLocalData.numTransactions[n]}getTransactions(t){return h(this,null,function*(){const{startDate:e,endDate:n,tokenId:s}=t,{currencyCode:i}=s==null?this.currencyInfo:this.allTokensMap[s];return yield this.loadTransactions(),this.transactionList[i]==null?[]:this.transactionList[i].filter(a=>new Date(a.date)>=(e!=null?e:new Date(0))&&new Date(a.date)<=(n!=null?n:new Date))})}getFreshAddress(t){return h(this,null,function*(){return{publicAddress:this.walletLocalData.publicKey}})}addGapLimitAddresses(t){return h(this,null,function*(){})}isAddressUsed(t){return h(this,null,function*(){return!1})}dumpData(){return h(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,n,s;const{skipChecks:i=!1,tokenId:r}=t;N(t,this.currencyInfo);for(const k of t.spendTargets)if(!i&&k.publicAddress===this.walletLocalData.publicKey)throw new S.gw;if(r!=null&&!this.enabledTokenIds.includes(r))throw new Error("Error: Token not enabled");const{currencyCode:a}=r==null?this.currencyInfo:this.allTokensMap[r],l=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",f={};for(const k of t.spendTargets){const{nativeAmount:L}=k;L!=null&&(f[a]=(n=f[a])!=null?n:"0",f[a]=(0,y.add)(f[a],L))}for(const[k,L]of Object.entries(f)){const g=(s=this.walletLocalData.totalBalances[k])!=null?s:"0";if(!i&&(0,y.lt)(g,L))throw new S.k5({tokenId:r})}const T=(0,D._r)(a,this.currencyInfo,this.allTokensMap);if(T==null)throw new Error("InternalErrorInvalidCurrencyCode");return{edgeSpendInfo:t,nativeBalance:l,currencyCode:a,denom:T,skipChecks:i}}checkRecipientMinimumBalance(t,e,n){return h(this,null,function*(){if((0,y.gte)(e,this.minimumAddressBalance))return;const s=yield t(n);if((0,y.lt)((0,y.add)(e,s),this.minimumAddressBalance)){const i=this.currencyInfo.denominations.find(a=>a.name===this.currencyInfo.currencyCode);if(i==null)throw new Error("Unknown denom");const r=(0,y.div)(this.minimumAddressBalance,i.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 h(this,null,function*(){this.addTransaction(t.currencyCode,t),this.transactionEvents.forEach(e=>this.warn(`executing back in saveTx and this.transactionsChangedArray is: ${(0,D.T5)(e.transaction)}`)),this.transactionEvents.length>0&&this.currencyEngineCallbacks.onTransactions(this.transactionEvents)})}resyncBlockchain(){return h(this,null,function*(){throw new Error("not implemented")})}makeSpend(t,e){return h(this,null,function*(){throw new Error("not implemented")})}signTx(t,e){return h(this,null,function*(){throw new Error("not implemented")})}broadcastTx(t,e){return h(this,null,function*(){throw new Error("not implemented")})}}},96542:function(R,$,m){m.d($,{m:function(){return h},x:function(){return P}});var y=m(66001),S=m.n(y),I=m(63054),p=m(61160),D=m.n(p),E=m(44276),N=Object.defineProperty,O=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,_=(c,d,o)=>d in c?N(c,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[d]=o,H=(c,d)=>{for(var o in d||(d={}))K.call(d,o)&&_(c,o,d[o]);if(O)for(var o of O(d))A.call(d,o)&&_(c,o,d[o]);return c},B=(c,d,o)=>new Promise((w,u)=>{var t=s=>{try{n(o.next(s))}catch(i){u(i)}},e=s=>{try{n(o.throw(s))}catch(i){u(i)}},n=s=>s.done?w(s.value):Promise.resolve(s.value).then(t,e);n((o=o.apply(c,d)).next())});function P(c){return B(this,null,function*(){const{currencyInfo:d,uri:o,networks:w,builtinTokens:u,customTokens:t=[],testPrivateKeys:e}=c;let{currencyCode:n}=c;const s=H({},D()(o,{},!0)),i=o.startsWith(`${d.pluginId}://`);if(s.protocol!=null&&(s.protocol=s.protocol.replace(":","")),s.protocol!=null&&s.protocol!==""&&!w[s.protocol])throw new Error(`Uri protocol '${s.protocol}' is not supported for ${d.pluginId}.`);if(s.host===""&&s.pathname==="")throw new Error("Path and host not found in uri.");const a={publicAddress:s.host!==""?s.host:s.pathname.split("/")[0]},l=s.query.label,f=s.query.message,T=s.query.category;(l!=null||f!=null||T!=null||i)&&(a.metadata={},a.metadata.name=l,a.metadata.notes=f,a.metadata.category=T,a.metadata.gateway=i!=null?i:!1);const k=s.query.amount;if(k!=null&&typeof k=="string"){n==null&&(n=d.currencyCode);const L=(0,E.FQ)(n!=null?n:"",d,t,u);if(L==null)throw new Error("InternalErrorInvalidCurrencyCode");let g=(0,y.mul)(k,L.multiplier);g=(0,y.toFixed)(g,0,0),a.nativeAmount=g,a.currencyCode=n}if(e!=null)try{yield e(o),a.privateKeys=[o],a.publicAddress=void 0}catch{}return{edgeParsedUri:a,parsedUri:s}})}function h(c,d,o){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(o==null&&c.label==null&&c.message==null)return c.publicAddress;{let w="";o!=null&&(w+="amount="+o+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(w+="label="+c.label+"&"),typeof c.message=="string"&&(w+="message="+c.message+"&")),w=w.substr(0,w.length-1);const u={scheme:d,path:c.publicAddress,query:w};return(0,I.lK)(u)}}}}]);
@@ -1,3 +1,3 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[6227],{62351:function(kt,U,y){"use strict";y.d(U,{Nn:function(){return W},Nt:function(){return z},fi:function(){return X},zp:function(){return V}});var v=y(14171),h=y(44276),M=(k,u,T)=>new Promise((E,A)=>{var N=S=>{try{F(T.next(S))}catch(P){A(P)}},B=S=>{try{F(T.throw(S))}catch(P){A(P)}},F=S=>S.done?E(S.value):Promise.resolve(S.value).then(N,B);F((T=T.apply(k,u)).next())});const nt=["https://info1.edge.app","https://info2.edge.app"];function Q(k,u,T){return M(this,arguments,function*(E,A,N,B=5e3,F=fetch){const S=E.map(P=>()=>M(this,null,function*(){const G=yield F(P+"/"+A,N);if(typeof G!="object"){const Y=`Invalid return value ${A} in ${P}`;throw console.log(Y),new Error(Y)}return G}));return yield(0,v.NN)(S,B)})}function V(k,u,T,E,A=5e3,N){return M(this,null,function*(){const B=yield Q((0,h.R3)(u),T,E,A,N);if(!B.ok){const P=yield B.text();throw console.error(P),new Error(`Error fetching ${T}: ${P}`)}const F=yield B.json();return k(F)})}function ot(k,u,T,E=5e3,A){return M(this,null,function*(){return yield Q((0,h.R3)(k),u,T,E,A)})}const W=(k,u,T,E)=>M(void 0,null,function*(){return yield ot(nt,k,u,T,E)}),z=k=>Object.keys(k).map(u=>{const T=k[u];return T==null?u:`${u}=${encodeURIComponent(T)}`}).join("&"),X=(k,u=5e3)=>k+Math.random()*u*2-u},17792:function(kt,U,y){"use strict";y.r(U),y.d(U,{SolanaTools:function(){return mt},isValidAddress:function(){return _},makeCurrencyEngine:function(){return St},makeCurrencyTools:function(){return Mt},updateInfoPayload:function(){return Nt}});var v=y(49196),h=y(66001),M=y(90749),nt=y(16763),Q=y.n(nt),V=y(48287),ot=y(37680),W=y(65828),z=y(14483),X=y(96542),k=y(44276),u=y(49841),T=y(8197),E=y(9646),A=y(76556),N=y(42704),B=y(82671),F=y(26277),S=y(62351),P=y(14171),G=y(48287).Buffer,Y=Object.defineProperty,gt=Object.defineProperties,wt=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertySymbols,vt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,Tt=Reflect.get,lt=(c,t,e)=>t in c?Y(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,ut=(c,t)=>{for(var e in t||(t={}))bt.call(t,e)&&lt(c,e,t[e]);if(at)for(var e of at(t))Pt.call(t,e)&&lt(c,e,t[e]);return c},It=(c,t)=>gt(c,wt(t)),ht=(c,t,e)=>Tt(vt(c),e,t),d=(c,t,e)=>new Promise((n,s)=>{var o=a=>{try{i(e.next(a))}catch(f){s(f)}},r=a=>{try{i(e.throw(a))}catch(f){s(f)}},i=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,r);i((e=e.apply(c,t)).next())});const Ct=(0,S.fi)(2e4),Bt=(0,S.fi)(2e4);class Z extends F.k{constructor(t,e,n,s){var o;super(t,e,n,s),this.lightMode=(o=s.lightMode)!=null?o:!1,this.networkInfo=t.networkInfo,this.chainCode=e.currencyInfo.currencyCode,this.fetch=(r,i)=>d(this,null,function*(){return yield t.io.fetch(r,It(ut({},i),{corsBypass:"always"}))}),this.feePerSignature="5000",this.getPriorityFee=(0,k.PP)(this.queryFee.bind(this),3e4),this.getRecentBlockhash=(0,k.PP)(this.queryBlockhash.bind(this),3e4),this.base58PublicKey=n.keys.publicKey,this.progressRatio=0,this.addressCache=new Map,this.getMinimumAddressBalance=(0,k.PP)(this.queryMinimumBalance.bind(this),3e4)}setOtherData(t){this.otherData=(0,u._$)(t)}fetchRpcBulk(t,e){return d(this,null,function*(){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(t.map((r,i)=>ut({jsonrpc:"2.0",id:i+1},r)))},o=(e!=null?e:this.networkInfo.rpcNodes).map(r=>()=>d(this,null,function*(){r=this.tools.rpcWithApiKey(r);const i=yield this.fetch(r,n);if(!i.ok)throw new Error(`fetchRpc ${n.method} failed error: ${i.status}`);return yield i.json()}));return yield(0,P.NN)(o)})}queryBalance(){return d(this,null,function*(){var t;try{const e=[{method:"getBalance",params:[this.base58PublicKey,{commitment:this.networkInfo.commitment}]},{method:"getTokenAccountsByOwner",params:[this.base58PublicKey,{programId:this.networkInfo.tokenPublicKey},{encoding:"jsonParsed"}]}],n=yield this.fetchRpcBulk(e),[s,o]=n,r=(0,u.GC)(s);this.updateBalance(this.chainCode,r.result.value.toString());const a=(0,u.Jl)(o).result.value.reduce((b,g)=>(b[g.account.data.parsed.info.mint]=g.account.data.parsed.info.tokenAmount.amount,b),{}),f=[];for(const b of Object.keys(this.allTokensMap)){const g=(t=a[b])!=null?t:"0";this.updateBalance(this.allTokensMap[b].currencyCode,g),(0,h.gt)(g,"0")&&f.push(b)}f.length>0&&this.currencyEngineCallbacks.onNewTokens(f)}catch(e){this.error(`Error checking ${this.chainCode} address balance`,e)}})}queryMinimumBalance(){return d(this,null,function*(){const t=this.tools.connections.map(n=>()=>d(this,null,function*(){return yield n.getMinimumBalanceForRentExemption(50)})),e=yield(0,P.NN)(t);return this.minimumAddressBalance=e.toString(),this.minimumAddressBalance})}queryFee(){return d(this,null,function*(){const t=this.tools.connections.map(o=>()=>d(this,null,function*(){return yield o.getRecentPrioritizationFees()})),e=yield(0,P.NN)(t);if(e.length===0)return this.networkInfo.basePriorityFee.toString();const n=e.map(o=>o.prioritizationFee),s=n.reduce((o,r)=>o+r,0)/n.length;return Math.max(Math.ceil(s),this.networkInfo.basePriorityFee).toString()})}queryBlockhash(){return d(this,null,function*(){const n=(yield Promise.allSettled(this.tools.connections.map(s=>d(this,null,function*(){return yield(0,P.wR)(s.getLatestBlockhash({commitment:"finalized"}),2e3)})))).filter(s=>s.status!=="rejected").sort((s,o)=>o.value.lastValidBlockHeight-s.value.lastValidBlockHeight)[0];if(n==null)throw new Error("No valid blockhash found");return{blockhash:n.value.blockhash,lastValidBlockHeight:n.value.lastValidBlockHeight}})}processSolanaTransaction(t,e,n,s){const o=[],{amount:r,networkFee:i,parentNetworkFee:a,tokenId:f=null}=e,b=f!=null?this.allTokensMap[f].currencyCode:this.chainCode;(0,h.gte)(r,"0")&&o.push(this.base58PublicKey);const g={blockHeight:t.slot,confirmations:"confirmed",currencyCode:b,date:n,isSend:r.startsWith("-"),memos:s.map(m=>({type:"text",value:m})),nativeAmount:r,networkFee:i,networkFees:[],ourReceiveAddresses:o,parentNetworkFee:a,signedTx:"",tokenId:f,txid:t.transaction.signatures[0],walletId:this.walletId};this.addTransaction(b,g)}parseTxAmounts(t,e){var n;const s=t.transaction.message.staticAccountKeys.findIndex(l=>l.equals(e));if(s<0||t.meta==null)return[];const{fee:o,preBalances:r,postBalances:i,preTokenBalances:a,postTokenBalances:f}=t.meta,b=a!=null?a:[],g=f!=null?f:[],m=t.transaction.message.staticAccountKeys.find(l=>l.equals(this.tools.tokenProgramPublicKey))!=null,K=o.toString();if(!m){const l=(i[s]-r[s]).toString(),C=(0,h.lt)(l,"0");return[{amount:l,networkFee:C?K:"0"}]}const w=l=>l.owner!==this.base58PublicKey||this.allTokensMap[l.mint]==null,p=new Map;for(const l of g)l==null||w(l)||p.set(l.mint,l.uiTokenAmount.amount);for(const l of b){if(l==null||w(l))continue;const C=(n=p.get(l.mint))!=null?n:"0";p.set(l.mint,(0,h.sub)(C,l.uiTokenAmount.amount))}const I=[];return p.forEach((l,C)=>{I.push({amount:l,networkFee:"0",parentNetworkFee:(0,h.lt)(l,"0")?K:void 0,tokenId:C})}),I}queryTransactions(){return d(this,null,function*(){const t=new v.J3(this.base58PublicKey),e=new Set([[this.currencyInfo.currencyCode,t]]);for(const n of this.enabledTokenIds){const s=(0,T.Xt)(new v.J3(n),t,!1,this.tools.tokenProgramPublicKey,new v.J3(this.networkInfo.associatedTokenPublicKey)),o=this.allTokensMap[n].currencyCode;e.add([o,s])}for(const n of e){const[s,o]=n;yield this.queryTransactionsInner(s,o)}})}queryTransactionsInner(t,e){return d(this,null,function*(){var n,s;let o;const r=this.otherData.newestTxid[t]!==""?this.otherData.newestTxid[t]:void 0;let i=[];try{for(;;){const g=this.tools.archiveConnections.map(K=>()=>d(this,null,function*(){return yield K.getSignaturesForAddress(e,{until:r,before:o,limit:this.networkInfo.txQueryLimit})})),m=yield(0,P.NN)(g);if(i=i.concat(m),m.length<this.networkInfo.txQueryLimit)break;o=m[this.networkInfo.txQueryLimit-1].signature}}catch(g){this.error("getTransactionSignatures failed with error: ",g);return}if(i.length===0){this.updateTxStatus(t,1);return}const a=50;let f=0;const b=i.map(g=>g.signature).reverse();for(let g=0;g<b.length;g+=a){const m=b.slice(g,g+a),K=this.tools.archiveConnections.map(p=>()=>d(this,null,function*(){return yield p.getTransactions(m,{commitment:this.networkInfo.commitment,maxSupportedTransactionVersion:0})})),w=yield(0,P.NN)(K);for(let p=0;p<w.length;p++){if(f++,((n=w[p].meta)==null?void 0:n.err)!=null)continue;const I=i.find(R=>R.signature===w[p].transaction.signatures[0]);if(I==null)continue;let l=(s=I.blockTime)!=null?s:w[p].blockTime;if(l==null){const R=this.tools.archiveConnections.map($=>()=>d(this,null,function*(){return yield $.getBlockTime(w[p].slot)})),D=yield(0,P.NN)(R),J=(0,N.HS)(u.Ft)(D);if(J==null)continue;l=J.result}const C=l,j=[];if(I.memo!=null){const R=/^\[\d+\]\s(.*)$/,D=I.memo.match(R);D!=null&&j.push(D[1])}this.parseTxAmounts(w[p],e).forEach(R=>{this.processSolanaTransaction(w[p],R,C,j)}),this.otherData.newestTxid[t]=w[p].transaction.signatures[0];const O=1-f/i.length;O!==this.progressRatio&&(Math.abs(O-this.progressRatio)>.25||O===1)&&(this.progressRatio=O,this.updateTxStatus(t,this.progressRatio))}}this.walletLocalDataDirty=!0,this.updateTxStatus(t,1),this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[])})}updateTxStatus(t,e){this.tokenCheckTransactionsStatus[t]=e,this.updateOnAddressesChecked()}startEngine(){return d(this,null,function*(){if(this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",Ct).catch(()=>{}),this.lightMode){this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1;for(const t of Object.values(this.allTokensMap))this.tokenCheckTransactionsStatus[t.currencyCode]=1}else this.addToLoop("queryTransactions",Bt).catch(()=>{});yield ht(Z.prototype,this,"startEngine").call(this)})}killEngine(){return d(this,null,function*(){yield this.tools.disconnectClient(),yield ht(Z.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return d(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return d(this,null,function*(){const{tokenId:e}=t,n=this.getBalance({tokenId:e});t.spendTargets[0].nativeAmount="1";const s=yield this.makeSpend(t),o=yield this.getMinimumAddressBalance();let r;if(e==null)r=(0,h.sub)((0,h.sub)(n,s.networkFee),o);else{const i=this.getBalance({tokenId:null}),a=(0,h.sub)(i,s.networkFee);if((0,h.lt)((0,h.sub)(a,o),"0"))throw new B.k5({networkFee:this.feePerSignature,tokenId:null});r=n}if((0,h.lt)(r,"0"))throw new B.k5({tokenId:e});return r})}makeSpend(t){return d(this,null,function*(){var e,n,s,o,r;const{edgeSpendInfo:i,currencyCode:a}=this.makeSpendCheck(t),{customNetworkFee:f,memos:b=[],networkFeeOption:g,tokenId:m,otherParams:K={}}=i;if(i.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:w,publicAddress:p}=i.spendTargets[0];if(p==null)throw new Error("makeSpend Missing publicAddress");if(w==null)throw new B.ef;const I=m!=null;let l="0",C=this.feePerSignature,j;const tt=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",O=new v.J3(this.base58PublicKey),R=new v.J3(p),D=this.tools.tokenProgramPublicKey,J=new v.J3(this.networkInfo.associatedTokenPublicKey),$=[],st=yield this.getPriorityFee();let H="0";switch(g){case"low":H=(0,h.max)("0",(0,h.mul)(st,"0.75"));break;case"standard":H=st;break;case"high":H=(0,h.max)("1",(0,h.mul)(st,"1.25"));break;case"custom":{H=(0,u.CB)(f).microLamports;break}}const pt=yield this.getMinimumAddressBalance();if((0,h.gt)(H,"0")){const L=v.d_.setComputeUnitPrice({microLamports:parseInt(H)});$.push(L),C=(0,h.add)(C,H)}if(I){const L=new v.J3(m),it=(0,T.Xt)(L,R,!1,D,J);let et=this.addressCache.get(p);if(et===void 0){const ct=this.tools.connections.map(Vt=>()=>d(this,null,function*(){return yield Vt.getAccountInfo(it,this.networkInfo.commitment)}));(yield(0,P.NN)(ct))==null?(et=!1,this.addressCache.set(p,!1)):(et=!0,this.addressCache.set(p,!0))}if(!et){const ct=(0,E.JA)(O,it,R,L,D,J);$.push(ct),C=(0,h.add)(C,this.feePerSignature)}if(j=C,C="0",l=w,(0,h.gt)(w,tt))throw new B.k5({tokenId:m});const jt=(n=this.walletLocalData.totalBalances[this.chainCode])!=null?n:"0";if((0,h.gt)((0,h.add)(j,pt),jt))throw new B.k5({networkFee:j,tokenId:null});const Ht=(0,T.Xt)(L,O,!1,D,J),Jt=(0,A.C3)(Ht,it,O,BigInt(w),[],D);$.push(Jt)}else{l=(0,h.add)(w,C);const L=v.yq.transfer({fromPubkey:O,toPubkey:R,lamports:parseInt(w)});if($.push(L),!(0,h.eq)(l,tt)){if((0,h.gt)((0,h.add)(l,pt),tt))throw new B.k5({tokenId:m})}}if(((s=b[0])==null?void 0:s.type)==="text"){const L=new v.fH({keys:[{pubkey:O,isSigner:!0,isWritable:!0}],programId:new v.J3(this.networkInfo.memoPublicKey),data:G.from(b[0].value,"utf-8")});$.push(L)}const rt=yield this.getRecentBlockhash(),Ft=v.Wr.compile({instructions:$,payerKey:O,recentBlockhash:rt.blockhash}),Dt=new v.Kt(Ft),Lt=(r=(o=(0,u.PT)(K))==null?void 0:o.unsignedTx)!=null?r:Dt.serialize(),$t=(0,u.c_)({unsignedTx:Lt,blockhash:rt.blockhash,lastValidBlockHeight:rt.lastValidBlockHeight});return{blockHeight:0,currencyCode:a,date:0,isSend:!0,memos:b,nativeAmount:(0,h.mul)(l,"-1"),networkFee:C,networkFees:[],otherParams:$t,ourReceiveAddresses:[],parentNetworkFee:j,signedTx:"",tokenId:m,txid:"",walletId:this.walletId}})}signTx(t,e){return d(this,null,function*(){const n=(0,u.aY)(this.currencyInfo.pluginId)(e),{unsignedTx:s}=(0,u.fQ)((0,k.Je)(t)),o=v.Kt.deserialize(s),r=yield this.queryBlockhash();o.message.recentBlockhash=r.blockhash;const i=v.AX.fromSecretKey(W.xn.parse(n.privateKey));return o.sign([{publicKey:i.publicKey,secretKey:i.secretKey}]),t.signedTx=W.K3.stringify(o.serialize()),t.otherParams=(0,u.c_)({unsignedTx:s,blockhash:r.blockhash,lastValidBlockHeight:r.lastValidBlockHeight}),this.warn(`signTx
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[6227],{62351:function(kt,U,y){"use strict";y.d(U,{Nn:function(){return W},Nt:function(){return z},fi:function(){return X},zp:function(){return V}});var v=y(14171),h=y(44276),M=(k,u,T)=>new Promise((E,A)=>{var N=S=>{try{F(T.next(S))}catch(P){A(P)}},B=S=>{try{F(T.throw(S))}catch(P){A(P)}},F=S=>S.done?E(S.value):Promise.resolve(S.value).then(N,B);F((T=T.apply(k,u)).next())});const nt=["https://info1.edge.app","https://info2.edge.app"];function Q(k,u,T){return M(this,arguments,function*(E,A,N,B=5e3,F=fetch){const S=E.map(P=>()=>M(this,null,function*(){const G=yield F(P+"/"+A,N);if(typeof G!="object"){const Y=`Invalid return value ${A} in ${P}`;throw console.log(Y),new Error(Y)}return G}));return yield(0,v.NN)(S,B)})}function V(k,u,T,E,A=5e3,N){return M(this,null,function*(){const B=yield Q((0,h.R3)(u),T,E,A,N);if(!B.ok){const P=yield B.text();throw console.error(P),new Error(`Error fetching ${T}: ${P}`)}const F=yield B.json();return k(F)})}function ot(k,u,T,E=5e3,A){return M(this,null,function*(){return yield Q((0,h.R3)(k),u,T,E,A)})}const W=(k,u,T,E)=>M(void 0,null,function*(){return yield ot(nt,k,u,T,E)}),z=k=>Object.keys(k).map(u=>{const T=k[u];return T==null?u:`${u}=${encodeURIComponent(T)}`}).join("&"),X=(k,u=5e3)=>k+Math.random()*u*2-u},17792:function(kt,U,y){"use strict";y.r(U),y.d(U,{SolanaTools:function(){return mt},isValidAddress:function(){return _},makeCurrencyEngine:function(){return St},makeCurrencyTools:function(){return Mt},updateInfoPayload:function(){return Nt}});var v=y(49196),h=y(66001),M=y(90749),nt=y(16763),Q=y.n(nt),V=y(48287),ot=y(37680),W=y(65828),z=y(14483),X=y(96542),k=y(44276),u=y(49841),T=y(8197),E=y(9646),A=y(76556),N=y(42704),B=y(82671),F=y(26277),S=y(62351),P=y(14171),G=y(48287).Buffer,Y=Object.defineProperty,gt=Object.defineProperties,wt=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertySymbols,vt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,Tt=Reflect.get,lt=(c,t,e)=>t in c?Y(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,ut=(c,t)=>{for(var e in t||(t={}))bt.call(t,e)&&lt(c,e,t[e]);if(at)for(var e of at(t))Pt.call(t,e)&&lt(c,e,t[e]);return c},It=(c,t)=>gt(c,wt(t)),ht=(c,t,e)=>Tt(vt(c),e,t),d=(c,t,e)=>new Promise((n,s)=>{var o=a=>{try{i(e.next(a))}catch(f){s(f)}},r=a=>{try{i(e.throw(a))}catch(f){s(f)}},i=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,r);i((e=e.apply(c,t)).next())});const Ct=(0,S.fi)(2e4),Bt=(0,S.fi)(2e4);class Z extends F.k{constructor(t,e,n,s){var o;super(t,e,n,s),this.lightMode=(o=s.lightMode)!=null?o:!1,this.networkInfo=t.networkInfo,this.chainCode=e.currencyInfo.currencyCode,this.fetch=(r,i)=>d(this,null,function*(){return yield t.io.fetch(r,It(ut({},i),{corsBypass:"always"}))}),this.feePerSignature="5000",this.getPriorityFee=(0,k.PP)(this.queryFee.bind(this),3e4),this.getRecentBlockhash=(0,k.PP)(this.queryBlockhash.bind(this),3e4),this.base58PublicKey=n.keys.publicKey,this.progressRatio=0,this.addressCache=new Map,this.getMinimumAddressBalance=(0,k.PP)(this.queryMinimumBalance.bind(this),3e4)}setOtherData(t){this.otherData=(0,u._$)(t)}fetchRpcBulk(t,e){return d(this,null,function*(){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(t.map((r,i)=>ut({jsonrpc:"2.0",id:i+1},r)))},o=(e!=null?e:this.networkInfo.rpcNodes).map(r=>()=>d(this,null,function*(){r=this.tools.rpcWithApiKey(r);const i=yield this.fetch(r,n);if(!i.ok)throw new Error(`fetchRpc ${n.method} failed error: ${i.status}`);return yield i.json()}));return yield(0,P.NN)(o)})}queryBalance(){return d(this,null,function*(){var t;try{const e=[{method:"getBalance",params:[this.base58PublicKey,{commitment:this.networkInfo.commitment}]},{method:"getTokenAccountsByOwner",params:[this.base58PublicKey,{programId:this.networkInfo.tokenPublicKey},{encoding:"jsonParsed"}]}],n=yield this.fetchRpcBulk(e),[s,o]=n,r=(0,u.GC)(s);this.updateBalance(this.chainCode,r.result.value.toString());const a=(0,u.Jl)(o).result.value.reduce((b,g)=>(b[g.account.data.parsed.info.mint]=g.account.data.parsed.info.tokenAmount.amount,b),{}),f=[];for(const b of Object.keys(this.allTokensMap)){const g=(t=a[b])!=null?t:"0";this.updateBalance(this.allTokensMap[b].currencyCode,g),(0,h.gt)(g,"0")&&f.push(b)}f.length>0&&this.currencyEngineCallbacks.onNewTokens(f)}catch(e){this.error(`Error checking ${this.chainCode} address balance`,e)}})}queryMinimumBalance(){return d(this,null,function*(){const t=this.tools.connections.map(n=>()=>d(this,null,function*(){return yield n.getMinimumBalanceForRentExemption(50)})),e=yield(0,P.NN)(t);return this.minimumAddressBalance=e.toString(),this.minimumAddressBalance})}queryFee(){return d(this,null,function*(){const t=this.tools.connections.map(o=>()=>d(this,null,function*(){return yield o.getRecentPrioritizationFees()})),e=yield(0,P.NN)(t);if(e.length===0)return this.networkInfo.basePriorityFee.toString();const n=e.map(o=>o.prioritizationFee),s=n.reduce((o,r)=>o+r,0)/n.length;return Math.max(Math.ceil(s),this.networkInfo.basePriorityFee).toString()})}queryBlockhash(){return d(this,null,function*(){const n=(yield Promise.allSettled(this.tools.connections.map(s=>d(this,null,function*(){return yield(0,P.wR)(s.getLatestBlockhash({commitment:"finalized"}),2e3)})))).filter(s=>s.status!=="rejected").sort((s,o)=>o.value.lastValidBlockHeight-s.value.lastValidBlockHeight)[0];if(n==null)throw new Error("No valid blockhash found");return{blockhash:n.value.blockhash,lastValidBlockHeight:n.value.lastValidBlockHeight}})}processSolanaTransaction(t,e,n,s){const o=[],{amount:r,networkFee:i,parentNetworkFee:a,tokenId:f=null}=e,b=f!=null?this.allTokensMap[f].currencyCode:this.chainCode;(0,h.gte)(r,"0")&&o.push(this.base58PublicKey);const g={blockHeight:t.slot,confirmations:"confirmed",currencyCode:b,date:n,isSend:r.startsWith("-"),memos:s.map(m=>({type:"text",value:m})),nativeAmount:r,networkFee:i,networkFees:[],ourReceiveAddresses:o,parentNetworkFee:a,signedTx:"",tokenId:f,txid:t.transaction.signatures[0],walletId:this.walletId};this.addTransaction(b,g)}parseTxAmounts(t,e){var n;const s=t.transaction.message.staticAccountKeys.findIndex(l=>l.equals(e));if(s<0||t.meta==null)return[];const{fee:o,preBalances:r,postBalances:i,preTokenBalances:a,postTokenBalances:f}=t.meta,b=a!=null?a:[],g=f!=null?f:[],m=t.transaction.message.staticAccountKeys.find(l=>l.equals(this.tools.tokenProgramPublicKey))!=null,K=o.toString();if(!m){const l=(i[s]-r[s]).toString(),C=(0,h.lt)(l,"0");return[{amount:l,networkFee:C?K:"0"}]}const w=l=>l.owner!==this.base58PublicKey||this.allTokensMap[l.mint]==null,p=new Map;for(const l of g)l==null||w(l)||p.set(l.mint,l.uiTokenAmount.amount);for(const l of b){if(l==null||w(l))continue;const C=(n=p.get(l.mint))!=null?n:"0";p.set(l.mint,(0,h.sub)(C,l.uiTokenAmount.amount))}const I=[];return p.forEach((l,C)=>{I.push({amount:l,networkFee:"0",parentNetworkFee:(0,h.lt)(l,"0")?K:void 0,tokenId:C})}),I}queryTransactions(){return d(this,null,function*(){const t=new v.J3(this.base58PublicKey),e=new Set([[this.currencyInfo.currencyCode,t]]);for(const n of this.enabledTokenIds){const s=(0,T.Xt)(new v.J3(n),t,!1,this.tools.tokenProgramPublicKey,new v.J3(this.networkInfo.associatedTokenPublicKey)),o=this.allTokensMap[n].currencyCode;e.add([o,s])}for(const n of e){const[s,o]=n;yield this.queryTransactionsInner(s,o)}})}queryTransactionsInner(t,e){return d(this,null,function*(){var n,s;let o;const r=this.otherData.newestTxid[t]!==""?this.otherData.newestTxid[t]:void 0;let i=[];try{for(;;){const g=this.tools.archiveConnections.map(K=>()=>d(this,null,function*(){return yield K.getSignaturesForAddress(e,{until:r,before:o,limit:this.networkInfo.txQueryLimit})})),m=yield(0,P.NN)(g);if(i=i.concat(m),m.length<this.networkInfo.txQueryLimit)break;o=m[this.networkInfo.txQueryLimit-1].signature}}catch(g){this.error("getTransactionSignatures failed with error: ",g);return}if(i.length===0){this.updateTxStatus(t,1);return}const a=50;let f=0;const b=i.map(g=>g.signature).reverse();for(let g=0;g<b.length;g+=a){const m=b.slice(g,g+a),K=this.tools.archiveConnections.map(p=>()=>d(this,null,function*(){return yield p.getTransactions(m,{commitment:this.networkInfo.commitment,maxSupportedTransactionVersion:0})})),w=yield(0,P.NN)(K);for(let p=0;p<w.length;p++){if(f++,((n=w[p].meta)==null?void 0:n.err)!=null)continue;const I=i.find(R=>R.signature===w[p].transaction.signatures[0]);if(I==null)continue;let l=(s=I.blockTime)!=null?s:w[p].blockTime;if(l==null){const R=this.tools.archiveConnections.map($=>()=>d(this,null,function*(){return yield $.getBlockTime(w[p].slot)})),D=yield(0,P.NN)(R),J=(0,N.HS)(u.Ft)(D);if(J==null)continue;l=J.result}const C=l,j=[];if(I.memo!=null){const R=/^\[\d+\]\s(.*)$/,D=I.memo.match(R);D!=null&&j.push(D[1])}this.parseTxAmounts(w[p],e).forEach(R=>{this.processSolanaTransaction(w[p],R,C,j)}),this.otherData.newestTxid[t]=w[p].transaction.signatures[0];const O=1-f/i.length;O!==this.progressRatio&&(Math.abs(O-this.progressRatio)>.25||O===1)&&(this.progressRatio=O,this.updateTxStatus(t,this.progressRatio))}}this.walletLocalDataDirty=!0,this.updateTxStatus(t,1),this.transactionEvents.length>0&&(this.currencyEngineCallbacks.onTransactions(this.transactionEvents),this.transactionEvents=[])})}updateTxStatus(t,e){this.tokenCheckTransactionsStatus[t]=e,this.updateOnAddressesChecked()}startEngine(){return d(this,null,function*(){if(this.engineOn=!0,yield this.tools.connectClient(),this.addToLoop("queryBalance",Ct).catch(()=>{}),this.lightMode){this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1;for(const t of Object.values(this.allTokensMap))this.tokenCheckTransactionsStatus[t.currencyCode]=1}else this.addToLoop("queryTransactions",Bt).catch(()=>{});yield ht(Z.prototype,this,"startEngine").call(this)})}killEngine(){return d(this,null,function*(){yield this.tools.disconnectClient(),yield ht(Z.prototype,this,"killEngine").call(this)})}resyncBlockchain(){return d(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return d(this,null,function*(){const{tokenId:e}=t,n=this.getBalance({tokenId:e});t.spendTargets[0].nativeAmount="1";const s=yield this.makeSpend(t),o=yield this.getMinimumAddressBalance();let r;if(e==null)r=(0,h.sub)((0,h.sub)(n,s.networkFee),o);else{const i=this.getBalance({tokenId:null}),a=(0,h.sub)(i,s.networkFee);if((0,h.lt)((0,h.sub)(a,o),"0"))throw new B.k5({networkFee:this.feePerSignature,tokenId:null});r=n}if((0,h.lt)(r,"0"))throw new B.k5({tokenId:e});return r})}makeSpend(t){return d(this,null,function*(){var e,n,s,o,r;const{edgeSpendInfo:i,currencyCode:a}=this.makeSpendCheck(t),{customNetworkFee:f,memos:b=[],networkFeeOption:g,tokenId:m,otherParams:K={}}=i;if(i.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:w,publicAddress:p}=i.spendTargets[0];if(p==null)throw new Error("makeSpend Missing publicAddress");if(w==null)throw new B.ef;const I=m!=null;let l="0",C=this.feePerSignature,j;const tt=(e=this.walletLocalData.totalBalances[a])!=null?e:"0",O=new v.J3(this.base58PublicKey),R=new v.J3(p),D=this.tools.tokenProgramPublicKey,J=new v.J3(this.networkInfo.associatedTokenPublicKey),$=[],st=yield this.getPriorityFee();let H="0";switch(g){case"low":H=(0,h.max)("0",(0,h.mul)(st,"0.75"));break;case void 0:case"standard":H=st;break;case"high":H=(0,h.max)("1",(0,h.mul)(st,"1.25"));break;case"custom":{H=(0,u.CB)(f).microLamports;break}}const pt=yield this.getMinimumAddressBalance();if((0,h.gt)(H,"0")){const L=v.d_.setComputeUnitPrice({microLamports:parseInt(H)});$.push(L),C=(0,h.add)(C,H)}if(I){const L=new v.J3(m),it=(0,T.Xt)(L,R,!1,D,J);let et=this.addressCache.get(p);if(et===void 0){const ct=this.tools.connections.map(Vt=>()=>d(this,null,function*(){return yield Vt.getAccountInfo(it,this.networkInfo.commitment)}));(yield(0,P.NN)(ct))==null?(et=!1,this.addressCache.set(p,!1)):(et=!0,this.addressCache.set(p,!0))}if(!et){const ct=(0,E.JA)(O,it,R,L,D,J);$.push(ct),C=(0,h.add)(C,this.feePerSignature)}if(j=C,C="0",l=w,(0,h.gt)(w,tt))throw new B.k5({tokenId:m});const jt=(n=this.walletLocalData.totalBalances[this.chainCode])!=null?n:"0";if((0,h.gt)((0,h.add)(j,pt),jt))throw new B.k5({networkFee:j,tokenId:null});const Ht=(0,T.Xt)(L,O,!1,D,J),Jt=(0,A.C3)(Ht,it,O,BigInt(w),[],D);$.push(Jt)}else{l=(0,h.add)(w,C);const L=v.yq.transfer({fromPubkey:O,toPubkey:R,lamports:parseInt(w)});if($.push(L),!(0,h.eq)(l,tt)){if((0,h.gt)((0,h.add)(l,pt),tt))throw new B.k5({tokenId:m})}}if(((s=b[0])==null?void 0:s.type)==="text"){const L=new v.fH({keys:[{pubkey:O,isSigner:!0,isWritable:!0}],programId:new v.J3(this.networkInfo.memoPublicKey),data:G.from(b[0].value,"utf-8")});$.push(L)}const rt=yield this.getRecentBlockhash(),Ft=v.Wr.compile({instructions:$,payerKey:O,recentBlockhash:rt.blockhash}),Dt=new v.Kt(Ft),Lt=(r=(o=(0,u.PT)(K))==null?void 0:o.unsignedTx)!=null?r:Dt.serialize(),$t=(0,u.c_)({unsignedTx:Lt,blockhash:rt.blockhash,lastValidBlockHeight:rt.lastValidBlockHeight});return{blockHeight:0,currencyCode:a,date:0,isSend:!0,memos:b,nativeAmount:(0,h.mul)(l,"-1"),networkFee:C,networkFees:[],otherParams:$t,ourReceiveAddresses:[],parentNetworkFee:j,signedTx:"",tokenId:m,txid:"",walletId:this.walletId}})}signTx(t,e){return d(this,null,function*(){const n=(0,u.aY)(this.currencyInfo.pluginId)(e),{unsignedTx:s}=(0,u.fQ)((0,k.Je)(t)),o=v.Kt.deserialize(s),r=yield this.queryBlockhash();o.message.recentBlockhash=r.blockhash;const i=v.AX.fromSecretKey(W.xn.parse(n.privateKey));return o.sign([{publicKey:i.publicKey,secretKey:i.secretKey}]),t.signedTx=W.K3.stringify(o.serialize()),t.otherParams=(0,u.c_)({unsignedTx:s,blockhash:r.blockhash,lastValidBlockHeight:r.lastValidBlockHeight}),this.warn(`signTx
2
2
  ${(0,k.T5)(t)}`),this.addressCache=new Map(Array.from(this.addressCache.entries()).filter(([a,f])=>f)),t})}broadcastTx(t){return d(this,null,function*(){if(t.signedTx==null)throw new Error("Missing signedTx");const{blockhash:e,lastValidBlockHeight:n}=(0,u.fQ)((0,k.Je)(t)),s=this.tools.makeConnections(this.networkInfo.stakedConnectionRpcNodes),o=this.tools.connections,r=[...this.tools.connections,...s],i=new AbortController,a=new AbortController,f=()=>d(this,null,function*(){const m=r.map(w=>d(this,null,function*(){return yield w.sendEncodedTransaction(t.signedTx,{skipPreflight:!0})}));return yield(0,P.QR)(m)}),b=()=>d(this,null,function*(){const m=o.map(I=>d(this,null,function*(){return yield(0,P.wR)(I.getBlockHeight("confirmed"),1e3)})),w=(yield Promise.allSettled(m)).filter(I=>I.status==="fulfilled").map(I=>I.value);return Math.max(...w)}),g=()=>d(this,null,function*(){for(;!a.signal.aborted;)if(yield(0,k.hr)(400),(yield b())<n)yield f();else throw i.abort(),new Error("transaction expired")});try{const m=yield f(),K=o.map(w=>d(this,null,function*(){const p=yield w.confirmTransaction({signature:m,blockhash:e,lastValidBlockHeight:n,abortSignal:i.signal},"confirmed"),I=(0,N.HS)(N.oJ)(p.value.err);if(I!=null)throw new Error(I);a.abort()}));yield Promise.race([g(),...K]),t.txid=m,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
3
3
  ${(0,k.T5)(t)}`)}catch(m){throw this.warn("FAILURE broadcastTx failed: ",m),m}return t})}}function St(c,t,e,n){return d(this,null,function*(){const s=(0,u.BW)(e),o=new Z(c,t,s,n);return yield o.loadEngine(),o})}var xt=Object.defineProperty,Kt=Object.defineProperties,Et=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable,yt=(c,t,e)=>t in c?xt(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,At=(c,t)=>{for(var e in t||(t={}))dt.call(t,e)&&yt(c,e,t[e]);if(q)for(var e of q(t))ft.call(t,e)&&yt(c,e,t[e]);return c},Ot=(c,t)=>Kt(c,Et(t)),Rt=(c,t)=>{var e={};for(var n in c)dt.call(c,n)&&t.indexOf(n)<0&&(e[n]=c[n]);if(c!=null&&q)for(var n of q(c))t.indexOf(n)<0&&ft.call(c,n)&&(e[n]=c[n]);return e},x=(c,t,e)=>new Promise((n,s)=>{var o=a=>{try{i(e.next(a))}catch(f){s(f)}},r=a=>{try{i(e.throw(a))}catch(f){s(f)}},i=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,r);i((e=e.apply(c,t)).next())});const _=c=>{try{return v.J3.isOnCurve(new v.J3(c).toBytes()),!0}catch{}return!1};class mt{constructor(t){const{builtinTokens:e,currencyInfo:n,io:s,log:o,networkInfo:r}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=s,this.log=o,this.networkInfo=r,this.initOptions=(0,u.Tk)(t.initOptions),this.connections=[],this.archiveConnections=[],this.clientCount=0,this.tokenProgramPublicKey=new v.J3(r.tokenPublicKey)}getDisplayPrivateKey(t){return x(this,null,function*(){var e,n;const{pluginId:s}=this.currencyInfo,o=(0,u.aY)(s)(t.keys);return(n=(e=o.mnemonic)!=null?e:o.base58Key)!=null?n:o.privateKey})}getDisplayPublicKey(t){return x(this,null,function*(){const{keys:e}=(0,u.BW)(t);return e.publicKey})}importPrivateKey(t){return x(this,null,function*(){const{pluginId:e}=this.currencyInfo;if((0,M.validateMnemonic)(t)){const n=yield(0,M.mnemonicToSeed)(t),s=ot.derivePath(this.networkInfo.derivationPath,W.xn.stringify(n)).key,o=v.AX.fromSeed(Uint8Array.from(s));return{[`${e}Mnemonic`]:t,[`${e}Key`]:V.Buffer.from(o.secretKey).toString("hex"),publicKey:o.publicKey.toBase58()}}else{const n=Q().decode(t),s=yield v.AX.fromSecretKey(n);return{[`${e}Base58Key`]:t,[`${e}Key`]:V.Buffer.from(s.secretKey).toString("hex"),publicKey:s.publicKey.toBase58()}}})}createPrivateKey(t){return x(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=V.Buffer.from(this.io.random(32)),n=(0,M.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}derivePublicKey(t){return x(this,null,function*(){var e;const{pluginId:n}=this.currencyInfo;if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");return{publicKey:(yield this.importPrivateKey((e=t.keys[`${n}Mnemonic`])!=null?e:t.keys[`${n}Base58Key`])).publicKey.toString()}})}parseUri(t,e,n){return x(this,null,function*(){const{pluginId:s}=this.currencyInfo,o={[s]:!0},{parsedUri:r,edgeParsedUri:i}=yield(0,X.x)({currencyInfo:this.currencyInfo,uri:t,networks:o,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:this.currencyInfo.currencyCode,customTokens:n,testPrivateKeys:this.importPrivateKey.bind(this)});if(i.privateKeys!=null)return i;if(i.publicAddress!=null&&!_(i.publicAddress))throw new Error("InvalidPublicAddressError");return i.uniqueIdentifier=r.query.memo,i})}encodeUri(t){return x(this,arguments,function*(e,n=[]){const{pluginId:s}=this.currencyInfo,{nativeAmount:o,currencyCode:r,publicAddress:i}=e;if(!_(i))throw new Error("InvalidPublicAddressError");let a;if(typeof o=="string"){const b=(0,k.FQ)(r!=null?r:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(b==null)throw new Error("InternalErrorInvalidCurrencyCode");a=(0,h.div)(o,b.multiplier,18)}return(0,X.m)(e,s,a)})}rpcWithApiKey(t){const e=this.initOptions,s=/{{(.*)}}/g.exec(t);if(s!=null){const o=s[1],r=e[o];if(typeof r=="string")t=t.replace(s[0],r);else throw r==null?new Error(`Missing ${o} in 'initOptions' for ${this.currencyInfo.pluginId}`):new Error("Incorrect apikey type for RPC")}return t}makeConnections(t){const e=(o,r)=>x(this,null,function*(){return yield this.io.fetch(o,Ot(At({},r),{corsBypass:"always"}))}),n={commitment:this.networkInfo.commitment,fetch:e},s=[];for(const o of t)try{const r=new v.Ng(this.rpcWithApiKey(o),n);s.push(r)}catch(r){this.log.warn("Error creating connection",r)}return s}connectClient(){return x(this,null,function*(){this.clientCount===0&&(this.connections=this.makeConnections(this.networkInfo.rpcNodes),this.archiveConnections=this.makeConnections(this.networkInfo.rpcNodesArchival)),++this.clientCount})}disconnectClient(){return x(this,null,function*(){--this.clientCount,this.clientCount===0&&(this.connections=[],this.archiveConnections=[])})}getTokenId(t){return x(this,null,function*(){(0,z.k9)(t);const e=(0,z.oQ)(t.networkLocation);if(e==null||!_(e.contractAddress))throw new Error("ErrorInvalidContractAddress");return e.contractAddress})}}function Mt(c){return x(this,null,function*(){return new mt(c)})}function Nt(c,t){return x(this,null,function*(){const e=Rt(t,[]);c.networkInfo=(0,k.wy)(c.networkInfo,e)})}},15340:function(){},79838:function(){},71281:function(){}}]);
@@ -82,7 +82,16 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
82
82
  // Each currency code can be a 0-1 value
83
83
 
84
84
 
85
+
86
+ /** The official core new-tx checkpoint, saved to synced storage. */
87
+
88
+
89
+ /**
90
+ * The highest transaction checkpoint we have seen.
91
+ * This will be saved to `seenTxCheckpoint` once we finish syncing.
92
+ */
85
93
 
94
+
86
95
 
87
96
 
88
97
 
@@ -273,6 +282,7 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
273
282
  // Undefined seenTxCheckpoint means we're syncing for the very first time
274
283
  // and should not emit new transaction notifications.
275
284
  this.seenTxCheckpoint != null &&
285
+ // We want the tx checkpoint to be `>` our existing one, not `>=`:
276
286
  txCheckpoint !== this.seenTxCheckpoint
277
287
  ) {
278
288
  // Return true if the transaction's checkpoint is selected
@@ -347,6 +357,16 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
347
357
  this.transactionList = _nullishCoalesce(transactionList, () => ( this.transactionList))
348
358
  this.txIdList = _nullishCoalesce(txIdList, () => ( this.txIdList))
349
359
  this.txIdMap = _nullishCoalesce(txIdMap, () => ( this.txIdMap))
360
+
361
+ // But we do need to update our checkpoints:
362
+ for (const cc of Object.keys(this.transactionList)) {
363
+ for (const tx of this.transactionList[cc]) {
364
+ this.highestSeenCheckpoint = this.selectSeenTxCheckpoint(
365
+ this.highestSeenCheckpoint,
366
+ this.getTxCheckpoint(tx)
367
+ )
368
+ }
369
+ }
350
370
  } else if (transactionList != null) {
351
371
  // Manually add transactions via addTransaction()
352
372
  for (const cc of Object.keys(transactionList)) {
@@ -401,6 +421,18 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
401
421
 
402
422
  this.doInitialBalanceCallback()
403
423
  this.doInitialUnactivatedTokenIdsCallback()
424
+
425
+ // If we have no checkpoint, load all transactions into memory.
426
+ // This will set up `highestSeenCheckpoint`, which gets copied to
427
+ // `seenTxCheckpoint` when the sync completes.
428
+ if (this.seenTxCheckpoint == null) {
429
+ await this.loadTransactions()
430
+ // We still need an initial checkpoint,
431
+ // even if we don't have any txs:
432
+ if (this.highestSeenCheckpoint == null) {
433
+ this.highestSeenCheckpoint = '0'
434
+ }
435
+ }
404
436
  }
405
437
 
406
438
  findTransaction(currencyCode, txid) {
@@ -467,10 +499,11 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
467
499
  this.transactionListDirty = true
468
500
  const isNew = this.isTransactionNew(edgeTransaction)
469
501
  this.transactionEvents.push({ isNew, transaction: edgeTransaction })
470
- if (isNew) {
471
- // Update the seenTxCheckpoint whenever there are new transactions added
472
- this.updateSeenTxCheckpoint(this.getTxCheckpoint(edgeTransaction))
473
- }
502
+ this.highestSeenCheckpoint = this.selectSeenTxCheckpoint(
503
+ this.getTxCheckpoint(edgeTransaction),
504
+ this.highestSeenCheckpoint
505
+ )
506
+ this.updateSeenTxCheckpoint()
474
507
  this.warn(`addTransaction new tx: ${edgeTransaction.txid}`)
475
508
  } else {
476
509
  // Already have this tx in the database. See if anything changed
@@ -793,18 +826,17 @@ const DROPPED_TX_TIME_GAP = 3600 * 24 // 1 Day
793
826
  this.updateSeenTxCheckpoint()
794
827
  }
795
828
 
796
- updateSeenTxCheckpoint(seenTxCheckpoint) {
797
- // Update the seenTxCheckpoint using the max-algorithm:
798
- this.seenTxCheckpoint = this.selectSeenTxCheckpoint(
799
- seenTxCheckpoint,
800
- this.seenTxCheckpoint
801
- )
802
-
829
+ updateSeenTxCheckpoint() {
803
830
  // Only call the callback if the wallet is fully synced.
804
831
  // This ensure that all initial syncs, without a defined seenTxCheckpoint,
805
832
  // will not incorrectly update the seenTxCheckpoint in the middle of an
806
833
  // initial sync.
807
- if (this.addressesChecked && this.seenTxCheckpoint != null) {
834
+ if (
835
+ this.addressesChecked &&
836
+ this.highestSeenCheckpoint != null &&
837
+ this.highestSeenCheckpoint !== this.seenTxCheckpoint
838
+ ) {
839
+ this.seenTxCheckpoint = this.highestSeenCheckpoint
808
840
  this.currencyEngineCallbacks.onSeenTxCheckpoint(this.seenTxCheckpoint)
809
841
  }
810
842
  }
@@ -630,6 +630,7 @@ const TRANSACTION_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void 0, 200
630
630
  case 'low':
631
631
  microLamports = _biggystring.max.call(void 0, '0', _biggystring.mul.call(void 0, priorityFee, '0.75'))
632
632
  break
633
+ case undefined:
633
634
  case 'standard':
634
635
  microLamports = priorityFee
635
636
  break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "4.36.0",
3
+ "version": "4.36.2",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {