@ic-pay/icpay-widget 0.1.76 → 0.1.77

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.
@@ -5241,7 +5241,7 @@ Make sure to test your application with a production build as repeat registratio
5241
5241
  .crypto-option { background: var(--icpay-surface-alt); border: 2px solid var(--icpay-border); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; color: var(--icpay-text); font-weight: 600; font-size: 12px; }
5242
5242
  .crypto-option.selected { background: var(--icpay-primary); color: #111827; border-color: var(--icpay-primary); }
5243
5243
  select { background: var(--icpay-surface-alt); border: 1px solid var(--icpay-border); color: var(--icpay-text); border-radius: 8px; padding: 10px; font-weight: 600; }
5244
- `,Se([ur({type:Array})],Nl.prototype,"options",2),Se([ur({type:String})],Nl.prototype,"value",2),Se([ur({type:String})],Nl.prototype,"defaultSymbol",2),Se([ur({type:String})],Nl.prototype,"mode",2),Se([ur({type:Object})],Nl.prototype,"theme",2),Nl=Se([Ui("icpay-token-selector")],Nl);var NM=typeof window<"u",pw=null;function uf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Xi=class extends mn{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new pw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),NM&&(uf(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!NM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(NM&&!(this.processing||this.unlocked)){uf(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){uf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new pw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(uf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){uf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}uf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);uf(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"premium-content"});uf(this.config?.debug||!1,"Payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}select(t){this.selectedSymbol=t}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5244
+ `,Se([ur({type:Array})],Nl.prototype,"options",2),Se([ur({type:String})],Nl.prototype,"value",2),Se([ur({type:String})],Nl.prototype,"defaultSymbol",2),Se([ur({type:String})],Nl.prototype,"mode",2),Se([ur({type:Object})],Nl.prototype,"theme",2),Nl=Se([Ui("icpay-token-selector")],Nl);var NM=typeof window<"u",pw=null;function uf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Xi=class extends mn{constructor(){super(...arguments);this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new pw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),NM&&(uf(this.config?.debug||!1,"Premium content connected",{config:this.config}),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.onPay()},0)}}async loadVerifiedLedgers(){if(!(!NM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}async onPay(){if(NM&&!(this.processing||this.unlocked)){uf(this.config?.debug||!1,"Premium content payment started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){uf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{pw||(pw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new pw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(uf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="pay",this.showWalletModal=!0;return}catch(o){uf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}uf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);uf(this.config?.debug||!1,"Payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"premium-content"});uf(this.config?.debug||!1,"Payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}select(t){this.selectedSymbol=t}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.onPay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5245
5245
  <div class="card section">
5246
5246
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5247
5247
  <div class="image-container">
@@ -5347,7 +5347,7 @@ Make sure to test your application with a production build as repeat registratio
5347
5347
  border-color: rgba(239, 68, 68, 0.3);
5348
5348
  color: #ef4444;
5349
5349
  }
5350
- `],Se([ur({type:Object})],Xi.prototype,"config",2),Se([Re()],Xi.prototype,"selectedSymbol",2),Se([Re()],Xi.prototype,"unlocked",2),Se([Re()],Xi.prototype,"succeeded",2),Se([Re()],Xi.prototype,"processing",2),Se([Re()],Xi.prototype,"availableLedgers",2),Se([Re()],Xi.prototype,"errorMessage",2),Se([Re()],Xi.prototype,"errorSeverity",2),Se([Re()],Xi.prototype,"errorAction",2),Se([Re()],Xi.prototype,"walletConnected",2),Se([Re()],Xi.prototype,"pendingAction",2),Se([Re()],Xi.prototype,"showWalletModal",2),Xi=Se([Ui("icpay-premium-content")],Xi);var TM=typeof window<"u",mw=null;function df(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ci=class extends mn{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new mw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),TM&&(df(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!TM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(TM&&(df(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){df(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new mw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(df(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){df(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}df(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);df(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"tip-jar"});df(this.config?.debug||!1,"Tip payment completed",{resp:s}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5350
+ `],Se([ur({type:Object})],Xi.prototype,"config",2),Se([Re()],Xi.prototype,"selectedSymbol",2),Se([Re()],Xi.prototype,"unlocked",2),Se([Re()],Xi.prototype,"succeeded",2),Se([Re()],Xi.prototype,"processing",2),Se([Re()],Xi.prototype,"availableLedgers",2),Se([Re()],Xi.prototype,"errorMessage",2),Se([Re()],Xi.prototype,"errorSeverity",2),Se([Re()],Xi.prototype,"errorAction",2),Se([Re()],Xi.prototype,"walletConnected",2),Se([Re()],Xi.prototype,"pendingAction",2),Se([Re()],Xi.prototype,"showWalletModal",2),Xi=Se([Ui("icpay-premium-content")],Xi);var TM=typeof window<"u",mw=null;function df(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ci=class extends mn{constructor(){super(...arguments);this.selectedAmount=1;this.selectedSymbol="ICP";this.total=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new mw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[1,5,10]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),TM&&(df(this.config?.debug||!1,"Tip jar connected",{config:this.config}),this.config&&this.config.defaultAmountUsd&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="tip"&&this.tip()},0)}}async loadVerifiedLedgers(){if(!(!TM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.config?.cryptoOptions&&this.config.cryptoOptions.length===1&&(this.selectedSymbol=this.config.cryptoOptions[0].symbol),!this.selectedSymbol&&this.availableLedgers.length>0&&(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){return Math.min(this.total/50*100,100)}async tip(){if(TM&&(df(this.config?.debug||!1,"Tip button clicked!",{config:this.config,processing:this.processing}),!this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="tip",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){df(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{mw||(mw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new mw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(df(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="tip",this.showWalletModal=!0;return}catch(o){df(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}df(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);df(this.config?.debug||!1,"Tip payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"tip-jar"});df(this.config?.debug||!1,"Tip payment completed",{resp:s}),this.total+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,total:this.total}),this.dispatchEvent(new CustomEvent("icpay-tip",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="tip"&&setTimeout(()=>this.tip(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5351
5351
  <div class="card section" style="text-align:center;">
5352
5352
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5353
5353
  <div class="jar"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
@@ -5435,7 +5435,7 @@ Make sure to test your application with a production build as repeat registratio
5435
5435
  border-color: rgba(239, 68, 68, 0.3);
5436
5436
  color: #ef4444;
5437
5437
  }
5438
- `],Se([ur({type:Object})],Ci.prototype,"config",2),Se([Re()],Ci.prototype,"selectedAmount",2),Se([Re()],Ci.prototype,"selectedSymbol",2),Se([Re()],Ci.prototype,"total",2),Se([Re()],Ci.prototype,"processing",2),Se([Re()],Ci.prototype,"succeeded",2),Se([Re()],Ci.prototype,"availableLedgers",2),Se([Re()],Ci.prototype,"errorMessage",2),Se([Re()],Ci.prototype,"errorSeverity",2),Se([Re()],Ci.prototype,"errorAction",2),Se([Re()],Ci.prototype,"walletConnected",2),Se([Re()],Ci.prototype,"pendingAction",2),Se([Re()],Ci.prototype,"showWalletModal",2),Ci=Se([Ui("icpay-tip-jar")],Ci);var OM=typeof window<"u",ww=null;function hf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var ni=class extends mn{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new ww(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),OM&&(hf(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!OM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(t){this.selectedSymbol=t}async unlock(){if(OM&&!(this.processing||this.unlocked)){hf(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){hf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new ww(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(hf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(o){hf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}hf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);hf(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"article"});hf(this.config?.debug||!1,"Article payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5438
+ `],Se([ur({type:Object})],Ci.prototype,"config",2),Se([Re()],Ci.prototype,"selectedAmount",2),Se([Re()],Ci.prototype,"selectedSymbol",2),Se([Re()],Ci.prototype,"total",2),Se([Re()],Ci.prototype,"processing",2),Se([Re()],Ci.prototype,"succeeded",2),Se([Re()],Ci.prototype,"availableLedgers",2),Se([Re()],Ci.prototype,"errorMessage",2),Se([Re()],Ci.prototype,"errorSeverity",2),Se([Re()],Ci.prototype,"errorAction",2),Se([Re()],Ci.prototype,"walletConnected",2),Se([Re()],Ci.prototype,"pendingAction",2),Se([Re()],Ci.prototype,"showWalletModal",2),Ci=Se([Ui("icpay-tip-jar")],Ci);var OM=typeof window<"u",ww=null;function hf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var ni=class extends mn{constructor(){super(...arguments);this.title="Article Title";this.preview="";this.lockedContent="";this.selectedSymbol="ICP";this.unlocked=!1;this.succeeded=!1;this.processing=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new ww(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),OM&&(hf(this.config?.debug||!1,"Article paywall connected",{config:this.config}),this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.config&&(typeof this.config.title=="string"&&(this.title=this.config.title),typeof this.config.preview=="string"&&(this.preview=this.config.preview),typeof this.config.lockedContent=="string"&&(this.lockedContent=this.config.lockedContent)),t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="unlock"&&this.unlock()},0)}}async loadVerifiedLedgers(){if(!(!OM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||this.availableLedgers[0]?.symbol||"ICP")}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectSymbol(t){this.selectedSymbol=t}async unlock(){if(OM&&!(this.processing||this.unlocked)){hf(this.config?.debug||!1,"Article paywall unlock started",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="unlock",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){hf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{ww||(ww=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new ww(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(hf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="unlock",this.showWalletModal=!0;return}catch(o){hf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}hf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);hf(this.config?.debug||!1,"Article payment details",{priceUsd:this.config.priceUsd,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.config.priceUsd,i,{context:"article"});hf(this.config?.debug||!1,"Article payment completed",{resp:s}),this.unlocked=!0,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status}),this.dispatchEvent(new CustomEvent("icpay-unlock",{detail:{amount:this.config.priceUsd,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="unlock"&&setTimeout(()=>this.unlock(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5439
5439
  <div class="card section">
5440
5440
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5441
5441
  <div class="container">
@@ -5607,7 +5607,7 @@ Make sure to test your application with a production build as repeat registratio
5607
5607
  border-color: rgba(239, 68, 68, 0.3);
5608
5608
  color: #ef4444;
5609
5609
  }
5610
- `],Se([ur({type:Object})],Ns.prototype,"config",2),Se([Re()],Ns.prototype,"selectedIndex",2),Se([Re()],Ns.prototype,"selectedSymbol",2),Se([Re()],Ns.prototype,"processing",2),Se([Re()],Ns.prototype,"availableLedgers",2),Se([Re()],Ns.prototype,"errorMessage",2),Se([Re()],Ns.prototype,"errorSeverity",2),Se([Re()],Ns.prototype,"errorAction",2),Se([Re()],Ns.prototype,"walletConnected",2),Se([Re()],Ns.prototype,"pendingAction",2),Se([Re()],Ns.prototype,"showWalletModal",2),Ns=Se([Ui("icpay-coffee-shop")],Ns);var MM=typeof window<"u",yw=null;function pf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ii=class extends mn{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new yw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),MM&&(pf(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!MM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){let t=Number(this.config?.goalUsd??1e3),n=t>0?t:1e3;return Math.min(this.raised/n*100,100)}async donate(){if(MM&&!this.processing){pf(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){pf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new yw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(pf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){pf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}pf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);pf(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"donation"});pf(this.config?.debug||!1,"Donation payment completed",{resp:s}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5610
+ `],Se([ur({type:Object})],Ns.prototype,"config",2),Se([Re()],Ns.prototype,"selectedIndex",2),Se([Re()],Ns.prototype,"selectedSymbol",2),Se([Re()],Ns.prototype,"processing",2),Se([Re()],Ns.prototype,"availableLedgers",2),Se([Re()],Ns.prototype,"errorMessage",2),Se([Re()],Ns.prototype,"errorSeverity",2),Se([Re()],Ns.prototype,"errorAction",2),Se([Re()],Ns.prototype,"walletConnected",2),Se([Re()],Ns.prototype,"pendingAction",2),Se([Re()],Ns.prototype,"showWalletModal",2),Ns=Se([Ui("icpay-coffee-shop")],Ns);var MM=typeof window<"u",yw=null;function pf(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var Ii=class extends mn{constructor(){super(...arguments);this.selectedAmount=10;this.selectedSymbol="ICP";this.raised=0;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}async tryAutoConnectPNP(){try{if(!this.config||this.config?.useOwnWallet)return;let t=localStorage.getItem("icpay:pnp");if(!t)return;let n=JSON.parse(t);if(!n?.provider||!n?.principal)return;yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP);let i=new yw(this.config?.plugNPlay||{});this.walletConnected=!1,this.config={...this.config,connectedWallet:{owner:n.principal,principal:n.principal,connected:!1}}}catch{}}get amounts(){return this.config?.amountsUsd||[10,25,50,100,250,500]}get cryptoOptions(){return this.config.cryptoOptions?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),MM&&(pf(this.config?.debug||!1,"Donation thermometer connected",{config:this.config}),this.config&&typeof this.config.defaultAmountUsd=="number"&&(this.selectedAmount=this.config.defaultAmountUsd),this.tryAutoConnectPNP(),this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers())}updated(t){if(t.has("config")&&this.pendingAction&&this.config?.actorProvider){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="donate"&&this.donate()},0)}}async loadVerifiedLedgers(){if(!(!MM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.availableLedgers.length>0&&!this.selectedSymbol&&(this.selectedSymbol=this.availableLedgers[0].symbol)}catch(t){console.warn("Failed to load verified ledgers:",t),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol="ICP")}}selectAmount(t){this.selectedAmount=t}selectSymbol(t){this.selectedSymbol=t}get fillPercentage(){let t=Number(this.config?.goalUsd??1e3),n=t>0?t:1e3;return Math.min(this.raised/n*100,100)}async donate(){if(MM&&!this.processing){pf(this.config?.debug||!1,"Donation started",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,useOwnWallet:this.config.useOwnWallet}),this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(this.config.useOwnWallet){if(!this.config.actorProvider){this.pendingAction="donate",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0}));return}}else if(!this.walletConnected){pf(this.config?.debug||!1,"Connecting to wallet via Plug N Play");try{yw||(yw=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new yw(this.config?.plugNPlay||{});let o=this.pnp.getEnabledWallets();if(pf(this.config?.debug||!1,"Available wallets",o),!o?.length)throw new Error("No wallets available");this.pendingAction="donate",this.showWalletModal=!0;return}catch(o){pf(this.config?.debug||!1,"Wallet connection error:",o),this.errorMessage=o instanceof Error?o.message:"Wallet connection failed",this.errorSeverity="error";return}}pf(this.config?.debug||!1,"Creating SDK for payment");let t=Ln(this.config),i=this.cryptoOptions.find(o=>o.symbol===this.selectedSymbol).canisterId||await t.client.getLedgerCanisterIdBySymbol(this.selectedSymbol);pf(this.config?.debug||!1,"Donation payment details",{amount:this.selectedAmount,selectedSymbol:this.selectedSymbol,canisterId:i});let s=await t.sendUsd(this.selectedAmount,i,{context:"donation"});pf(this.config?.debug||!1,"Donation payment completed",{resp:s}),this.raised+=this.selectedAmount,this.succeeded=!0,this.config.onSuccess&&this.config.onSuccess({id:s.transactionId,status:s.status,raised:this.raised}),this.dispatchEvent(new CustomEvent("icpay-donation",{detail:{amount:this.selectedAmount,tx:s},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="donate"&&setTimeout(()=>this.donate(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}render(){return this.config?ke`
5611
5611
  <div class="card section" style="text-align:center;">
5612
5612
  ${this.config?.progressBar?.enabled!==!1?ke`<icpay-progress-bar mode="${this.config?.progressBar?.mode||"modal"}"></icpay-progress-bar>`:null}
5613
5613
  <div class="thermo"><div class="fill" style="height:${this.fillPercentage}%"></div></div>
@@ -5709,26 +5709,26 @@ Make sure to test your application with a production build as repeat registratio
5709
5709
  </button>
5710
5710
  </div>
5711
5711
  </div>
5712
- `}async pay(){if(!(!RM||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.config?.amountUsd??0),c={context:"pay-button"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let t=this.config?.showLedgerDropdown===!0,i=(this.cryptoOptions?.length||0)>1,s=this.config?.showLedgerDropdown,o=s==="dropdown"?"dropdown":s==="none"?"none":"buttons",a=o!=="none"&&(i||o==="dropdown"),c=o==="dropdown"?"dropdown":i?"buttons":"none",l=this.selectedSymbol||this.config?.defaultSymbol||"ICP",u=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",f=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",u||"$0.00").replace("{symbol}",l),g=this.config?.progressBar?.enabled!==!1;return ke`
5712
+ `}async pay(){if(!(!RM||this.processing)){this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.config?.amountUsd??0),c={context:"pay-button"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let n=(this.cryptoOptions?.length||0)>1,i=this.config?.showLedgerDropdown,s=i==="dropdown"?"dropdown":"none",o=s!=="none"&&(n||s==="dropdown"),a=s==="dropdown"?"dropdown":n?"buttons":"none",c=this.selectedSymbol||this.config?.defaultSymbol||"ICP",l=typeof this.config?.amountUsd=="number"?`${Number(this.config.amountUsd).toFixed(2)}`:"",d=(this.config?.buttonLabel||(typeof this.config?.amountUsd=="number"?"Pay ${amount} with {symbol}":"Pay with {symbol}")).replace("{amount}",l||"$0.00").replace("{symbol}",c),m=this.config?.progressBar?.enabled!==!1;return ke`
5713
5713
  <div class="card section">
5714
- ${g?ke`
5714
+ ${m?ke`
5715
5715
  <icpay-progress-bar></icpay-progress-bar>
5716
5716
  `:null}
5717
5717
 
5718
- <div class="row ${a?"":"single"}">
5719
- ${a?ke`
5718
+ <div class="row ${o?"":"single"}">
5719
+ ${o?ke`
5720
5720
  <icpay-token-selector
5721
5721
  .options=${this.cryptoOptions}
5722
5722
  .value=${this.selectedSymbol||""}
5723
5723
  .defaultSymbol=${this.config?.defaultSymbol||"ICP"}
5724
- mode=${c}
5725
- @icpay-token-change=${y=>this.selectSymbol(y.detail.symbol)}
5724
+ mode=${a}
5725
+ @icpay-token-change=${g=>this.selectSymbol(g.detail.symbol)}
5726
5726
  ></icpay-token-selector>
5727
5727
  `:null}
5728
5728
  <button class="pay-button ${this.processing?"processing":""}"
5729
5729
  ?disabled=${this.processing||this.config?.disablePaymentButton===!0||this.succeeded&&this.config?.disableAfterSuccess===!0}
5730
5730
  @click=${()=>this.pay()}>
5731
- ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":f}
5731
+ ${this.succeeded&&this.config?.disableAfterSuccess?"Paid":this.processing?"Processing\u2026":d}
5732
5732
  </button>
5733
5733
  </div>
5734
5734
 
@@ -5748,7 +5748,7 @@ Make sure to test your application with a production build as repeat registratio
5748
5748
  .error-message.info { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #3b82f6; }
5749
5749
  .error-message.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: #f59e0b; }
5750
5750
  .error-message.error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
5751
- `],Se([ur({type:Object})],Ts.prototype,"config",2),Se([Re()],Ts.prototype,"selectedSymbol",2),Se([Re()],Ts.prototype,"processing",2),Se([Re()],Ts.prototype,"succeeded",2),Se([Re()],Ts.prototype,"availableLedgers",2),Se([Re()],Ts.prototype,"errorMessage",2),Se([Re()],Ts.prototype,"errorSeverity",2),Se([Re()],Ts.prototype,"errorAction",2),Se([Re()],Ts.prototype,"walletConnected",2),Se([Re()],Ts.prototype,"pendingAction",2),Se([Re()],Ts.prototype,"showWalletModal",2),Ts=Se([Ui("icpay-pay-button")],Ts);var UM=typeof window<"u",LM=null;function ZKe(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var _i=class extends mn{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),UM&&(ZKe(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!UM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(t){let n=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(t.target.value||0)),s=Math.round(i/n)*n;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(t){this.selectedSymbol=t}isValidAmount(){let t=Number(this.config?.minUsd??.5),n=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=t&&this.amountUsd<=n}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{if(LM||(LM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new LM(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!UM||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),c={context:"amount-input"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1,this.pendingAction=null}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let t=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.config?.showLedgerDropdown===!0,o=this.cryptoOptions.find(f=>f.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",a=this.config?.progressBar?.mode||"modal",c=this.config?.showLedgerDropdown,l=c==="buttons"?"buttons":c==="none"?"none":"dropdown",d=this.config?.progressBar?.enabled!==!1&&(a==="modal"?!0:this.processing);return ke`
5751
+ `],Se([ur({type:Object})],Ts.prototype,"config",2),Se([Re()],Ts.prototype,"selectedSymbol",2),Se([Re()],Ts.prototype,"processing",2),Se([Re()],Ts.prototype,"succeeded",2),Se([Re()],Ts.prototype,"availableLedgers",2),Se([Re()],Ts.prototype,"errorMessage",2),Se([Re()],Ts.prototype,"errorSeverity",2),Se([Re()],Ts.prototype,"errorAction",2),Se([Re()],Ts.prototype,"walletConnected",2),Se([Re()],Ts.prototype,"pendingAction",2),Se([Re()],Ts.prototype,"showWalletModal",2),Ts=Se([Ui("icpay-pay-button")],Ts);var UM=typeof window<"u",LM=null;function ZKe(r,e,t){r&&(t!==void 0?console.log(`[ICPay Widget] ${e}`,t):console.log(`[ICPay Widget] ${e}`))}var _i=class extends mn{constructor(){super(...arguments);this.amountUsd=0;this.hasUserAmount=!1;this.selectedSymbol=null;this.processing=!1;this.succeeded=!1;this.availableLedgers=[];this.errorMessage=null;this.errorSeverity=null;this.errorAction=null;this.walletConnected=!1;this.pendingAction=null;this.showWalletModal=!1;this.pnp=null}get cryptoOptions(){return this.config?.cryptoOptions?.length?this.config.cryptoOptions:this.availableLedgers}connectedCallback(){super.connectedCallback(),UM&&(ZKe(this.config?.debug||!1,"Amount input connected",{config:this.config}),this.amountUsd=Number(this.config?.defaultAmountUsd??0),this.hasUserAmount=!1,this.config?.cryptoOptions&&this.config.cryptoOptions.length>0||this.loadVerifiedLedgers(),this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol))}updated(t){if(t.has("config")&&(!this.hasUserAmount&&typeof this.config?.defaultAmountUsd=="number"&&(this.amountUsd===0||this.amountUsd==null||Number.isNaN(this.amountUsd))&&(this.amountUsd=Number(this.config.defaultAmountUsd)),!this.selectedSymbol&&this.config?.defaultSymbol&&(this.selectedSymbol=this.config.defaultSymbol),!(this.config?.cryptoOptions&&this.config.cryptoOptions.length>0)&&this.availableLedgers.length===0&&this.loadVerifiedLedgers(),this.pendingAction&&this.config?.actorProvider)){let n=this.pendingAction;this.pendingAction=null,setTimeout(()=>{n==="pay"&&this.pay()},0)}}async loadVerifiedLedgers(){if(!(!UM||!this.config?.publishableKey))try{let n=await Ln(this.config).client.getVerifiedLedgers();this.availableLedgers=n.map(i=>({symbol:i.symbol,label:i.name,canisterId:i.canisterId})),this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||(this.availableLedgers[0]?.symbol??"ICP"))}catch(t){this.dispatchEvent(new CustomEvent("icpay-error",{detail:{message:"Failed to load verified ledgers",cause:t},bubbles:!0})),this.availableLedgers=[{symbol:"ICP",label:"ICP",canisterId:"ryjl3-tyaaa-aaaaa-aaaba-cai"}],this.selectedSymbol||(this.selectedSymbol=this.config?.defaultSymbol||"ICP")}}onInputChange(t){let n=Number(this.config?.stepUsd??.5),i=Math.max(0,Number(t.target.value||0)),s=Math.round(i/n)*n;this.amountUsd=Number(s.toFixed(2)),this.hasUserAmount=!0}selectSymbol(t){this.selectedSymbol=t}isValidAmount(){let t=Number(this.config?.minUsd??.5),n=this.config?.maxUsd!==void 0?Number(this.config.maxUsd):1/0;return this.amountUsd>=t&&this.amountUsd<=n}async ensureWallet(){if(this.config.useOwnWallet)return this.config.actorProvider?!0:(this.pendingAction="pay",this.dispatchEvent(new CustomEvent("icpay-connect-wallet",{bubbles:!0})),!1);if(this.walletConnected)return!0;try{if(LM||(LM=(await Promise.resolve().then(()=>(pc(),fc))).PNP),this.pnp=new LM(this.config?.plugNPlay||{}),!this.pnp.getEnabledWallets()?.length)throw new Error("No wallets available");return this.pendingAction="pay",this.showWalletModal=!0,!1}catch(t){return this.errorMessage=t instanceof Error?t.message:"Wallet connection failed",this.errorSeverity="error",!1}}getWalletId(t){return t&&(t.id||t.provider||t.key)||""}getWalletLabel(t){return t&&(t.label||t.name||t.title||t.id)||"Wallet"}getWalletIcon(t){return t&&(t.icon||t.logo||t.image)||null}async connectWithWallet(t){if(this.pnp)try{if(!t)throw new Error("No wallet ID provided");let n=await this.pnp.connect(t);if(!!!(n&&(n.connected===!0||n.principal||n.owner||this.pnp?.account)))throw new Error("Wallet connection was rejected");this.walletConnected=!0,this.config={...this.config,connectedWallet:n,actorProvider:(o,a)=>this.pnp.getActor({canisterId:o,idl:a,requiresSigning:!0,anon:!1})},this.showWalletModal=!1;let s=this.pendingAction;this.pendingAction=null,s==="pay"&&setTimeout(()=>this.pay(),0)}catch(n){this.errorMessage=n instanceof Error?n.message:"Wallet connection failed",this.errorSeverity="error",this.showWalletModal=!1}}async pay(){if(!(!UM||this.processing)){if(this.errorMessage=null,this.errorSeverity=null,this.errorAction=null,!this.isValidAmount()){this.errorMessage="Please enter a valid amount",this.errorSeverity="warning";return}this.processing=!0;try{if(!await this.ensureWallet())return;let n=Ln(this.config),i=this.selectedSymbol||"ICP",o=this.cryptoOptions.find(u=>u.symbol===i)?.canisterId||await n.client.getLedgerCanisterIdBySymbol(i),a=Number(this.amountUsd),c={context:"amount-input"},l=await n.sendUsd(a,o,c);this.config.onSuccess&&this.config.onSuccess({id:l.transactionId,status:l.status,amountUsd:a}),this.succeeded=!0,this.dispatchEvent(new CustomEvent("icpay-amount-pay",{detail:{amount:a,tx:l},bubbles:!0}))}catch(t){Bo(t,{onError:n=>{this.dispatchEvent(new CustomEvent("icpay-error",{detail:n,bubbles:!0})),Mo(n)&&(this.errorMessage=Po(n),this.errorSeverity=ko(n),this.errorAction=Ro(n))}})}finally{this.processing=!1}}}render(){if(!this.config)return ke`<div class="card section">Loading...</div>`;let t=this.config?.placeholder||"Enter amount in USD",i=(this.config?.buttonLabel||"Pay ${amount} with {symbol}").replace("{amount}",this.amountUsd?`${Number(this.amountUsd).toFixed(2)}`:"$0.00").replace("{symbol}",this.selectedSymbol||this.config?.defaultSymbol||"ICP"),s=this.config?.showLedgerDropdown===!0,o=this.cryptoOptions.find(f=>f.symbol===(this.selectedSymbol||""))?.label||this.cryptoOptions[0]?.label||this.config?.defaultSymbol||"ICP",a=this.config?.progressBar?.mode||"modal",c=this.config?.showLedgerDropdown,l=c==="buttons"?"buttons":c==="none"?"none":"dropdown",d=this.config?.progressBar?.enabled!==!1&&(a==="modal"?!0:this.processing);return ke`
5752
5752
  <div class="card section">
5753
5753
  ${d?ke`<icpay-progress-bar mode="${a}"></icpay-progress-bar>`:null}
5754
5754