PageSourceSearch

https://opencollective.xyz/_next/static/chunks/5533.3155f36e9f769b54.js

js opencollective.xyz collected 2026-10-06 12:16:35 UTC 16,744 bytes, 61 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5533],{30725:(e,t,o)=>{o.d(t,{GN:()=>N});var a=o(30522),r=o(61156),n=o(30332),s=o(11731),i=o(32375),c=o(29640),u=o(75387),l=o(88515),d=o(59085),T=o(81839);let k={getGasPriceInEther:(e,t)=>Number(t*e)/1e18,getGasPriceInUSD(e,t,o){let a=k.getGasPriceInEther(t,o);return n.S.bigNumber(e).times(a).toNumber()},getPriceImpact({sourceTokenAmount:e,sourceTokenPriceInUSD:t,toTokenPriceInUSD:o,toTokenAmount:a}){let r=n.S.bigNumber(e).times(t),s=n.S.bigNumber(a).times(o);return r.minus(s).div(r).times(100).toNumber()},getMaxSlippage(e,t){let o=n.S.bigNumber(e).div(100);return n.S.multiply(t,o).toNumber()},getProviderFee:(e,t=.0085)=>n.S.bigNumber(e).times(t).toString(),isInsufficientNetworkTokenForGas:(e,t)=>!!n.S.bigNumber(e).eq(0)||n.S.bigNumber(n.S.bigNumber(t||"0")).gt(e),isInsufficientSourceTokenForSwap(e,t,o){let a=o?.find(e=>e.address===t)?.quantity?.numeric;return n.S.bigNumber(a||"0").lt(e)},getToTokenAmount({sourceToken:e,toToken:t,sourceTokenPrice:o,toTokenPrice:a,sourceTokenAmount:r}){if("0"===r||!e||!t)return"0";let s=e.decimals,i=t.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(o).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=o(5738),p=o(69485),m=o(97268),w=o(636),h=o(18539),S=o(85845),b=o(4537),P=o(66699),v=o(83503),A=o(10840);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,t)=>(0,r.u$)(y,e,t),getParams(){let e=h.W.state.activeCaipAddress,t=h.W.state.activeChain,o=d.w.getPlainAddress(e),a=(0,u.K)(),r=b.a.getConnectorId(t);if(!o)throw Error("No address found to swap the tokens from.");let i=!y.toToken?.address||!y.toToken?.decimals,c=!y.sourceToken?.address||!y.sourceToken?.decimals||!n.S.bigNumber(y.sourceTokenAmount).gt(0),l=!y.sourceTokenAmount;return{networkAddress:a,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:i,invalidSourceToken:c,invalidSourceTokenAmount:l,availableToSwap:e&&!i&&!c&&!l,isAuthConnector:r===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,t){let o=y.tokensPriceMap[e]||0;o||(y.loadingPrices=!0,o=await N.getAddressPrice(e)),"sourceToken"===t?y.sourceTokenPriceInUSD=o:"toToken"===t&&(y.toTokenPriceInUSD=o),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,t=y.sourceToken?{...y.sourceToken}:void 0,o=e&&""===y.toTokenAmount?"1":y.toTokenAmount;N.setSourceToken(e),N.setToToken(t),N.setSourceTokenAmount(o),N.setToTokenAmount(""),N.swapTokens()},resetState(){y.myTokensWithBalance=f.myTokensWithBalance,y.tokensPriceMap=f.tokensPriceMap,y.initialized=f.
1initialized,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(),t=y.tokens?.find(t=>t.address===e);N.setSourceToken(t),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,A.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 t=y.tokens?.find(t=>t.address===e);t&&(y.networkTokenSymbol=t.symbol,N.setSourceToken(t),N.setSourceTokenAmount("1"))},async getTokenList(){let e=await T.s.getTokenList();y.tokens=e,y.popularTokens=e.sort((e,t)=>e.symbol<t.symbol?-1:e.symbol>t.symbol?1:0),y.suggestedTokens=e.filter(e=>!!l.oU.SWAP_SUGGESTED_TOKENS.includes(e.symbol),{})},async getAddressPrice(e){let t=y.tokensPriceMap[e];if(t)return t;let o=await w.T.fetchTokenPrice({addresses:[e]}),a=o?.fungibles||[],r=[...y.tokens||[],...y.myTokensWithBalance||[]],n=r?.find(t=>t.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(),t=await w.T.fetchTokenPrice({addresses:[e]}).catch(()=>(A.P.showError("Failed to fetch network token price"),{fungibles:[]})),o=t.fungibles?.[0],a=o?.price.toString()||"0";y.tokensPriceMap[e]=parseFloat(a),y.networkTokenSymbol=o?.symbol||"",y.networkPrice=a},async getMyTokensWithBalance(e){let t=await c.Z.getMyTokensWithBalance(e),o=T.s.mapBalancesToSwapTokens(t);o&&(await N.getInitialGasPrice(),N.setBalances(o))},setBalances(e){let{networkAddress:t}=N.getParams(),o=h.W.state.activeCaipNetwork;if(!o)return;let a=e.find(e=>e.address===t);e.forEach(e=>{y.tokensPriceMap[e.address]=e.price||0}),y.myTokensWithBalance=e.filter(e=>e.address.startsWith(o.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};if(h.W.state?.activeCaipNetwork?.chainNamespace==="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)};{let t=e.standard??"0",o=BigInt(t),a=BigInt(15e4),r=k.getGasPriceInUSD(y.networkPrice,a,o);return y.gasFee=t,y.gasPriceInUSD=r,{gasPrice:o,gasPriceInUSD:r}}},async swapTokens(){let e=p.U.state.address,t=y.sourceToken,o=y.toToken,a=n.S.bigNumber(y.sourceTokenAmount).gt(0);if(a||N.setToTokenAmount(""),!o||!t||y.loadingPrices||!a)return;y.loadingQuote=!0;let r=n.S.bigNumber(y.sourceTokenAmount).times(10**t.decimals).round(0);try{let a=await w.T.fetchSwapQuote({userAddress:e,from:t.address,to:o.address,gasPrice:y.gasFee,amount:r.toString()});y.loadingQuote=!1;let s=a?.quotes?.[0]?.toAmount;if(!s){m.h.open({shortMessage:"Incorrect amount",longMessage:"Please enter a valid amount"},"error");return}let i=n.S.bigNumber(s).div(10**o.decimals).toString();N.setToTokenAmount(i),N.hasInsufficientToken(y.sourceTokenAmount,t.address)?y.inputError="Insufficient balance":(y.inputError=void 0,N.setTransactionDetails())}catch(e){y.loadingQuote=!1,y.inputError="Insufficient balance"}},async getTransaction(){let{fromCaipAddress:e,availableToSwap:t}=N.getParams(),o=y.sourceToken,a=y.toToken;if(e&&t&&o&&a&&!y.loadingQuote)try{let t;return y.loadingBuildTransaction=!0,t=await T.s.fetchSwapAllowance({userAddress:e,tokenAddress:o.address,sourceTokenAmount:y.sourceTokenAmount,sourceTokenDecimals:o.decimals})?await N.createSwapTransaction():await N.createAllowanceTransaction(),y.loadingBuildTransaction=!1,y.fetchError=!1,t}catch(e){v.I.goBack(),A.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:t,toTokenAddress:o}=N.getParams();if(e&&o){if(!t)throw Error("createAllowanceTransaction - No source token address found.");try{let a=await w.T.generateApproveCalldata({from:t,to:o,userAddress:e}),r={data:a.tx.data,to:d.w.getPlainAddress(a.tx.from),gasPrice:BigInt(
1a.tx.eip155.gasPrice),value:BigInt(a.tx.value),toAmount:y.toTokenAmount};return y.swapTransaction=void 0,y.approvalTransaction={data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount},{data:r.data,to:r.to,gasPrice:r.gasPrice,value:r.value,toAmount:r.toAmount}}catch(e){v.I.goBack(),A.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:t,sourceTokenAmount:o}=N.getParams(),a=y.sourceToken,r=y.toToken;if(!t||!o||!a||!r)return;let n=S.x.parseUnits(o,a.decimals)?.toString();try{let o=await w.T.generateSwapCalldata({userAddress:t,from:a.address,to:r.address,amount:n,disableEstimate:!0}),s=a.address===e,i=BigInt(o.tx.eip155.gas),c=BigInt(o.tx.eip155.gasPrice),u={data:o.tx.data,to:d.w.getPlainAddress(o.tx.to),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=u,u}catch(e){v.I.goBack(),A.P.showError("Failed to create transaction"),y.approvalTransaction=void 0,y.swapTransaction=void 0,y.fetchError=!0;return}},async sendTransactionForApproval(e){let{fromAddress:t,isAuthConnector:o}=N.getParams();y.loadingApprovalTransaction=!0;let a="Approve limit increase in your wallet";o?v.I.pushTransactionStack({onSuccess(){A.P.showLoading(a)}}):A.P.showLoading(a);try{await S.x.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:"eip155"}),await N.swapTokens(),await N.getTransaction(),y.approvalTransaction=void 0,y.loadingApprovalTransaction=!1}catch(e){y.transactionError=e?.shortMessage,y.loadingApprovalTransaction=!1,A.P.showError(e?.shortMessage||"Transaction error"),P.E.sendEvent({type:"track",event:"SWAP_APPROVAL_ERROR",properties:{message:e?.shortMessage||e?.message||"Unknown",network:h.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:p.U.state.preferredAccountTypes?.eip155===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}})}},async sendTransactionForSwap(e){if(!e)return;let{fromAddress:t,toTokenAmount:o,isAuthConnector:a}=N.getParams();y.loadingTransaction=!0;let r=`Swapping ${y.sourceToken?.symbol} to ${n.S.formatNumberToLocalString(o,3)} ${y.toToken?.symbol}`,s=`Swapped ${y.sourceToken?.symbol} to ${n.S.formatNumberToLocalString(o,3)} ${y.toToken?.symbol}`;a?v.I.pushTransactionStack({onSuccess(){v.I.replace("Account"),A.P.showLoading(r),I.resetState()}}):A.P.showLoading("Confirm transaction in your wallet");try{let o=[y.sourceToken?.address,y.toToken?.address].join(","),r=await S.x.sendTransaction({address:t,to:e.to,data:e.data,value:e.value,chainNamespace:"eip155"});return y.loadingTransaction=!1,A.P.showSuccess(s),P.E.sendEvent({type:"track",event:"SWAP_SUCCESS",properties:{network:h.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:p.U.state.preferredAccountTypes?.eip155===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}}),I.resetState(),a||v.I.replace("Account"),I.getMyTokensWithBalance(o),r}catch(e){y.transactionError=e?.shortMessage,y.loadingTransaction=!1,A.P.showError(e?.shortMessage||"Transaction error"),P.E.sendEvent({type:"track",event:"SWAP_ERROR",properties:{message:e?.shortMessage||e?.message||"Unknown",network:h.W.state.activeCaipNetwork?.caipNetworkId||"",swapFromToken:N.state.sourceToken?.symbol||"",swapToToken:N.state.toToken?.symbol||"",swapFromAmount:N.state.sourceTokenAmount||"",swapToAmount:N.state.toTokenAmount||"",isSmartAccount:p.U.state.preferredAccountTypes?.eip155===i.Vl.ACCOUNT_TYPES.SMART_ACCOUNT}});return}},hasInsufficientToken:(e,t)=>k.isInsufficientSourceTokenForSwap(e,t,y.myTokensWithBalance),setTransactionDetails(){let{toTokenAddress:e,toTokenDecimals:t}=N.getParams();e&&t&&(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)},66571:(e,t,o)=>{o(28009)},98082:(e,t,o)=>{o(60665)},67411:(e,t,o)=>{var a=o(41270),r=o(12456);o(55602),o(13076);var n=o(67998),s=o(45857);o(38542);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,t,o,a){var r,n=arguments.length,s=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,a);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(s=(n<3?r(s):n>3?r(t,o,s):r(t,o))||s);return n>3&&s&&Object.defineProperty(t,o,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)},55602:(e,t,o)=>{var a=o(41270),r=o(12456),n=o(67998),s=o(45857);let i=(0,a.AH)`
36  :host {
37    display: block;
38    width: var(--local-width);
39    height: var(--local-height);
40  }
41
42  :host([data-object-fit='cover']) img {
43    object-fit: cover;
44    object-position: center center;
45  }
46
47  :host([data-object-fit='contain']) img {
48    object-fit: contain;
49    object-position: center center;
50  }
51
52  img {
53    display: block;
54    width: 100%;
55    height: 100%;
56    border-radius: inherit;
57  }
58`;var c=function(e,t,o,a){var r,n=arguments.length,s=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,a);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(s=(n<3?r(s):n>3?r(t,o,s):r(t,o))||s);return n>3&&s&&Object.defineProperty(t,o,s),s};let u=class extends a.WF{constructor(){super(...arguments),this.src="./path/to/image.jpg",this.alt="Image",this.size=void 0,this.objectFit="cover"}render(){return this.objectFit&&(this.dataset.objectFit=this.objectFit),this.style.cssText=`
59      --local-width: ${this.size?`var(--wui-icon-size-${this.size});`:"100%"};
60      --local-height: ${this.size?`var(--wui-icon-size-${this.size});`:"100%"};
61      `,(0,a.qy)`<img src=${this.src} alt=${this.alt} @error=${this.handleImageError} />`}handleImageError(){this.dispatchEvent(new CustomEvent("onLoadError",{bubbles:!0,composed:!0}))}};u.styles=[n.W5,n.ck,i],c([(0,r.MZ)()],u.prototype,"src",void 0),c([(0,r.MZ)()],u.prototype,"alt",void 0),c([(0,r.MZ)()],u.prototype,"size",void 0),c([(0,r.MZ)()],u.prototype,"objectFit",void 0),u=c([(0,s.E)("wui-image")],u)}}]);

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.