PageSourceSearch

https://devconnect.org/_next/static/chunks/7961.fa028379619f1667.js

js devconnect.org collected 2026-10-03 21:04:21 UTC 15,385 bytes, 35 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7961],{51636:(e,o,t)=>{var a=t(22707),r=t(71877);t(2657),t(67327);var n=t(12248),s=t(64859);t(79933);let i=(0,a.AH)`
2  :host {
3    display: block;
4  }
5
6  :host > button {
7    gap: var(--wui-spacing-xxs);
8    padding: var(--wui-spacing-xs);
9    padding-right: var(--wui-spacing-1xs);
10    height: 40px;
11    border-radius: var(--wui-border-radius-l);
12    background: var(--wui-color-gray-glass-002);
13    border-width: 0px;
14    box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-002);
15  }
16
17  :host > button wui-image {
18    width: 24px;
19    height: 24px;
20    border-radius: var(--wui-border-radius-s);
21    box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-010);
22  }
23`;var c=function(e,o,t,a){var r,n=arguments.length,s=n<3?o:null===a?a=Object.getOwnPropertyDescriptor(o,t):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,o,t,a);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(s=(n<3?r(s):n>3?r(o,t,s):r(o,t))||s);return n>3&&s&&Object.defineProperty(o,t,s),s};let u=class extends a.WF{constructor(){super(...arguments),this.text=""}render(){return(0,a.qy)`
24      <button>
25        ${this.tokenTemplate()}
26        <wui-text variant="paragraph-600" color="fg-100">${this.text}</wui-text>
27      </button>
28    `}tokenTemplate(){return this.imageSrc?(0,a.qy)`<wui-image src=${this.imageSrc}></wui-image>`:(0,a.qy)`
29      <wui-icon-box
30        size="sm"
31        iconColor="fg-200"
32        backgroundColor="fg-300"
33        icon="networkPlaceholder"
34      ></wui-icon-box>
35    `}};u.styles=[n.W5,n.fD,i],c([(0,r.MZ)()],u.prototype,"imageSrc",void 0),c([(0,r.MZ)()],u.prototype,"text",void 0),u=c([(0,s.E)("wui-token-button")],u)},96060:(e,o,t)=>{t.d(o,{GN:()=>N});var a=t(42649),r=t(65501),n=t(58692),s=t(34907),i=t(98280),c=t(58672),u=t(11862),l=t(40818),d=t(85934),T=t(21682);let k={getGasPriceInEther:(e,o)=>Number(o*e)/1e18,getGasPriceInUSD(e,o,t){let a=k.getGasPriceInEther(o,t);return n.S.bigNumber(e).times(a).toNumber()},getPriceImpact({sourceTokenAmount:e,sourceTokenPriceInUSD:o,toTokenPriceInUSD:t,toTokenAmount:a}){let r=n.S.bigNumber(e).times(o),s=n.S.bigNumber(a).times(t);return r.minus(s).div(r).times(100).toNumber()},getMaxSlippage(e,o){let t=n.S.bigNumber(e).div(100);return n.S.multiply(o,t).toNumber()},getProviderFee:(e,o=.0085)=>n.S.bigNumber(e).times(o).toString(),isInsufficientNetworkTokenForGas:(e,o)=>!!n.S.bigNumber(e).eq(0)||n.S.bigNumber(n.S.bigNumber(o||"0")).gt(e),isInsufficientSourceTokenForSwap(e,o,t){let a=t?.find(e=>e.address===o)?.quantity?.numeric;return n.S.bigNumber(a||"0").lt(e)},getToTokenAmount({sourceToken:e,toToken:o,sourceTokenPrice:t,toTokenPrice:a,sourceTokenAmount:r}){if("0"===r||!e||!o)return"0";let s=e.decimals,i=o.decimals;if(a<=0)return"0";let c=n.S.bigNumber(r).times(.0085),u=n.S.bigNumber(r).minus(c).times(n.S.bigNumber(10).pow(s)),l=n.S.bigNumber(t).div(a),d=s-i;return u.times(l).div(n.S.bigNumber(10).pow(d)).div(n.S.bigNumber(10).pow(i)).toFixed(i).toString()}};var g=t(66585),m=t(35728),p=t(41421),w=t(35149),S=t(12890),A=t(2767),P=t(15176),b=t(77424),v=t(6792),h=t(72317);let f={initializing:!1,initialized:!1,loadingPrices:!1,loadingQuote:!1,loadingApprovalTransaction:!1,loadingBuildTransaction:!1,loadingTransaction:!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:l.oU.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},y=(0,a.BX)(f),I={state:y,subscribe:e=>(0,a.B1)(y,()=>e(y)),subscribeKey:(e,o)=>(0,r.u$)(y,e,o),getParams(){let e=S.W.state.activeCaipAddress,o=d.w.getPlainAddress(e),t=(0,u.K1)(),a=P.a.getConnectorId(S.W.state.activeChain);if(!o)throw Error("No address found to swap the tokens from.");let r=!y.toToken?.address||!y.toToken?.decimals,i=!y.sourceToken?.address||!y.sourceToken?.decimals||!n.S.bigNumber(y.sourceTokenAmount).gt(0),c=!y.sourceTokenAmount;return{networkAddress:t,fromAddress:o,fromCaipAddress:e,sourceTokenAddress:y.sourceToken?.address,toTokenAddress:y.toToken?.address,toTokenAmount:y.toTokenAmount,toTokenDecimals:y.toToken?.decimals,sourceTokenAmount:y.sourceTokenAmount,sourceTokenDecimals:y.sourceToken?.decimals,invalidToToken:r,invali
35dSourceToken:i,invalidSourceTokenAmount:c,availableToSwap:e&&!r&&!i&&!c,isAuthConnector:a===s.o.CONNECTOR_ID.AUTH}},setSourceToken(e){if(!e){y.sourceToken=e,y.sourceTokenAmount="",y.sourceTokenPriceInUSD=0;return}y.sourceToken=e,N.setTokenPrice(e.address,"sourceToken")},setSourceTokenAmount(e){y.sourceTokenAmount=e},setToToken(e){if(!e){y.toToken=e,y.toTokenAmount="",y.toTokenPriceInUSD=0;return}y.toToken=e,N.setTokenPrice(e.address,"toToken")},setToTokenAmount(e){y.toTokenAmount=e?n.S.formatNumberToLocalString(e,6):""},async setTokenPrice(e,o){let t=y.tokensPriceMap[e]||0;t||(y.loadingPrices=!0,t=await N.getAddressPrice(e)),"sourceToken"===o?y.sourceTokenPriceInUSD=t:"toToken"===o&&(y.toTokenPriceInUSD=t),y.loadingPrices&&(y.loadingPrices=!1),N.getParams().availableToSwap&&N.swapTokens()},switchTokens(){if(y.initializing||!y.initialized)return;let e=y.toToken?{...y.toToken}:void 0,o=y.sourceToken?{...y.sourceToken}:void 0,t=e&&""===y.toTokenAmount?"1":y.toTokenAmount;N.setSourceToken(e),N.setToToken(o),N.setSourceTokenAmount(t),N.setToTokenAmount(""),N.swapTokens()},resetState(){y.myTokensWithBalance=f.myTokensWithBalance,y.tokensPriceMap=f.tokensPriceMap,y.initialized=f.initialized,y.sourceToken=f.sourceToken,y.sourceTokenAmount=f.sourceTokenAmount,y.sourceTokenPriceInUSD=f.sourceTokenPriceInUSD,y.toToken=f.toToken,y.toTokenAmount=f.toTokenAmount,y.toTokenPriceInUSD=f.toTokenPriceInUSD,y.networkPrice=f.networkPrice,y.networkTokenSymbol=f.networkTokenSymbol,y.networkBalanceInUSD=f.networkBalanceInUSD,y.inputError=f.inputError,y.myTokensWithBalance=f.myTokensWithBalance},resetValues(){let{networkAddress:e}=N.getParams(),o=y.tokens?.find(o=>o.address===e);N.setSourceToken(o),N.setToToken(void 0)},getApprovalLoadingState:()=>y.loadingApprovalTransaction,clearError(){y.transactionError=void 0},async initializeState(){if(!y.initializing){if(y.initializing=!0,!y.initialized)try{await N.fetchTokens(),y.initialized=!0}catch(e){y.initialized=!1,h.P.showError("Failed to initialize swap"),v.I.goBack()}y.initializing=!1}},async fetchTokens(){let{networkAddress:e}=N.getParams();await N.getTokenList(),await N.getNetworkTokenPrice(),await N.getMyTokensWithBalance();let o=y.tokens?.find(o=>o.address===e);o&&(y.networkTokenSymbol=o.symbol,N.setSourceToken(o),N.setSourceTokenAmount("0"))},async getTokenList(){let e=await T.s.getTokenList();y.tokens=e,y.popularTokens=e.sort((e,o)=>e.symbol<o.symbol?-1:+(e.symbol>o.symbol)),y.suggestedTokens=e.filter(e=>!!l.oU.SWAP_SUGGESTED_TOKENS.includes(e.symbol),{})},async getAddressPrice(e){let o=y.tokensPriceMap[e];if(o)return o;let t=await w.T.fetchTokenPrice({addresses:[e]}),a=t?.fungibles||[],r=[...y.tokens||[],...y.myTokensWithBalance||[]],n=r?.find(o=>o.address===e)?.symbol,s=parseFloat((a.find(e=>e.symbol.toLowerCase()===n?.toLowerCase())?.price||0).toString());return y.tokensPriceMap[e]=s,s},async getNetworkTokenPrice(){let{networkAddress:e}=N.getParams(),o=await w.T.fetchTokenPrice({addresses:[e]}).catch(()=>(h.P.showError("Failed to fetch network token price"),{fungibles:[]})),t=o.fungibles?.[0],a=t?.price.toString()||"0";y.tokensPriceMap[e]=parseFloat(a),y.networkTokenSymbol=t?.symbol||"",y.networkPrice=a},async getMyTokensWithBalance(e){let o=await c.Z.getMyTokensWithBalance(e),t=T.s.mapBalancesToSwapTokens(o);t&&(await N.getInitialGasPrice(),N.setBalances(t))},setBalances(e){let{networkAddress:o}=N.getParams(),t=S.W.state.activeCaipNetwork;if(!t)return;let a=e.find(e=>e.address===o);e.forEach(e=>{y.tokensPriceMap[e.address]=e.price||0}),y.myTokensWithBalance=e.filter(e=>e.address.startsWith(t.caipNetworkId)),y.networkBalanceInUSD=a?n.S.multiply(a.quantity.numeric,a.price).toString():"0"},async getInitialGasPrice(){let e=await T.s.fetchGasPrice();if(!e)return{gasPrice:null,gasPriceInUSD:null};switch(S.W.state?.activeCaipNetwork?.chainNamespace){case s.o.CHAIN.SOLANA:return y.gasFee=e.standard??"0",y.gasPriceInUSD=n.S.multiply(e.standard,y.networkPrice).div(1e9).toNumber(),{gasPrice:BigInt(y.gasFee),gasPriceInUSD:Number(y.gasPriceInUSD)};case s.o.CHAIN.EVM:default:let o=e.standard??"0",t=BigInt(o),a=BigInt(15e4),r=k.getGasPriceInUSD(y.networkPrice,a,t);return y.gasFee=o,y.gasPriceInUSD=r,{gasPrice:t,gasPriceInUSD:r}}},async swapTokens(){let e=m.U.state.address,o=y.sourceToken,t=y.toToken,a=n.S.bigNumber(y.sourceTokenAmount).gt(0);if(a||N.setToTokenAmount(""),!t||!o||y.loadingPrices||!a)return;y.loadingQuote=!0;let r=n.S.bigNumber(y.sourceTokenAmount).times(10**o.decimals).round(0);try{let a=await w.T.fetchSwapQuote({userAddress:e,from:o.address,to:t.address,gasPrice:y.gasFee,amount:r.toString()});y.loadingQuote=!1;let s=a?.quotes?.[0]?.toAmount;if(!s)return void p.h.open({displayMessage:"Incorrect amount",debugMessage:"Please enter a valid amount"},"error");let i=n.S.bigNumber(s).div(10**t.decimals).toString();N.setToTokenAmount(i),N.hasInsufficientToken(y.sourceTokenAmount,o.address)?y.inputError="Insufficient balance":(y.inputError=void 0,N.setTransactionDetail
35s())}catch(e){y.loadingQuote=!1,y.inputError="Insufficient balance"}},async getTransaction(){let{fromCaipAddress:e,availableToSwap:o}=N.getParams(),t=y.sourceToken,a=y.toToken;if(e&&o&&t&&a&&!y.loadingQuote)try{let o;return y.loadingBuildTransaction=!0,o=await T.s.fetchSwapAllowance({userAddress:e,tokenAddress:t.address,sourceTokenAmount:y.sourceTokenAmount,sourceTokenDecimals:t.decimals})?await N.createSwapTransaction():await N.createAllowanceTransaction(),y.loadingBuildTransaction=!1,y.fetchError=!1,o}catch(e){v.I.goBack(),h.P.showError("Failed to check allowance"),y.loadingBuildTransaction=!1,y.approvalTransaction=void 0,y.swapTransaction=void 0,y.fetchError=!0;return}},async createAllowanceTransaction(){let{fromCaipAddress:e,sourceTokenAddress:o,toTokenAddress:t}=N.getParams();if(e&&t){if(!o)throw Error("createAllowanceTransaction - No source token address found.");try{let a=await w.T.generateApproveCalldata({from:o,to:t,userAddress:e}),r=d.w.getPlainAddress(a.tx.from);if(!r)throw Error("SwapController:createAllowanceTransaction - address is required");let n={data:a.tx.data,to:r,gasPrice:BigInt(a.tx.eip155.gasPrice),value:BigInt(a.tx.value),toAmount:y.toTokenAmount};return y.swapTransaction=void 0,y.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(e){v.I.goBack(),h.P.showError("Failed to create approval transaction"),y.approvalTransaction=void 0,y.swapTransaction=void 0,y.fetchError=!0;return}}},async createSwapTransaction(){let{networkAddress:e,fromCaipAddress:o,sourceTokenAmount:t}=N.getParams(),a=y.sourceToken,r=y.toToken;if(!o||!t||!a||!r)return;let n=A.x.parseUnits(t,a.decimals)?.toString();try{let t=await w.T.generateSwapCalldata({userAddress:o,from:a.address,to:r.address,amount:n,disableEstimate:!0}),s=a.address===e,i=BigInt(t.tx.eip155.gas),c=BigInt(t.tx.eip155.gasPrice),u=d.w.getPlainAddress(t.tx.to);if(!u)throw Error("SwapController:createSwapTransaction - address is required");let l={data:t.tx.data,to:u,gas:i,gasPrice:c,value:s?BigInt(n??"0"):BigInt("0"),toAmount:y.toTokenAmount};return y.gasPriceInUSD=k.getGasPriceInUSD(y.networkPrice,i,c),y.approvalTransaction=void 0,y.swapTransaction=l,l}catch(e){v.I.goBack(),h.P.showError("Failed to create transaction"),y.approvalTransaction=void 0,y.swapTransaction=void 0,y.fetchError=!0;return}},onEmbeddedWalletApprovalSuccess(){h.P.showLoading("Approve limit increase in your wallet"),v.I.replace("SwapPreview")},async sendTransactionForApproval(e){let{fromAddress:o,isAuthConnector:t}=N.getParams();y.loadingApprovalTransaction=!0,t?v.I.pushTransactionStack({onSuccess:N.onEmbeddedWalletApprovalSuccess}):h.P.showLoading("Approve limit increase in your wallet");try{await A.x.sendTransaction({address:o,to:e.to,data:e.data,value:e.value,chainNamespace:s.o.CHAIN.EVM}),await N.swapTokens(),await N.getTransaction(),y.approvalTransaction=void 0,y.loadingApprovalTransaction=!1}catch(e){y.transactionError=e?.displayMessage,y.loadingApprovalTransaction=!1,h.P.showError(e?.displayMessage||"Transaction error"),b.E.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:e?.displayMessage||e?.message||"Unknown",network:S.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:(0,u.lj)(s.o.CHAIN.EVM)===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(e){if(!e)return;let{fromAddress:o,toTokenAmount:t,isAuthConnector:a}=N.getParams();y.loadingTransaction=!0;let r=`Swapping ${y.sourceToken?.symbol} to ${n.S.formatNumberToLocalString(t,3)} ${y.toToken?.symbol}`,c=`Swapped ${y.sourceToken?.symbol} to ${n.S.formatNumberToLocalString(t,3)} ${y.toToken?.symbol}`;a?v.I.pushTransactionStack({onSuccess(){v.I.replace("Account"),h.P.showLoading(r),I.resetState()}}):h.P.showLoading("Confirm transaction in your wallet");try{let t=[y.sourceToken?.address,y.toToken?.address].join(","),r=await A.x.sendTransaction({address:o,to:e.to,data:e.data,value:e.value,chainNamespace:s.o.CHAIN.EVM});return y.loadingTransaction=!1,h.P.showSuccess(c),b.E.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:S.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:(0,u.lj)(s.o.CHAIN.EVM)===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}}),I.resetState(),a||v.I.replace("Account"),I.getMyTokensWithBalance(t),r}catch(e){y.transactionError=e?.displayMessage,y.loadingTransaction=!1,h.P.showError(e?.displayMessage||"Transaction error"),b.E.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:e?.displayMessage||e?.message||"Unknown",network:S.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:(0,u.lj)(s.o.CHAIN.EVM)===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken:(e,o)=>k.isInsufficientSourceTokenForSwap(e,o,y.myTokensWithBalance),setTransactionDetail
35s(){let{toTokenAddress:e,toTokenDecimals:o}=N.getParams();e&&o&&(y.gasPriceInUSD=k.getGasPriceInUSD(y.networkPrice,BigInt(y.gasFee),BigInt(15e4)),y.priceImpact=k.getPriceImpact({sourceTokenAmount:y.sourceTokenAmount,sourceTokenPriceInUSD:y.sourceTokenPriceInUSD,toTokenPriceInUSD:y.toTokenPriceInUSD,toTokenAmount:y.toTokenAmount}),y.maxSlippage=k.getMaxSlippage(y.slippage,y.toTokenAmount),y.providerFee=k.getProviderFee(y.sourceTokenAmount))}},N=(0,g.X)(I)}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.