@dcl-regenesislabs/mobile-hub 1.0.0-20717816491.commit-17f8927 → 1.0.0-20723159718.commit-457ece6
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/assets/{basic-D4vJRBfa.js → basic-CGO724kq.js} +1 -1
- package/assets/{core-Ds-5UYKM.js → core-Be_s2Hcs.js} +4 -4
- package/assets/{features-BgzVlStz.js → features-dSuLxGt9.js} +1 -1
- package/assets/{fortmatic-B79B8GDv.js → fortmatic-tDqJJpPT.js} +1 -1
- package/assets/{index-Cf-uY5dQ.js → index-9uP_tzWK.js} +3 -3
- package/assets/index-D42x9zzA.css +1 -0
- package/assets/{index-RgK09Bbj.js → index-D5ZH0nbD.js} +1 -1
- package/assets/{index-B88UDh6R.js → index-DMBiP40H.js} +1 -1
- package/assets/{index-CcElmyXG.js → index-DrI2FF3s.js} +1 -1
- package/assets/index-i2A_phFP.js +23 -0
- package/assets/{w3m-modal-xfuWMvke.js → w3m-modal-D8dRHyZX.js} +1 -1
- package/index.html +3 -3
- package/package.json +3 -3
- package/assets/index-CEmkvSJ-.js +0 -23
- package/assets/index-CcyN_bjy.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{N as h,t as Pe,u as Ie,R as u,S as g,b as te,c as O,E as _,v as oe,x as ne,n as m,B as j,a as de,y as M,z as G,D as Fe,m as pe,F as Le,C as re,G as Ee,I as Ne,M as P,J as We,e as S,r as Z,i as k,d as c,j as Re,K as ae,h as ue,f as He,L as F,O as b,s as Oe,A as ee,T as je,P as Me}from"./core-Ds-5UYKM.js";import{c as y,n as p,o as I,r as w,U as De}from"./index-RgK09Bbj.js";import"./index-CEmkvSJ-.js";import"./index-Cf-uY5dQ.js";const D={getGasPriceInEther(e,t){const o=t*e;return Number(o)/1e18},getGasPriceInUSD(e,t,o){const i=D.getGasPriceInEther(t,o);return h.bigNumber(e).times(i).toNumber()},getPriceImpact({sourceTokenAmount:e,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:i}){const a=h.bigNumber(e).times(t),n=h.bigNumber(i).times(o);return a.minus(n).div(a).times(100).toNumber()},getMaxSlippage(e,t){const o=h.bigNumber(e).div(100);return h.multiply(t,o).toNumber()},getProviderFee(e,t=.0085){return h.bigNumber(e).times(t).toString()},isInsufficientNetworkTokenForGas(e,t){const o=t||"0";return h.bigNumber(e).eq(0)?!0:h.bigNumber(h.bigNumber(o)).gt(e)},isInsufficientSourceTokenForSwap(e,t,o){const i=o?.find(n=>n.address===t)?.quantity?.numeric;return h.bigNumber(i||"0").lt(e)}},xe=15e4,Ve=6,T={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!1,switchingTokens:!1,fetchError:!1,approvalTransaction:void 0,swapTransaction:void 0,transactionError:void 0,sourceToken:void 0,sourceTokenAmount:"",sourceTokenPriceInUSD:0,toToken:void 0,toTokenAmount:"",toTokenPriceInUSD:0,networkPrice:"0",networkBalanceInUSD:"0",networkTokenSymbol:"",inputError:void 0,slippage:pe.CONVERT_SLIPPAGE_TOLERANCE,tokens:void 0,popularTokens:void 0,suggestedTokens:void 0,foundTokens:void 0,myTokensWithBalance:void 0,tokensPriceMap:{},gasFee:"0",gasPriceInUSD:0,priceImpact:void 0,maxSlippage:void 0,providerFee:void 0},r=Ie({...T}),ie={state:r,subscribe(e){return Ne(r,()=>e(r))},subscribeKey(e,t){return Ee(r,e,t)},getParams(){const e=m.state.activeChain,t=m.getAccountData(e)?.caipAddress??m.state.activeCaipAddress,o=de.getPlainAddress(t),i=Le(),a=re.getConnectorId(m.state.activeChain);if(!o)throw new Error("No address found to swap the tokens from.");const n=!r.toToken?.address||!r.toToken?.decimals,s=!r.sourceToken?.address||!r.sourceToken?.decimals||!h.bigNumber(r.sourceTokenAmount).gt(0),l=!r.sourceTokenAmount;return{networkAddress:i,fromAddress:o,fromCaipAddress:t,sourceTokenAddress:r.sourceToken?.address,toTokenAddress:r.toToken?.address,toTokenAmount:r.toTokenAmount,toTokenDecimals:r.toToken?.decimals,sourceTokenAmount:r.sourceTokenAmount,sourceTokenDecimals:r.sourceToken?.decimals,invalidToToken:n,invalidSourceToken:s,invalidSourceTokenAmount:l,availableToSwap:t&&!n&&!s&&!l,isAuthConnector:a===O.CONNECTOR_ID.AUTH}},async setSourceToken(e){if(!e){r.sourceToken=e,r.sourceTokenAmount="",r.sourceTokenPriceInUSD=0;return}r.sourceToken=e,await d.setTokenPrice(e.address,"sourceToken")},setSourceTokenAmount(e){r.sourceTokenAmount=e},async setToToken(e){if(!e){r.toToken=e,r.toTokenAmount="",r.toTokenPriceInUSD=0;return}r.toToken=e,await d.setTokenPrice(e.address,"toToken")},setToTokenAmount(e){r.toTokenAmount=e?h.toFixed(e,Ve):""},async setTokenPrice(e,t){let o=r.tokensPriceMap[e]||0;o||(r.loadingPrices=!0,o=await d.getAddressPrice(e)),t==="sourceToken"?r.sourceTokenPriceInUSD=o:t==="toToken"&&(r.toTokenPriceInUSD=o),r.loadingPrices&&(r.loadingPrices=!1),d.getParams().availableToSwap&&!r.switchingTokens&&d.swapTokens()},async switchTokens(){if(!(r.initializing||!r.initialized||r.switchingTokens)){r.switchingTokens=!0;try{const e=r.toToken?{...r.toToken}:void 0,t=r.sourceToken?{...r.sourceToken}:void 0,o=e&&r.toTokenAmount===""?"1":r.toTokenAmount;d.setSourceTokenAmount(o),d.setToTokenAmount(""),await d.setSourceToken(e),await d.setToToken(t),r.switchingTokens=!1,d.swapTokens()}catch(e){throw r.switchingTokens=!1,e}}},resetState(){r.myTokensWithBalance=T.myTokensWithBalance,r.tokensPriceMap=T.tokensPriceMap,r.initialized=T.initialized,r.initializing=T.initializing,r.switchingTokens=T.switchingTokens,r.sourceToken=T.sourceToken,r.sourceTokenAmount=T.sourceTokenAmount,r.sourceTokenPriceInUSD=T.sourceTokenPriceInUSD,r.toToken=T.toToken,r.toTokenAmount=T.toTokenAmount,r.toTokenPriceInUSD=T.toTokenPriceInUSD,r.networkPrice=T.networkPrice,r.networkTokenSymbol=T.networkTokenSymbol,r.networkBalanceInUSD=T.networkBalanceInUSD,r.inputError=T.inputError},resetValues(){const{networkAddress:e}=d.getParams(),t=r.tokens?.find(o=>o.address===e);d.setSourceToken(t),d.setToToken(void 0)},getApprovalLoadingState(){return r.loadingApprovalTransaction},clearError(){r.transactionError=void 0},async initializeState(){if(!r.initializing){if(r.initializing=!0,!r.initialized)try{await d.fetchTokens(),r.initialized=!0}catch{r.initialized=!1,g.showError("Failed to initialize swap"),u.goBack()}r.initializing=!1}},async fetchTokens(){const{networkAddress:e}=d.getParams();await d.getNetworkTokenPrice(),await d.getMyTokensWithBalance();const t=r.myTokensWithBalance?.find(o=>o.address===e);t&&(r.networkTokenSymbol=t.symbol,d.setSourceToken(t),d.setSourceTokenAmount("0"))},async getTokenList(){const e=m.state.activeCaipNetwork?.caipNetworkId;if(!(r.caipNetworkId===e&&r.tokens))try{r.tokensLoading=!0;const t=await M.getTokenList(e);r.tokens=t,r.caipNetworkId=e,r.popularTokens=t.sort((s,l)=>s.symbol<l.symbol?-1:s.symbol>l.symbol?1:0);const i=(e&&pe.SUGGESTED_TOKENS_BY_CHAIN?.[e]||[]).map(s=>t.find(l=>l.symbol===s)).filter(s=>!!s),n=(pe.SWAP_SUGGESTED_TOKENS||[]).map(s=>t.find(l=>l.symbol===s)).filter(s=>!!s).filter(s=>!i.some(l=>l.address===s.address));r.suggestedTokens=[...i,...n]}catch{r.tokens=[],r.popularTokens=[],r.suggestedTokens=[]}finally{r.tokensLoading=!1}},async getAddressPrice(e){const t=r.tokensPriceMap[e];if(t)return t;const i=(await j.fetchTokenPrice({addresses:[e]}))?.fungibles||[],n=[...r.tokens||[],...r.myTokensWithBalance||[]]?.find(f=>f.address===e)?.symbol,s=i.find(f=>f.symbol.toLowerCase()===n?.toLowerCase())?.price||0,l=parseFloat(s.toString());return r.tokensPriceMap[e]=l,l},async getNetworkTokenPrice(){const{networkAddress:e}=d.getParams(),o=(await j.fetchTokenPrice({addresses:[e]}).catch(()=>(g.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles?.[0],i=o?.price.toString()||"0";r.tokensPriceMap[e]=parseFloat(i),r.networkTokenSymbol=o?.symbol||"",r.networkPrice=i},async getMyTokensWithBalance(e){const t=await Fe.getMyTokensWithBalance(e),o=M.mapBalancesToSwapTokens(t);o&&(await d.getInitialGasPrice(),d.setBalances(o))},setBalances(e){const{networkAddress:t}=d.getParams(),o=m.state.activeCaipNetwork;if(!o)return;const i=e.find(a=>a.address===t);e.forEach(a=>{r.tokensPriceMap[a.address]=a.price||0}),r.myTokensWithBalance=e.filter(a=>a.address.startsWith(o.caipNetworkId)),r.networkBalanceInUSD=i?h.multiply(i.quantity.numeric,i.price).toString():"0"},async getInitialGasPrice(){const e=await M.fetchGasPrice();if(!e)return{gasPrice:null,gasPriceInUSD:null};switch(m.state?.activeCaipNetwork?.chainNamespace){case O.CHAIN.SOLANA:return r.gasFee=e.standard??"0",r.gasPriceInUSD=h.multiply(e.standard,r.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(r.gasFee),gasPriceInUSD:Number(r.gasPriceInUSD)};case O.CHAIN.EVM:default:const t=e.standard??"0",o=BigInt(t),i=BigInt(xe),a=D.getGasPriceInUSD(r.networkPrice,i,o);return r.gasFee=t,r.gasPriceInUSD=a,{gasPrice:o,gasPriceInUSD:a}}},async swapTokens(){const e=m.getAccountData()?.address,t=r.sourceToken,o=r.toToken,i=h.bigNumber(r.sourceTokenAmount).gt(0);if(i||d.setToTokenAmount(""),!o||!t||r.loadingPrices||!i||!e)return;r.loadingQuote=!0;const a=h.bigNumber(r.sourceTokenAmount).times(10**t.decimals).round(0);try{const n=await j.fetchSwapQuote({userAddress:e,from:t.address,to:o.address,gasPrice:r.gasFee,amount:a.toString()});r.loadingQuote=!1;const s=n?.quotes?.[0]?.toAmount;if(!s){G.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const l=h.bigNumber(s).div(10**o.decimals).toString();d.setToTokenAmount(l),d.hasInsufficientToken(r.sourceTokenAmount,t.address)?r.inputError="Insufficient balance":(r.inputError=void 0,d.setTransactionDetails())}catch(n){const s=await M.handleSwapError(n);r.loadingQuote=!1,r.inputError=s||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:e,availableToSwap:t}=d.getParams(),o=r.sourceToken,i=r.toToken;if(!(!e||!t||!o||!i||r.loadingQuote))try{r.loadingBuildTransaction=!0;const a=await M.fetchSwapAllowance({userAddress:e,tokenAddress:o.address,sourceTokenAmount:r.sourceTokenAmount,sourceTokenDecimals:o.decimals});let n;return a?n=await d.createSwapTransaction():n=await d.createAllowanceTransaction(),r.loadingBuildTransaction=!1,r.fetchError=!1,n}catch{u.goBack(),g.showError("Failed to check allowance"),r.loadingBuildTransaction=!1,r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}},async createAllowanceTransaction(){const{fromCaipAddress:e,sourceTokenAddress:t,toTokenAddress:o}=d.getParams();if(!(!e||!o)){if(!t)throw new Error("createAllowanceTransaction - No source token address found.");try{const i=await j.generateApproveCalldata({from:t,to:o,userAddress:e}),a=de.getPlainAddress(i.tx.from);if(!a)throw new Error("SwapController:createAllowanceTransaction - address is required");const n={data:i.tx.data,to:a,gasPrice:BigInt(i.tx.eip155.gasPrice),value:BigInt(i.tx.value),toAmount:r.toTokenAmount};return r.swapTransaction=void 0,r.approvalTransaction={data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount},{data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount}}catch{u.goBack(),g.showError("Failed to create approval transaction"),r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}}},async createSwapTransaction(){const{networkAddress:e,fromCaipAddress:t,sourceTokenAmount:o}=d.getParams(),i=r.sourceToken,a=r.toToken;if(!t||!o||!i||!a)return;const n=te.parseUnits(o,i.decimals)?.toString();try{const s=await j.generateSwapCalldata({userAddress:t,from:i.address,to:a.address,amount:n,disableEstimate:!0}),l=i.address===e,f=BigInt(s.tx.eip155.gas),ye=BigInt(s.tx.eip155.gasPrice),ke=de.getPlainAddress(s.tx.to);if(!ke)throw new Error("SwapController:createSwapTransaction - address is required");const Te={data:s.tx.data,to:ke,gas:f,gasPrice:ye,value:BigInt(l?n??"0":"0"),toAmount:r.toTokenAmount};return r.gasPriceInUSD=D.getGasPriceInUSD(r.networkPrice,f,ye),r.approvalTransaction=void 0,r.swapTransaction=Te,Te}catch{u.goBack(),g.showError("Failed to create transaction"),r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){g.showLoading("Approve limit increase in your wallet"),u.replace("SwapPreview")},async sendTransactionForApproval(e){const{fromAddress:t,isAuthConnector:o}=d.getParams();r.loadingApprovalTransaction=!0,o?u.pushTransactionStack({onSuccess:d.onEmbeddedWalletApprovalSuccess}):g.showLoading("Approve limit increase in your wallet");try{await te.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:O.CHAIN.EVM}),await d.swapTokens(),await d.getTransaction(),r.approvalTransaction=void 0,r.loadingApprovalTransaction=!1}catch(a){const n=a;r.transactionError=n?.displayMessage,r.loadingApprovalTransaction=!1,g.showError(n?.displayMessage||"Transaction error"),_.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:n?.displayMessage||n?.message||"Unknown",network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(e){if(!e)return;const{fromAddress:t,toTokenAmount:o,isAuthConnector:i}=d.getParams();r.loadingTransaction=!0;const a=`Swapping ${r.sourceToken?.symbol} to ${h.formatNumberToLocalString(o,3)} ${r.toToken?.symbol}`,n=`Swapped ${r.sourceToken?.symbol} to ${h.formatNumberToLocalString(o,3)} ${r.toToken?.symbol}`;i?u.pushTransactionStack({onSuccess(){u.replace("Account"),g.showLoading(a),ie.resetState()}}):g.showLoading("Confirm transaction in your wallet");try{const s=[r.sourceToken?.address,r.toToken?.address].join(","),l=await te.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:O.CHAIN.EVM});return r.loadingTransaction=!1,g.showSuccess(n),_.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}}),ie.resetState(),i||u.replace("Account"),ie.getMyTokensWithBalance(s),l}catch(s){const l=s;r.transactionError=l?.displayMessage,r.loadingTransaction=!1,g.showError(l?.displayMessage||"Transaction error"),_.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:l?.displayMessage||l?.message||"Unknown",network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(e,t){return D.isInsufficientSourceTokenForSwap(e,t,r.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:e,toTokenDecimals:t}=d.getParams();!e||!t||(r.gasPriceInUSD=D.getGasPriceInUSD(r.networkPrice,BigInt(r.gasFee),BigInt(xe)),r.priceImpact=D.getPriceImpact({sourceTokenAmount:r.sourceTokenAmount,sourceTokenPriceInUSD:r.sourceTokenPriceInUSD,toTokenPriceInUSD:r.toTokenPriceInUSD,toTokenAmount:r.toTokenAmount}),r.maxSlippage=D.getMaxSlippage(r.slippage,r.toTokenAmount),r.providerFee=D.getProviderFee(r.sourceTokenAmount))}},d=Pe(ie),A=Ie({message:"",open:!1,triggerRect:{width:0,height:0,top:0,left:0},variant:"shade"}),Ge={state:A,subscribe(e){return Ne(A,()=>e(A))},subscribeKey(e,t){return Ee(A,e,t)},showTooltip({message:e,triggerRect:t,variant:o}){A.open=!0,A.message=e,A.triggerRect=t,A.variant=o},hide(){A.open=!1,A.message="",A.triggerRect={width:0,height:0,top:0,left:0}}},V=Pe(Ge),_e={isUnsupportedChainView(){return u.state.view==="UnsupportedChain"||u.state.view==="SwitchNetwork"&&u.state.history.includes("UnsupportedChain")},async safeClose(){if(this.isUnsupportedChainView()){P.shake();return}if(await We.isSIWXCloseDisabled()){P.shake();return}(u.state.view==="DataCapture"||u.state.view==="DataCaptureOtpConfirm")&&te.disconnect(),P.close()}},Ke=S`
|
|
1
|
+
import{N as h,t as Pe,u as Ie,R as u,S as g,b as te,c as O,E as _,v as oe,x as ne,n as m,B as j,a as de,y as M,z as G,D as Fe,m as pe,F as Le,C as re,G as Ee,I as Ne,M as P,J as We,e as S,r as Z,i as k,d as c,j as Re,K as ae,h as ue,f as He,L as F,O as b,s as Oe,A as ee,T as je,P as Me}from"./core-Be_s2Hcs.js";import{c as y,n as p,o as I,r as w,U as De}from"./index-D5ZH0nbD.js";import"./index-i2A_phFP.js";import"./index-9uP_tzWK.js";const D={getGasPriceInEther(e,t){const o=t*e;return Number(o)/1e18},getGasPriceInUSD(e,t,o){const i=D.getGasPriceInEther(t,o);return h.bigNumber(e).times(i).toNumber()},getPriceImpact({sourceTokenAmount:e,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:i}){const a=h.bigNumber(e).times(t),n=h.bigNumber(i).times(o);return a.minus(n).div(a).times(100).toNumber()},getMaxSlippage(e,t){const o=h.bigNumber(e).div(100);return h.multiply(t,o).toNumber()},getProviderFee(e,t=.0085){return h.bigNumber(e).times(t).toString()},isInsufficientNetworkTokenForGas(e,t){const o=t||"0";return h.bigNumber(e).eq(0)?!0:h.bigNumber(h.bigNumber(o)).gt(e)},isInsufficientSourceTokenForSwap(e,t,o){const i=o?.find(n=>n.address===t)?.quantity?.numeric;return h.bigNumber(i||"0").lt(e)}},xe=15e4,Ve=6,T={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!1,switchingTokens:!1,fetchError:!1,approvalTransaction:void 0,swapTransaction:void 0,transactionError:void 0,sourceToken:void 0,sourceTokenAmount:"",sourceTokenPriceInUSD:0,toToken:void 0,toTokenAmount:"",toTokenPriceInUSD:0,networkPrice:"0",networkBalanceInUSD:"0",networkTokenSymbol:"",inputError:void 0,slippage:pe.CONVERT_SLIPPAGE_TOLERANCE,tokens:void 0,popularTokens:void 0,suggestedTokens:void 0,foundTokens:void 0,myTokensWithBalance:void 0,tokensPriceMap:{},gasFee:"0",gasPriceInUSD:0,priceImpact:void 0,maxSlippage:void 0,providerFee:void 0},r=Ie({...T}),ie={state:r,subscribe(e){return Ne(r,()=>e(r))},subscribeKey(e,t){return Ee(r,e,t)},getParams(){const e=m.state.activeChain,t=m.getAccountData(e)?.caipAddress??m.state.activeCaipAddress,o=de.getPlainAddress(t),i=Le(),a=re.getConnectorId(m.state.activeChain);if(!o)throw new Error("No address found to swap the tokens from.");const n=!r.toToken?.address||!r.toToken?.decimals,s=!r.sourceToken?.address||!r.sourceToken?.decimals||!h.bigNumber(r.sourceTokenAmount).gt(0),l=!r.sourceTokenAmount;return{networkAddress:i,fromAddress:o,fromCaipAddress:t,sourceTokenAddress:r.sourceToken?.address,toTokenAddress:r.toToken?.address,toTokenAmount:r.toTokenAmount,toTokenDecimals:r.toToken?.decimals,sourceTokenAmount:r.sourceTokenAmount,sourceTokenDecimals:r.sourceToken?.decimals,invalidToToken:n,invalidSourceToken:s,invalidSourceTokenAmount:l,availableToSwap:t&&!n&&!s&&!l,isAuthConnector:a===O.CONNECTOR_ID.AUTH}},async setSourceToken(e){if(!e){r.sourceToken=e,r.sourceTokenAmount="",r.sourceTokenPriceInUSD=0;return}r.sourceToken=e,await d.setTokenPrice(e.address,"sourceToken")},setSourceTokenAmount(e){r.sourceTokenAmount=e},async setToToken(e){if(!e){r.toToken=e,r.toTokenAmount="",r.toTokenPriceInUSD=0;return}r.toToken=e,await d.setTokenPrice(e.address,"toToken")},setToTokenAmount(e){r.toTokenAmount=e?h.toFixed(e,Ve):""},async setTokenPrice(e,t){let o=r.tokensPriceMap[e]||0;o||(r.loadingPrices=!0,o=await d.getAddressPrice(e)),t==="sourceToken"?r.sourceTokenPriceInUSD=o:t==="toToken"&&(r.toTokenPriceInUSD=o),r.loadingPrices&&(r.loadingPrices=!1),d.getParams().availableToSwap&&!r.switchingTokens&&d.swapTokens()},async switchTokens(){if(!(r.initializing||!r.initialized||r.switchingTokens)){r.switchingTokens=!0;try{const e=r.toToken?{...r.toToken}:void 0,t=r.sourceToken?{...r.sourceToken}:void 0,o=e&&r.toTokenAmount===""?"1":r.toTokenAmount;d.setSourceTokenAmount(o),d.setToTokenAmount(""),await d.setSourceToken(e),await d.setToToken(t),r.switchingTokens=!1,d.swapTokens()}catch(e){throw r.switchingTokens=!1,e}}},resetState(){r.myTokensWithBalance=T.myTokensWithBalance,r.tokensPriceMap=T.tokensPriceMap,r.initialized=T.initialized,r.initializing=T.initializing,r.switchingTokens=T.switchingTokens,r.sourceToken=T.sourceToken,r.sourceTokenAmount=T.sourceTokenAmount,r.sourceTokenPriceInUSD=T.sourceTokenPriceInUSD,r.toToken=T.toToken,r.toTokenAmount=T.toTokenAmount,r.toTokenPriceInUSD=T.toTokenPriceInUSD,r.networkPrice=T.networkPrice,r.networkTokenSymbol=T.networkTokenSymbol,r.networkBalanceInUSD=T.networkBalanceInUSD,r.inputError=T.inputError},resetValues(){const{networkAddress:e}=d.getParams(),t=r.tokens?.find(o=>o.address===e);d.setSourceToken(t),d.setToToken(void 0)},getApprovalLoadingState(){return r.loadingApprovalTransaction},clearError(){r.transactionError=void 0},async initializeState(){if(!r.initializing){if(r.initializing=!0,!r.initialized)try{await d.fetchTokens(),r.initialized=!0}catch{r.initialized=!1,g.showError("Failed to initialize swap"),u.goBack()}r.initializing=!1}},async fetchTokens(){const{networkAddress:e}=d.getParams();await d.getNetworkTokenPrice(),await d.getMyTokensWithBalance();const t=r.myTokensWithBalance?.find(o=>o.address===e);t&&(r.networkTokenSymbol=t.symbol,d.setSourceToken(t),d.setSourceTokenAmount("0"))},async getTokenList(){const e=m.state.activeCaipNetwork?.caipNetworkId;if(!(r.caipNetworkId===e&&r.tokens))try{r.tokensLoading=!0;const t=await M.getTokenList(e);r.tokens=t,r.caipNetworkId=e,r.popularTokens=t.sort((s,l)=>s.symbol<l.symbol?-1:s.symbol>l.symbol?1:0);const i=(e&&pe.SUGGESTED_TOKENS_BY_CHAIN?.[e]||[]).map(s=>t.find(l=>l.symbol===s)).filter(s=>!!s),n=(pe.SWAP_SUGGESTED_TOKENS||[]).map(s=>t.find(l=>l.symbol===s)).filter(s=>!!s).filter(s=>!i.some(l=>l.address===s.address));r.suggestedTokens=[...i,...n]}catch{r.tokens=[],r.popularTokens=[],r.suggestedTokens=[]}finally{r.tokensLoading=!1}},async getAddressPrice(e){const t=r.tokensPriceMap[e];if(t)return t;const i=(await j.fetchTokenPrice({addresses:[e]}))?.fungibles||[],n=[...r.tokens||[],...r.myTokensWithBalance||[]]?.find(f=>f.address===e)?.symbol,s=i.find(f=>f.symbol.toLowerCase()===n?.toLowerCase())?.price||0,l=parseFloat(s.toString());return r.tokensPriceMap[e]=l,l},async getNetworkTokenPrice(){const{networkAddress:e}=d.getParams(),o=(await j.fetchTokenPrice({addresses:[e]}).catch(()=>(g.showError("Failed to fetch network token price"),{fungibles:[]}))).fungibles?.[0],i=o?.price.toString()||"0";r.tokensPriceMap[e]=parseFloat(i),r.networkTokenSymbol=o?.symbol||"",r.networkPrice=i},async getMyTokensWithBalance(e){const t=await Fe.getMyTokensWithBalance(e),o=M.mapBalancesToSwapTokens(t);o&&(await d.getInitialGasPrice(),d.setBalances(o))},setBalances(e){const{networkAddress:t}=d.getParams(),o=m.state.activeCaipNetwork;if(!o)return;const i=e.find(a=>a.address===t);e.forEach(a=>{r.tokensPriceMap[a.address]=a.price||0}),r.myTokensWithBalance=e.filter(a=>a.address.startsWith(o.caipNetworkId)),r.networkBalanceInUSD=i?h.multiply(i.quantity.numeric,i.price).toString():"0"},async getInitialGasPrice(){const e=await M.fetchGasPrice();if(!e)return{gasPrice:null,gasPriceInUSD:null};switch(m.state?.activeCaipNetwork?.chainNamespace){case O.CHAIN.SOLANA:return r.gasFee=e.standard??"0",r.gasPriceInUSD=h.multiply(e.standard,r.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(r.gasFee),gasPriceInUSD:Number(r.gasPriceInUSD)};case O.CHAIN.EVM:default:const t=e.standard??"0",o=BigInt(t),i=BigInt(xe),a=D.getGasPriceInUSD(r.networkPrice,i,o);return r.gasFee=t,r.gasPriceInUSD=a,{gasPrice:o,gasPriceInUSD:a}}},async swapTokens(){const e=m.getAccountData()?.address,t=r.sourceToken,o=r.toToken,i=h.bigNumber(r.sourceTokenAmount).gt(0);if(i||d.setToTokenAmount(""),!o||!t||r.loadingPrices||!i||!e)return;r.loadingQuote=!0;const a=h.bigNumber(r.sourceTokenAmount).times(10**t.decimals).round(0);try{const n=await j.fetchSwapQuote({userAddress:e,from:t.address,to:o.address,gasPrice:r.gasFee,amount:a.toString()});r.loadingQuote=!1;const s=n?.quotes?.[0]?.toAmount;if(!s){G.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");return}const l=h.bigNumber(s).div(10**o.decimals).toString();d.setToTokenAmount(l),d.hasInsufficientToken(r.sourceTokenAmount,t.address)?r.inputError="Insufficient balance":(r.inputError=void 0,d.setTransactionDetails())}catch(n){const s=await M.handleSwapError(n);r.loadingQuote=!1,r.inputError=s||"Insufficient balance"}},async getTransaction(){const{fromCaipAddress:e,availableToSwap:t}=d.getParams(),o=r.sourceToken,i=r.toToken;if(!(!e||!t||!o||!i||r.loadingQuote))try{r.loadingBuildTransaction=!0;const a=await M.fetchSwapAllowance({userAddress:e,tokenAddress:o.address,sourceTokenAmount:r.sourceTokenAmount,sourceTokenDecimals:o.decimals});let n;return a?n=await d.createSwapTransaction():n=await d.createAllowanceTransaction(),r.loadingBuildTransaction=!1,r.fetchError=!1,n}catch{u.goBack(),g.showError("Failed to check allowance"),r.loadingBuildTransaction=!1,r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}},async createAllowanceTransaction(){const{fromCaipAddress:e,sourceTokenAddress:t,toTokenAddress:o}=d.getParams();if(!(!e||!o)){if(!t)throw new Error("createAllowanceTransaction - No source token address found.");try{const i=await j.generateApproveCalldata({from:t,to:o,userAddress:e}),a=de.getPlainAddress(i.tx.from);if(!a)throw new Error("SwapController:createAllowanceTransaction - address is required");const n={data:i.tx.data,to:a,gasPrice:BigInt(i.tx.eip155.gasPrice),value:BigInt(i.tx.value),toAmount:r.toTokenAmount};return r.swapTransaction=void 0,r.approvalTransaction={data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount},{data:n.data,to:n.to,gasPrice:n.gasPrice,value:n.value,toAmount:n.toAmount}}catch{u.goBack(),g.showError("Failed to create approval transaction"),r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}}},async createSwapTransaction(){const{networkAddress:e,fromCaipAddress:t,sourceTokenAmount:o}=d.getParams(),i=r.sourceToken,a=r.toToken;if(!t||!o||!i||!a)return;const n=te.parseUnits(o,i.decimals)?.toString();try{const s=await j.generateSwapCalldata({userAddress:t,from:i.address,to:a.address,amount:n,disableEstimate:!0}),l=i.address===e,f=BigInt(s.tx.eip155.gas),ye=BigInt(s.tx.eip155.gasPrice),ke=de.getPlainAddress(s.tx.to);if(!ke)throw new Error("SwapController:createSwapTransaction - address is required");const Te={data:s.tx.data,to:ke,gas:f,gasPrice:ye,value:BigInt(l?n??"0":"0"),toAmount:r.toTokenAmount};return r.gasPriceInUSD=D.getGasPriceInUSD(r.networkPrice,f,ye),r.approvalTransaction=void 0,r.swapTransaction=Te,Te}catch{u.goBack(),g.showError("Failed to create transaction"),r.approvalTransaction=void 0,r.swapTransaction=void 0,r.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){g.showLoading("Approve limit increase in your wallet"),u.replace("SwapPreview")},async sendTransactionForApproval(e){const{fromAddress:t,isAuthConnector:o}=d.getParams();r.loadingApprovalTransaction=!0,o?u.pushTransactionStack({onSuccess:d.onEmbeddedWalletApprovalSuccess}):g.showLoading("Approve limit increase in your wallet");try{await te.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:O.CHAIN.EVM}),await d.swapTokens(),await d.getTransaction(),r.approvalTransaction=void 0,r.loadingApprovalTransaction=!1}catch(a){const n=a;r.transactionError=n?.displayMessage,r.loadingApprovalTransaction=!1,g.showError(n?.displayMessage||"Transaction error"),_.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:n?.displayMessage||n?.message||"Unknown",network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(e){if(!e)return;const{fromAddress:t,toTokenAmount:o,isAuthConnector:i}=d.getParams();r.loadingTransaction=!0;const a=`Swapping ${r.sourceToken?.symbol} to ${h.formatNumberToLocalString(o,3)} ${r.toToken?.symbol}`,n=`Swapped ${r.sourceToken?.symbol} to ${h.formatNumberToLocalString(o,3)} ${r.toToken?.symbol}`;i?u.pushTransactionStack({onSuccess(){u.replace("Account"),g.showLoading(a),ie.resetState()}}):g.showLoading("Confirm transaction in your wallet");try{const s=[r.sourceToken?.address,r.toToken?.address].join(","),l=await te.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:O.CHAIN.EVM});return r.loadingTransaction=!1,g.showSuccess(n),_.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}}),ie.resetState(),i||u.replace("Account"),ie.getMyTokensWithBalance(s),l}catch(s){const l=s;r.transactionError=l?.displayMessage,r.loadingTransaction=!1,g.showError(l?.displayMessage||"Transaction error"),_.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:l?.displayMessage||l?.message||"Unknown",network:m.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:d.state.sourceToken?.symbol||"",swapToToken:d.state.toToken?.symbol||"",swapFromAmount:d.state.sourceTokenAmount||"",swapToAmount:d.state.toTokenAmount||"",isSmartAccount:oe(O.CHAIN.EVM)===ne.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken(e,t){return D.isInsufficientSourceTokenForSwap(e,t,r.myTokensWithBalance)},setTransactionDetails(){const{toTokenAddress:e,toTokenDecimals:t}=d.getParams();!e||!t||(r.gasPriceInUSD=D.getGasPriceInUSD(r.networkPrice,BigInt(r.gasFee),BigInt(xe)),r.priceImpact=D.getPriceImpact({sourceTokenAmount:r.sourceTokenAmount,sourceTokenPriceInUSD:r.sourceTokenPriceInUSD,toTokenPriceInUSD:r.toTokenPriceInUSD,toTokenAmount:r.toTokenAmount}),r.maxSlippage=D.getMaxSlippage(r.slippage,r.toTokenAmount),r.providerFee=D.getProviderFee(r.sourceTokenAmount))}},d=Pe(ie),A=Ie({message:"",open:!1,triggerRect:{width:0,height:0,top:0,left:0},variant:"shade"}),Ge={state:A,subscribe(e){return Ne(A,()=>e(A))},subscribeKey(e,t){return Ee(A,e,t)},showTooltip({message:e,triggerRect:t,variant:o}){A.open=!0,A.message=e,A.triggerRect=t,A.variant=o},hide(){A.open=!1,A.message="",A.triggerRect={width:0,height:0,top:0,left:0}}},V=Pe(Ge),_e={isUnsupportedChainView(){return u.state.view==="UnsupportedChain"||u.state.view==="SwitchNetwork"&&u.state.history.includes("UnsupportedChain")},async safeClose(){if(this.isUnsupportedChainView()){P.shake();return}if(await We.isSIWXCloseDisabled()){P.shake();return}(u.state.view==="DataCapture"||u.state.view==="DataCaptureOtpConfirm")&&te.disconnect(),P.close()}},Ke=S`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
border-radius: clamp(0px, ${({borderRadius:e})=>e[8]}, 44px);
|
package/index.html
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-20723159718.commit-457ece6/dcl-regenesislabs.png" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>DCL Regenesis Labs Mobile Hub</title>
|
|
8
|
-
<script type="module" crossorigin src="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-
|
|
8
|
+
<script type="module" crossorigin src="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-20723159718.commit-457ece6/assets/index-i2A_phFP.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-20723159718.commit-457ece6/assets/index-D42x9zzA.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl-regenesislabs/mobile-hub",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-20723159718.commit-457ece6",
|
|
4
4
|
"description": "Mobile Hub",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/decentraland/mobile-hub.git"
|
|
19
19
|
},
|
|
20
|
-
"homepage": "https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-
|
|
21
|
-
"commit": "
|
|
20
|
+
"homepage": "https://cdn.decentraland.org/@dcl-regenesislabs/mobile-hub/1.0.0-20723159718.commit-457ece6",
|
|
21
|
+
"commit": "457ece649d377cd3b02a5fe14d6398db0a4a5f25"
|
|
22
22
|
}
|