@safe-stars/components
Version:
React component library for buying Telegram Stars in Telegram Mini Apps via Safe Stars.
132 lines (126 loc) • 23.7 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-CtZaCMo8.cjs"),m=require("./if-defined-MmHKu2JE.cjs");require("./index-2v8aP99g.cjs");require("./index-1CrdV1LX.cjs");require("./index-BB9Vnkx8.cjs");require("./index-BXulAD-4.cjs");require("./index-BE8Edgdz.cjs");require("./index--KmZMQQE.cjs");require("./index-4AKqpZUN.cjs");require("./index-qAKUCMGe.cjs");const c={INVALID_PAYMENT_CONFIG:"INVALID_PAYMENT_CONFIG",INVALID_RECIPIENT:"INVALID_RECIPIENT",INVALID_ASSET:"INVALID_ASSET",INVALID_AMOUNT:"INVALID_AMOUNT",UNKNOWN_ERROR:"UNKNOWN_ERROR",UNABLE_TO_INITIATE_PAYMENT:"UNABLE_TO_INITIATE_PAYMENT",INVALID_CHAIN_NAMESPACE:"INVALID_CHAIN_NAMESPACE",GENERIC_PAYMENT_ERROR:"GENERIC_PAYMENT_ERROR",UNABLE_TO_GET_EXCHANGES:"UNABLE_TO_GET_EXCHANGES",ASSET_NOT_SUPPORTED:"ASSET_NOT_SUPPORTED",UNABLE_TO_GET_PAY_URL:"UNABLE_TO_GET_PAY_URL",UNABLE_TO_GET_BUY_STATUS:"UNABLE_TO_GET_BUY_STATUS"},y={[c.INVALID_PAYMENT_CONFIG]:"Invalid payment configuration",[c.INVALID_RECIPIENT]:"Invalid recipient address",[c.INVALID_ASSET]:"Invalid asset specified",[c.INVALID_AMOUNT]:"Invalid payment amount",[c.UNKNOWN_ERROR]:"Unknown payment error occurred",[c.UNABLE_TO_INITIATE_PAYMENT]:"Unable to initiate payment",[c.INVALID_CHAIN_NAMESPACE]:"Invalid chain namespace",[c.GENERIC_PAYMENT_ERROR]:"Unable to process payment",[c.UNABLE_TO_GET_EXCHANGES]:"Unable to get exchanges",[c.ASSET_NOT_SUPPORTED]:"Asset not supported by the selected exchange",[c.UNABLE_TO_GET_PAY_URL]:"Unable to get payment URL",[c.UNABLE_TO_GET_BUY_STATUS]:"Unable to get buy status"};class l extends Error{get message(){return y[this.code]}constructor(e,r){super(y[e]),this.name="AppKitPayError",this.code=e,this.details=r,Error.captureStackTrace&&Error.captureStackTrace(this,l)}}const I="https://rpc.walletconnect.org/v1/json-rpc";class _ extends Error{}function C(){const t=s.OptionsController.getSnapshot().projectId;return`${I}?projectId=${t}`}async function P(t,e){const r=C(),o=await(await fetch(r,{method:"POST",body:JSON.stringify({jsonrpc:"2.0",id:1,method:t,params:e}),headers:{"Content-Type":"application/json"}})).json();if(o.error)throw new _(o.error.message);return o}async function A(t){return(await P("reown_getExchanges",t)).result}async function x(t){return(await P("reown_getExchangePayUrl",t)).result}async function T(t){return(await P("reown_getExchangeBuyStatus",t)).result}const S=["eip155"],b={eip155:{native:{assetNamespace:"slip44",assetReference:"60"},defaultTokenNamespace:"erc20"},solana:{native:{assetNamespace:"slip44",assetReference:"501"},defaultTokenNamespace:"token"}};function E(t,e){const{chainNamespace:r,chainId:a}=s.ParseUtil.parseCaipNetworkId(t),i=b[r];if(!i)throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${r}`);let o=i.native.assetNamespace,u=i.native.assetReference;return e!=="native"&&(o=i.defaultTokenNamespace,u=e),`${`${r}:${a}`}/${o}:${u}`}function v(t){const{chainNamespace:e}=s.ParseUtil.parseCaipNetworkId(t);return S.includes(e)}async function U(t){const{paymentAssetNetwork:e,activeCaipNetwork:r,approvedCaipNetworkIds:a,requestedCaipNetworks:i}=t,u=s.CoreHelperUtil.sortRequestedNetworks(a,i).find(g=>g.caipNetworkId===e);if(!u)throw new l(c.INVALID_PAYMENT_CONFIG);if(u.caipNetworkId===r.caipNetworkId)return;const p=s.ChainController.getNetworkProp("supportsAllNetworks",u.chainNamespace);if(!((a==null?void 0:a.includes(u.caipNetworkId))||p))throw new l(c.INVALID_PAYMENT_CONFIG);try{await s.ChainController.switchActiveNetwork(u)}catch(g){throw new l(c.GENERIC_PAYMENT_ERROR,g)}}async function R(t,e,r){var p;if(e!==s.ConstantsUtil$1.CHAIN.EVM)throw new l(c.INVALID_CHAIN_NAMESPACE);if(!r.fromAddress)throw new l(c.INVALID_PAYMENT_CONFIG,"fromAddress is required for native EVM payments.");const a=typeof r.amount=="string"?parseFloat(r.amount):r.amount;if(isNaN(a))throw new l(c.INVALID_PAYMENT_CONFIG);const i=((p=t.metadata)==null?void 0:p.decimals)??18,o=s.ConnectionController.parseUnits(a.toString(),i);if(typeof o!="bigint")throw new l(c.GENERIC_PAYMENT_ERROR);return await s.ConnectionController.sendTransaction({chainNamespace:e,to:r.recipient,address:r.fromAddress,value:o,data:"0x"})??void 0}async function k(t,e){if(!e.fromAddress)throw new l(c.INVALID_PAYMENT_CONFIG,"fromAddress is required for ERC20 EVM payments.");const r=t.asset,a=e.recipient,i=Number(t.metadata.decimals),o=s.ConnectionController.parseUnits(e.amount.toString(),i);if(o===void 0)throw new l(c.GENERIC_PAYMENT_ERROR);return await s.ConnectionController.writeContract({fromAddress:e.fromAddress,tokenAddress:r,args:[a,o],method:"transfer",abi:s.ContractUtil.getERC20Abi(r),chainNamespace:s.ConstantsUtil$1.CHAIN.EVM})??void 0}const N=0,f="unknown",n=s.proxy({paymentAsset:{network:"eip155:1",asset:"0x0",metadata:{name:"0x0",symbol:"0x0",decimals:0}},recipient:"0x0",amount:0,isConfigured:!1,error:null,isPaymentInProgress:!1,exchanges:[],isLoading:!1,openInNewTab:!0,redirectUrl:void 0,payWithExchange:void 0,currentPayment:void 0,analyticsSet:!1,paymentId:void 0}),d={state:n,subscribe(t){return s.subscribe(n,()=>t(n))},subscribeKey(t,e){return s.subscribeKey(n,t,e)},async handleOpenPay(t){this.resetState(),this.setPaymentConfig(t),this.subscribeEvents(),this.initializeAnalytics(),n.isConfigured=!0,s.EventsController.sendEvent({type:"track",event:"PAY_MODAL_OPEN",properties:{exchanges:n.exchanges,configuration:{network:n.paymentAsset.network,asset:n.paymentAsset.asset,recipient:n.recipient,amount:n.amount}}}),await s.ModalController.open({view:"Pay"})},resetState(){n.paymentAsset={network:"eip155:1",asset:"0x0",metadata:{name:"0x0",symbol:"0x0",decimals:0}},n.recipient="0x0",n.amount=0,n.isConfigured=!1,n.error=null,n.isPaymentInProgress=!1,n.isLoading=!1,n.currentPayment=void 0},setPaymentConfig(t){if(!t.paymentAsset)throw new l(c.INVALID_PAYMENT_CONFIG);try{n.paymentAsset=t.paymentAsset,n.recipient=t.recipient,n.amount=t.amount,n.openInNewTab=t.openInNewTab??!0,n.redirectUrl=t.redirectUrl,n.payWithExchange=t.payWithExchange,n.error=null}catch(e){throw new l(c.INVALID_PAYMENT_CONFIG,e.message)}},getPaymentAsset(){return n.paymentAsset},getExchanges(){return n.exchanges},async fetchExchanges(){try{n.isLoading=!0;const t=await A({page:N,asset:E(n.paymentAsset.network,n.paymentAsset.asset),amount:n.amount.toString()});n.exchanges=t.exchanges.slice(0,2)}catch{throw s.SnackController.showError(y.UNABLE_TO_GET_EXCHANGES),new l(c.UNABLE_TO_GET_EXCHANGES)}finally{n.isLoading=!1}},async getAvailableExchanges(t){var e;try{const r=t!=null&&t.asset&&(t!=null&&t.network)?E(t.network,t.asset):void 0;return await A({page:(t==null?void 0:t.page)??N,asset:r,amount:(e=t==null?void 0:t.amount)==null?void 0:e.toString()})}catch{throw new l(c.UNABLE_TO_GET_EXCHANGES)}},async getPayUrl(t,e,r=!1){try{const a=Number(e.amount),i=await x({exchangeId:t,asset:E(e.network,e.asset),amount:a.toString(),recipient:`${e.network}:${e.recipient}`});return s.EventsController.sendEvent({type:"track",event:"PAY_EXCHANGE_SELECTED",properties:{exchange:{id:t},configuration:{network:e.network,asset:e.asset,recipient:e.recipient,amount:a},currentPayment:{type:"exchange",exchangeId:t},headless:r}}),r&&(this.initiatePayment(),s.EventsController.sendEvent({type:"track",event:"PAY_INITIATED",properties:{paymentId:n.paymentId||f,configuration:{network:e.network,asset:e.asset,recipient:e.recipient,amount:a},currentPayment:{type:"exchange",exchangeId:t}}})),i}catch(a){throw a instanceof Error&&a.message.includes("is not supported")?new l(c.ASSET_NOT_SUPPORTED):new Error(a.message)}},async openPayUrl(t,e,r=!1){try{const a=await this.getPayUrl(t.exchangeId,e,r);if(!a)throw new l(c.UNABLE_TO_GET_PAY_URL);const o=t.openInNewTab??!0?"_blank":"_self";return s.CoreHelperUtil.openHref(a.url,o),a}catch(a){throw a instanceof l?n.error=a.message:n.error=y.GENERIC_PAYMENT_ERROR,new l(c.UNABLE_TO_GET_PAY_URL)}},subscribeEvents(){n.isConfigured||(s.ProviderUtil.subscribeProviders(async t=>{const e=s.ChainController.state.activeChain;s.ProviderUtil.getProvider(e)&&await this.handlePayment()}),s.AccountController.subscribeKey("caipAddress",async t=>{t&&await this.handlePayment()}))},async handlePayment(){n.currentPayment={type:"wallet",status:"IN_PROGRESS"};const t=s.AccountController.state.caipAddress;if(!t)return;const{chainId:e,address:r}=s.ParseUtil.parseCaipAddress(t),a=s.ChainController.state.activeChain;if(!r||!e||!a||!s.ProviderUtil.getProvider(a))return;const o=s.ChainController.state.activeCaipNetwork;if(o&&!n.isPaymentInProgress)try{this.initiatePayment();const u=s.ChainController.getAllRequestedCaipNetworks(),p=s.ChainController.getAllApprovedCaipNetworkIds();switch(await U({paymentAssetNetwork:n.paymentAsset.network,activeCaipNetwork:o,approvedCaipNetworkIds:p,requestedCaipNetworks:u}),await s.ModalController.open({view:"PayLoading"}),a){case s.ConstantsUtil$1.CHAIN.EVM:n.paymentAsset.asset==="native"&&(n.currentPayment.result=await R(n.paymentAsset,a,{recipient:n.recipient,amount:n.amount,fromAddress:r})),n.paymentAsset.asset.startsWith("0x")&&(n.currentPayment.result=await k(n.paymentAsset,{recipient:n.recipient,amount:n.amount,fromAddress:r})),n.currentPayment.status="SUCCESS";break;default:throw new l(c.INVALID_CHAIN_NAMESPACE)}}catch(u){u instanceof l?n.error=u.message:n.error=y.GENERIC_PAYMENT_ERROR,n.currentPayment.status="FAILED",s.SnackController.showError(n.error)}finally{n.isPaymentInProgress=!1}},getExchangeById(t){return n.exchanges.find(e=>e.id===t)},validatePayConfig(t){const{paymentAsset:e,recipient:r,amount:a}=t;if(!e)throw new l(c.INVALID_PAYMENT_CONFIG);if(!r)throw new l(c.INVALID_RECIPIENT);if(!e.asset)throw new l(c.INVALID_ASSET);if(a==null||a<=0)throw new l(c.INVALID_AMOUNT)},handlePayWithWallet(){const t=s.AccountController.state.caipAddress;if(!t){s.RouterController.push("Connect");return}const{chainId:e,address:r}=s.ParseUtil.parseCaipAddress(t),a=s.ChainController.state.activeChain;if(!r||!e||!a){s.RouterController.push("Connect");return}this.handlePayment()},async handlePayWithExchange(t){try{n.currentPayment={type:"exchange",exchangeId:t};const{network:e,asset:r}=n.paymentAsset,a={network:e,asset:r,amount:n.amount,recipient:n.recipient},i=await this.getPayUrl(t,a);if(!i)throw new l(c.UNABLE_TO_INITIATE_PAYMENT);return n.currentPayment.sessionId=i.sessionId,n.currentPayment.status="IN_PROGRESS",n.currentPayment.exchangeId=t,this.initiatePayment(),{url:i.url,openInNewTab:n.openInNewTab}}catch(e){return e instanceof l?n.error=e.message:n.error=y.GENERIC_PAYMENT_ERROR,n.isPaymentInProgress=!1,s.SnackController.showError(n.error),null}},async getBuyStatus(t,e){var r,a;try{const i=await T({sessionId:e,exchangeId:t});return(i.status==="SUCCESS"||i.status==="FAILED")&&s.EventsController.sendEvent({type:"track",event:i.status==="SUCCESS"?"PAY_SUCCESS":"PAY_ERROR",properties:{paymentId:n.paymentId||f,configuration:{network:n.paymentAsset.network,asset:n.paymentAsset.asset,recipient:n.recipient,amount:n.amount},currentPayment:{type:"exchange",exchangeId:(r=n.currentPayment)==null?void 0:r.exchangeId,sessionId:(a=n.currentPayment)==null?void 0:a.sessionId,result:i.txHash}}}),i}catch{throw new l(c.UNABLE_TO_GET_BUY_STATUS)}},async updateBuyStatus(t,e){try{const r=await this.getBuyStatus(t,e);n.currentPayment&&(n.currentPayment.status=r.status,n.currentPayment.result=r.txHash),(r.status==="SUCCESS"||r.status==="FAILED")&&(n.isPaymentInProgress=!1)}catch{throw new l(c.UNABLE_TO_GET_BUY_STATUS)}},initiatePayment(){n.isPaymentInProgress=!0,n.paymentId=crypto.randomUUID()},initializeAnalytics(){n.analyticsSet||(n.analyticsSet=!0,this.subscribeKey("isPaymentInProgress",t=>{var e;if((e=n.currentPayment)!=null&&e.status&&n.currentPayment.status!=="UNKNOWN"){const r={IN_PROGRESS:"PAY_INITIATED",SUCCESS:"PAY_SUCCESS",FAILED:"PAY_ERROR"}[n.currentPayment.status];s.EventsController.sendEvent({type:"track",event:r,properties:{paymentId:n.paymentId||f,configuration:{network:n.paymentAsset.network,asset:n.paymentAsset.asset,recipient:n.recipient,amount:n.amount},currentPayment:{type:n.currentPayment.type,exchangeId:n.currentPayment.exchangeId,sessionId:n.currentPayment.sessionId,result:n.currentPayment.result}}})}}))}},L=s.i`
wui-separator {
margin: var(--wui-spacing-m) calc(var(--wui-spacing-m) * -1) var(--wui-spacing-xs)
calc(var(--wui-spacing-m) * -1);
width: calc(100% + var(--wui-spacing-s) * 2);
}
.token-display {
padding: var(--wui-spacing-s) var(--wui-spacing-m);
border-radius: var(--wui-border-radius-s);
background-color: var(--wui-color-bg-125);
margin-top: var(--wui-spacing-s);
margin-bottom: var(--wui-spacing-s);
}
.token-display wui-text {
text-transform: none;
}
wui-loading-spinner {
padding: var(--wui-spacing-xs);
}
`;var w=function(t,e,r,a){var i=arguments.length,o=i<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,r):a,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(t,e,r,a);else for(var p=t.length-1;p>=0;p--)(u=t[p])&&(o=(i<3?u(o):i>3?u(e,r,o):u(e,r))||o);return i>3&&o&&Object.defineProperty(e,r,o),o};exports.W3mPayView=class extends s.i$1{constructor(){super(),this.unsubscribe=[],this.amount="",this.tokenSymbol="",this.networkName="",this.exchanges=d.state.exchanges,this.isLoading=d.state.isLoading,this.loadingExchangeId=null,this.connectedWalletInfo=s.AccountController.state.connectedWalletInfo,this.initializePaymentDetails(),this.unsubscribe.push(d.subscribeKey("exchanges",e=>this.exchanges=e)),this.unsubscribe.push(d.subscribeKey("isLoading",e=>this.isLoading=e)),this.unsubscribe.push(s.AccountController.subscribe(e=>this.connectedWalletInfo=e.connectedWalletInfo)),d.fetchExchanges()}get isWalletConnected(){return s.AccountController.state.status==="connected"}render(){return s.x`
<wui-flex flexDirection="column">
<wui-flex flexDirection="column" .padding=${["0","l","l","l"]} gap="s">
${this.renderPaymentHeader()}
<wui-flex flexDirection="column" gap="s">
${this.renderPayWithWallet()} ${this.renderExchangeOptions()}
</wui-flex>
</wui-flex>
</wui-flex>
`}initializePaymentDetails(){const e=d.getPaymentAsset();this.networkName=e.network,this.tokenSymbol=e.metadata.symbol,this.amount=d.state.amount.toString()}renderPayWithWallet(){return v(this.networkName)?s.x`<wui-flex flexDirection="column" gap="s">
${this.isWalletConnected?this.renderConnectedView():this.renderDisconnectedView()}
</wui-flex>
<wui-separator text="or"></wui-separator>`:s.x``}renderPaymentHeader(){let e=this.networkName;if(this.networkName){const a=s.ChainController.getAllRequestedCaipNetworks().find(i=>i.caipNetworkId===this.networkName);a&&(e=a.name)}return s.x`
<wui-flex flexDirection="column" alignItems="center">
<wui-flex alignItems="center" gap="xs">
<wui-text variant="large-700" color="fg-100">${this.amount||"0.0000"}</wui-text>
<wui-flex class="token-display" alignItems="center" gap="xxs">
<wui-text variant="paragraph-600" color="fg-100">
${this.tokenSymbol||"Unknown Asset"}
</wui-text>
${e?s.x`
<wui-text variant="small-500" color="fg-200"> on ${e} </wui-text>
`:""}
</wui-flex>
</wui-flex>
</wui-flex>
`}renderConnectedView(){var r,a,i;const e=((r=this.connectedWalletInfo)==null?void 0:r.name)||"connected wallet";return s.x`
<wui-list-item
=${this.onWalletPayment}
?chevron=${!0}
data-testid="wallet-payment-option"
>
<wui-flex alignItems="center" gap="s">
<wui-wallet-image
size="sm"
imageSrc=${m.o((a=this.connectedWalletInfo)==null?void 0:a.icon)}
name=${m.o((i=this.connectedWalletInfo)==null?void 0:i.name)}
></wui-wallet-image>
<wui-text variant="paragraph-500" color="inherit">Pay with ${e}</wui-text>
</wui-flex>
</wui-list-item>
<wui-list-item
variant="icon"
iconVariant="overlay"
icon="disconnect"
=${this.onDisconnect}
data-testid="disconnect-button"
?chevron=${!1}
>
<wui-text variant="paragraph-500" color="fg-200">Disconnect</wui-text>
</wui-list-item>
`}renderDisconnectedView(){return s.x`<wui-list-item
variant="icon"
iconVariant="overlay"
icon="walletPlaceholder"
=${this.onWalletPayment}
?chevron=${!0}
data-testid="wallet-payment-option"
>
<wui-text variant="paragraph-500" color="inherit">Pay from wallet</wui-text>
</wui-list-item>`}renderExchangeOptions(){return this.isLoading?s.x`<wui-flex justifyContent="center" alignItems="center">
<wui-spinner size="md"></wui-spinner>
</wui-flex>`:this.exchanges.length===0?s.x`<wui-flex justifyContent="center" alignItems="center">
<wui-text variant="paragraph-500" color="fg-100">No exchanges available</wui-text>
</wui-flex>`:this.exchanges.map(e=>s.x`
<wui-list-item
=${()=>this.onExchangePayment(e.id)}
data-testid="exchange-option-${e.id}"
?chevron=${!0}
?disabled=${this.loadingExchangeId!==null}
>
<wui-flex alignItems="center" gap="s">
${this.loadingExchangeId===e.id?s.x`<wui-loading-spinner color="accent-100" size="md"></wui-loading-spinner>`:s.x`<wui-wallet-image
size="sm"
imageSrc=${m.o(e.imageUrl)}
name=${e.name}
></wui-wallet-image>`}
<wui-text flexGrow="1" variant="paragraph-500" color="inherit"
>Pay with ${e.name} <wui-spinner size="sm" color="fg-200"></wui-spinner
></wui-text>
</wui-flex>
</wui-list-item>
`)}onWalletPayment(){d.handlePayWithWallet()}async onExchangePayment(e){try{this.loadingExchangeId=e;const r=await d.handlePayWithExchange(e);r&&(await s.ModalController.open({view:"PayLoading"}),s.CoreHelperUtil.openHref(r.url,r.openInNewTab?"_blank":"_self"))}catch(r){console.error("Failed to pay with exchange",r),s.SnackController.showError("Failed to pay with exchange")}finally{this.loadingExchangeId=null}}async onDisconnect(e){e.stopPropagation();try{await s.ConnectionController.disconnect(),s.ModalController.close()}catch{console.error("Failed to disconnect"),s.SnackController.showError("Failed to disconnect")}}disconnectedCallback(){this.unsubscribe.forEach(e=>e())}};exports.W3mPayView.styles=L;w([m.r()],exports.W3mPayView.prototype,"amount",void 0);w([m.r()],exports.W3mPayView.prototype,"tokenSymbol",void 0);w([m.r()],exports.W3mPayView.prototype,"networkName",void 0);w([m.r()],exports.W3mPayView.prototype,"exchanges",void 0);w([m.r()],exports.W3mPayView.prototype,"isLoading",void 0);w([m.r()],exports.W3mPayView.prototype,"loadingExchangeId",void 0);w([m.r()],exports.W3mPayView.prototype,"connectedWalletInfo",void 0);exports.W3mPayView=w([m.customElement("w3m-pay-view")],exports.W3mPayView);const O=s.i`
:host {
display: block;
height: 100%;
width: 100%;
}
`;var h=function(t,e,r,a){var i=arguments.length,o=i<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,r):a,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(t,e,r,a);else for(var p=t.length-1;p>=0;p--)(u=t[p])&&(o=(i<3?u(o):i>3?u(e,r,o):u(e,r))||o);return i>3&&o&&Object.defineProperty(e,r,o),o};const M=4e3;exports.W3mPayLoadingView=class extends s.i$1{constructor(){super(),this.loadingMessage="",this.subMessage="",this.paymentState="in-progress",this.paymentState=d.state.isPaymentInProgress?"in-progress":"completed",this.updateMessages(),this.setupSubscription(),this.setupExchangeSubscription()}disconnectedCallback(){clearInterval(this.exchangeSubscription)}render(){return s.x`
<wui-flex
flexDirection="column"
alignItems="center"
.padding=${["xl","xl","xl","xl"]}
gap="xl"
>
<wui-flex justifyContent="center" alignItems="center"> ${this.getStateIcon()} </wui-flex>
<wui-flex flexDirection="column" alignItems="center" gap="xs">
<wui-text align="center" variant="paragraph-500" color="fg-100">
${this.loadingMessage}
</wui-text>
<wui-text align="center" variant="small-400" color="fg-200">
${this.subMessage}
</wui-text>
</wui-flex>
</wui-flex>
`}updateMessages(){var e;switch(this.paymentState){case"completed":this.loadingMessage="Payment completed",this.subMessage="Your transaction has been successfully processed";break;case"error":this.loadingMessage="Payment failed",this.subMessage="There was an error processing your transaction";break;case"in-progress":default:((e=d.state.currentPayment)==null?void 0:e.type)==="exchange"?(this.loadingMessage="Payment initiated",this.subMessage="Please complete the payment on the exchange"):(this.loadingMessage="Awaiting payment confirmation",this.subMessage="Please confirm the payment transaction in your wallet");break}}getStateIcon(){switch(this.paymentState){case"completed":return this.successTemplate();case"error":return this.errorTemplate();case"in-progress":default:return this.loaderTemplate()}}setupExchangeSubscription(){var e;((e=d.state.currentPayment)==null?void 0:e.type)==="exchange"&&(this.exchangeSubscription=setInterval(async()=>{var i,o,u;const r=(i=d.state.currentPayment)==null?void 0:i.exchangeId,a=(o=d.state.currentPayment)==null?void 0:o.sessionId;r&&a&&(await d.updateBuyStatus(r,a),((u=d.state.currentPayment)==null?void 0:u.status)==="SUCCESS"&&clearInterval(this.exchangeSubscription))},M))}setupSubscription(){d.subscribeKey("isPaymentInProgress",e=>{var r;!e&&this.paymentState==="in-progress"&&(d.state.error||!((r=d.state.currentPayment)!=null&&r.result)?this.paymentState="error":this.paymentState="completed",this.updateMessages(),setTimeout(()=>{s.ConnectionController.state.status!=="disconnected"&&s.ModalController.close()},3e3))}),d.subscribeKey("error",e=>{e&&this.paymentState==="in-progress"&&(this.paymentState="error",this.updateMessages())})}loaderTemplate(){const e=s.ThemeController.state.themeVariables["--w3m-border-radius-master"],r=e?parseInt(e.replace("px",""),10):4;return s.x`<wui-loading-thumbnail radius=${r*9}></wui-loading-thumbnail>`}successTemplate(){return s.x`<wui-icon size="xl" color="success-100" name="checkmark"></wui-icon>`}errorTemplate(){return s.x`<wui-icon size="xl" color="error-100" name="close"></wui-icon>`}};exports.W3mPayLoadingView.styles=O;h([m.r()],exports.W3mPayLoadingView.prototype,"loadingMessage",void 0);h([m.r()],exports.W3mPayLoadingView.prototype,"subMessage",void 0);h([m.r()],exports.W3mPayLoadingView.prototype,"paymentState",void 0);exports.W3mPayLoadingView=h([m.customElement("w3m-pay-loading-view")],exports.W3mPayLoadingView);async function D(t){return d.handleOpenPay(t)}function V(){return d.getExchanges()}function W(){var t;return(t=d.state.currentPayment)==null?void 0:t.result}function G(){return d.state.error}function $(){return d.state.isPaymentInProgress}const Y={network:"eip155:8453",asset:"native",metadata:{name:"Ethereum",symbol:"ETH",decimals:18}},B={network:"eip155:8453",asset:"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",metadata:{name:"USD Coin",symbol:"USDC",decimals:6}},H={network:"eip155:84532",asset:"native",metadata:{name:"Ethereum",symbol:"ETH",decimals:18}};exports.baseETH=Y;exports.baseSepoliaETH=H;exports.baseUSDC=B;exports.getExchanges=V;exports.getIsPaymentInProgress=$;exports.getPayError=G;exports.getPayResult=W;exports.openPay=D;
//# sourceMappingURL=index-D7ExiwKc.cjs.map