brahma-trade-widget
Version:
A React component for trade automation within the Brahma ecosystem.
1 lines • 91.7 kB
JavaScript
(self.webpackChunkbrahma_trade_widget=self.webpackChunkbrahma_trade_widget||[]).push([[598],{20053:(e,t,n)=>{"use strict";function s(e){var t,n,i="";if("string"==typeof e||"number"==typeof e)i+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(n=s(e[t]))&&(i&&(i+=" "),i+=n);else for(t in e)e[t]&&(i&&(i+=" "),i+=t);return i}function i(){for(var e,t,n=0,i="";n<arguments.length;)(e=arguments[n++])&&(t=s(e))&&(i&&(i+=" "),i+=t);return i}n.r(t),n.d(t,{clsx:()=>i,default:()=>r});const r=i},20598:(e,t,n)=>{"use strict";n.d(t,{createCoinbaseWalletSDK:()=>ft});class s{constructor(e,t){this.scope=e,this.module=t}storeObject(e,t){this.setItem(e,JSON.stringify(t))}loadObject(e){const t=this.getItem(e);return t?JSON.parse(t):void 0}setItem(e,t){localStorage.setItem(this.scopedKey(e),t)}getItem(e){return localStorage.getItem(this.scopedKey(e))}removeItem(e){localStorage.removeItem(this.scopedKey(e))}clear(){const e=this.scopedKey(""),t=[];for(let n=0;n<localStorage.length;n++){const s=localStorage.key(n);"string"==typeof s&&s.startsWith(e)&&t.push(s)}t.forEach((e=>localStorage.removeItem(e)))}scopedKey(e){return`-${this.scope}${this.module?`:${this.module}`:""}:${e}`}static clearAll(){new s("CBWSDK").clear(),new s("walletlink").clear()}}const i={invalidInput:-32e3,resourceNotFound:-32001,resourceUnavailable:-32002,transactionRejected:-32003,methodNotSupported:-32004,limitExceeded:-32005,parse:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internal:-32603},r={userRejectedRequest:4001,unauthorized:4100,unsupportedMethod:4200,disconnected:4900,chainDisconnected:4901,unsupportedChain:4902},a={"-32700":{standard:"JSON RPC 2.0",message:"Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."},"-32600":{standard:"JSON RPC 2.0",message:"The JSON sent is not a valid Request object."},"-32601":{standard:"JSON RPC 2.0",message:"The method does not exist / is not available."},"-32602":{standard:"JSON RPC 2.0",message:"Invalid method parameter(s)."},"-32603":{standard:"JSON RPC 2.0",message:"Internal JSON-RPC error."},"-32000":{standard:"EIP-1474",message:"Invalid input."},"-32001":{standard:"EIP-1474",message:"Resource not found."},"-32002":{standard:"EIP-1474",message:"Resource unavailable."},"-32003":{standard:"EIP-1474",message:"Transaction rejected."},"-32004":{standard:"EIP-1474",message:"Method not supported."},"-32005":{standard:"EIP-1474",message:"Request limit exceeded."},4001:{standard:"EIP-1193",message:"User rejected the request."},4100:{standard:"EIP-1193",message:"The requested account and/or method has not been authorized by the user."},4200:{standard:"EIP-1193",message:"The requested method is not supported by this Ethereum provider."},4900:{standard:"EIP-1193",message:"The provider is disconnected from all chains."},4901:{standard:"EIP-1193",message:"The provider is disconnected from the specified chain."},4902:{standard:"EIP-3085",message:"Unrecognized chain ID."}},o="Unspecified error message.";function c(e,t=o){if(e&&Number.isInteger(e)){const t=e.toString();if(h(a,t))return a[t].message;if(d(e))return"Unspecified server error."}return t}function l(e,{shouldIncludeStack:t=!1}={}){const n={};if(e&&"object"==typeof e&&!Array.isArray(e)&&h(e,"code")&&function(e){if(!Number.isInteger(e))return!1;const t=e.toString();return!!a[t]||!!d(e)}(e.code)){const t=e;n.code=t.code,t.message&&"string"==typeof t.message?(n.message=t.message,h(t,"data")&&(n.data=t.data)):(n.message=c(n.code),n.data={originalError:u(e)})}else n.code=i.internal,n.message=p(e,"message")?e.message:o,n.data={originalError:u(e)};return t&&(n.stack=p(e,"stack")?e.stack:void 0),n}function d(e){return e>=-32099&&e<=-32e3}function u(e){return e&&"object"==typeof e&&!Array.isArray(e)?Object.assign({},e):e}function h(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function p(e,t){return"object"==typeof e&&null!==e&&t in e&&"string"==typeof e[t]}const f={parse:e=>m(i.parse,e),invalidRequest:e=>m(i.invalidRequest,e),invalidParams:e=>m(i.invalidParams,e),methodNotFound:e=>m(i.methodNotFound,e),internal:e=>m(i.internal,e),server:e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Ethereum RPC Server errors must provide single object argument.");const{code:t}=e;if(!Number.isInteger(t)||t>-32005||t<-32099)throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');return m(t,e)},invalidInput:e=>m(i.invalidInput,e),resourceNotFound:e=>m(i.resourceNotFound,e),resourceUnavailable:e=>m(i.resourceUnavailable,e),transactionRejected:e=>m(i.transactionRejected,e),methodNotSupported:e=>m(i.methodNotSupported,e),limitExceeded:e=>m(i.limitExceeded,e)},g={userRejectedRequest:e=>_(r.userRejectedRequest,e),unauthorized:e=>_(r.unauthorized,e),unsupportedMethod:e=>_(r.unsupportedMethod,e),disconnected:e=>_(r.disconnected,e),chainDisconnected:e=>_(r.chainDisconnected,e),unsupportedChain:e=>_(r.unsupportedChain,e),custom:e=>{if(!e||"object"!=typeof e||Array.isArray(e))throw new Error("Ethereum Provider custom errors must provide single object argument.");const{code:t,message:n,data:s}=e;if(!n||"string"!=typeof n)throw new Error('"message" must be a nonempty string');return new w(t,n,s)}};function m(e,t){const[n,s]=y(t);return new b(e,n||c(e),s)}function _(e,t){const[n,s]=y(t);return new w(e,n||c(e),s)}function y(e){if(e){if("string"==typeof e)return[e];if("object"==typeof e&&!Array.isArray(e)){const{message:t,data:n}=e;if(t&&"string"!=typeof t)throw new Error("Must specify string message.");return[t||void 0,n]}}return[]}class b extends Error{constructor(e,t,n){if(!Number.isInteger(e))throw new Error('"code" must be an integer.');if(!t||"string"!=typeof t)throw new Error('"message" must be a nonempty string.');super(t),this.code=e,void 0!==n&&(this.data=n)}}class w extends b{constructor(e,t,n){if(!function(e){return Number.isInteger(e)&&e>=1e3&&e<=4999}(e))throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');super(e,t,n)}}const v=e=>e,k=e=>e,I=e=>e;function E(e){return Math.floor(e)}const C=/^[0-9]*$/,x=/^[a-f0-9]*$/;function S(e){return M(crypto.getRandomValues(new Uint8Array(e)))}function M(e){return[...e].map((e=>e.toString(16).padStart(2,"0"))).join("")}function A(e){return new Uint8Array(e.match(/.{1,2}/g).map((e=>Number.parseInt(e,16))))}function P(e,t=!1){const n=e.toString("hex");return v(t?`0x${n}`:n)}function L(e){return P(q(e),!0)}function D(e){return I(e.toString(10))}function N(e){return v(`0x${BigInt(e).toString(16)}`)}function R(e){return e.startsWith("0x")||e.startsWith("0X")}function T(e){return R(e)?e.slice(2):e}function U(e){return R(e)?`0x${e.slice(2)}`:`0x${e}`}function j(e){if("string"!=typeof e)return!1;const t=T(e).toLowerCase();return x.test(t)}function O(e,t=!1){let n=function(e,t=!1){if("string"==typeof e){const n=T(e).toLowerCase();if(x.test(n))return v(t?`0x${n}`:n)}throw f.invalidParams(`"${String(e)}" is not a hexadecimal string`)}(e,!1);return n.length%2==1&&(n=v(`0${n}`)),t?v(`0x${n}`):n}function W(e){if("string"==typeof e){const t=T(e).toLowerCase();if(j(t)&&40===t.length)return k(U(t))}throw f.invalidParams(`Invalid Ethereum address: ${String(e)}`)}function q(e){if(Buffer.isBuffer(e))return e;if("string"==typeof e){if(j(e)){const t=O(e,!1);return Buffer.from(t,"hex")}return Buffer.from(e,"utf8")}throw f.invalidParams(`Not binary data: ${String(e)}`)}function B(e){if("number"==typeof e&&Number.isInteger(e))return E(e);if("string"==typeof e){if(C.test(e))return E(Number(e));if(j(e))return E(Number(BigInt(O(e,!0))))}throw f.invalidParams(`Not an integer: ${String(e)}`)}function z(e){if(null!==e&&("bigint"==typeof e||function(e){if(null==e||"function"!=typeof e.constructor)return!1;const{constructor:t}=e;return"function"==typeof t.config&&"number"==typeof t.EUCLID}(e)))return BigInt(e.toString(10));if("number"==typeof e)return BigInt(B(e));if("string"==typeof e){if(C.test(e))return BigInt(e);if(j(e))return BigInt(O(e,!0))}throw f.invalidParams(`Not an integer: ${String(e)}`)}function K(e){if("string"==typeof e)return JSON.parse(e);if("object"==typeof e)return e;throw f.invalidParams(`Not a JSON string or an object: ${String(e)}`)}function H(e){switch(e){case"public":return"spki";case"private":return"pkcs8"}}async function F(e,t){const n=H(e),s=await crypto.subtle.exportKey(n,t);return M(new Uint8Array(s))}async function G(e,t){const n=H(e),s=A(t).buffer;return await crypto.subtle.importKey(n,new Uint8Array(s),{name:"ECDH",namedCurve:"P-256"},!0,"private"===e?["deriveKey"]:[])}async function $(e,t){return async function(e,t){const n=crypto.getRandomValues(new Uint8Array(12));return{iv:n,cipherText:await crypto.subtle.encrypt({name:"AES-GCM",iv:n},e,(new TextEncoder).encode(t))}}(t,JSON.stringify(e,((e,t)=>{if(!(t instanceof Error))return t;const n=t;return Object.assign(Object.assign({},n.code?{code:n.code}:{}),{message:n.message})})))}async function J(e,t){return JSON.parse(await async function(e,{iv:t,cipherText:n}){const s=await crypto.subtle.decrypt({name:"AES-GCM",iv:t},e,n);return(new TextDecoder).decode(s)}(t,e))}const Y={storageKey:"ownPrivateKey",keyType:"private"},V={storageKey:"ownPublicKey",keyType:"public"},Q={storageKey:"peerPublicKey",keyType:"public"};class Z{constructor(){this.storage=new s("CBWSDK","SCWKeyManager"),this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null}async getOwnPublicKey(){return await this.loadKeysIfNeeded(),this.ownPublicKey}async getSharedSecret(){return await this.loadKeysIfNeeded(),this.sharedSecret}async setPeerPublicKey(e){this.sharedSecret=null,this.peerPublicKey=e,await this.storeKey(Q,e),await this.loadKeysIfNeeded()}async clear(){this.ownPrivateKey=null,this.ownPublicKey=null,this.peerPublicKey=null,this.sharedSecret=null,this.storage.removeItem(V.storageKey),this.storage.removeItem(Y.storageKey),this.storage.removeItem(Q.storageKey)}async generateKeyPair(){const e=await async function(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"])}();this.ownPrivateKey=e.privateKey,this.ownPublicKey=e.publicKey,await this.storeKey(Y,e.privateKey),await this.storeKey(V,e.publicKey)}async loadKeysIfNeeded(){if(null===this.ownPrivateKey&&(this.ownPrivateKey=await this.loadKey(Y)),null===this.ownPublicKey&&(this.ownPublicKey=await this.loadKey(V)),null!==this.ownPrivateKey&&null!==this.ownPublicKey||await this.generateKeyPair(),null===this.peerPublicKey&&(this.peerPublicKey=await this.loadKey(Q)),null===this.sharedSecret){if(null===this.ownPrivateKey||null===this.peerPublicKey)return;this.sharedSecret=await async function(e,t){return crypto.subtle.deriveKey({name:"ECDH",public:t},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}(this.ownPrivateKey,this.peerPublicKey)}}async loadKey(e){const t=this.storage.getItem(e.storageKey);return t?G(e.keyType,t):null}async storeKey(e,t){const n=await F(e.keyType,t);this.storage.setItem(e.storageKey,n)}}const X="4.2.3",ee="@coinbase/wallet-sdk";async function te(e,t){const n=Object.assign(Object.assign({},e),{jsonrpc:"2.0",id:crypto.randomUUID()}),s=await window.fetch(t,{method:"POST",body:JSON.stringify(n),mode:"cors",headers:{"Content-Type":"application/json","X-Cbw-Sdk-Version":X,"X-Cbw-Sdk-Platform":ee}}),{result:i,error:r}=await s.json();if(r)throw r;return i}function ne({metadata:e,preference:t}){var n,s;const{appName:i,appLogoUrl:r,appChainIds:a}=e;if("smartWalletOnly"!==t.options){const e=globalThis.coinbaseWalletExtension;if(e)return null===(n=e.setAppInfo)||void 0===n||n.call(e,i,r,a,t),e}const o=function(){var e,t;try{const n=globalThis;return null!==(e=n.ethereum)&&void 0!==e?e:null===(t=n.top)||void 0===t?void 0:t.ethereum}catch(e){return}}();if(null==o?void 0:o.isCoinbaseBrowser)return null===(s=o.setAppInfo)||void 0===s||s.call(o,i,r,a,t),o}const se="accounts",ie="activeChain",re="availableChains",ae="walletCapabilities";class oe{constructor(e){var t,n,i;this.metadata=e.metadata,this.communicator=e.communicator,this.callback=e.callback,this.keyManager=new Z,this.storage=new s("CBWSDK","SCWStateManager"),this.accounts=null!==(t=this.storage.loadObject(se))&&void 0!==t?t:[],this.chain=this.storage.loadObject(ie)||{id:null!==(i=null===(n=e.metadata.appChainIds)||void 0===n?void 0:n[0])&&void 0!==i?i:1},this.handshake=this.handshake.bind(this),this.request=this.request.bind(this),this.createRequestMessage=this.createRequestMessage.bind(this),this.decryptResponseMessage=this.decryptResponseMessage.bind(this)}async handshake(e){var t,n;const s=await this.createRequestMessage({handshake:{method:e.method,params:Object.assign({},this.metadata,null!==(t=e.params)&&void 0!==t?t:{})}}),i=await this.communicator.postRequestAndWaitForResponse(s);if("failure"in i.content)throw i.content.failure;const r=await G("public",i.sender);await this.keyManager.setPeerPublicKey(r);const a=(await this.decryptResponseMessage(i)).result;if("error"in a)throw a.error;const o=a.value;this.accounts=o,this.storage.storeObject(se,o),null===(n=this.callback)||void 0===n||n.call(this,"accountsChanged",o)}async request(e){var t;if(0===this.accounts.length)throw g.unauthorized();switch(e.method){case"eth_requestAccounts":return null===(t=this.callback)||void 0===t||t.call(this,"connect",{chainId:N(this.chain.id)}),this.accounts;case"eth_accounts":return this.accounts;case"eth_coinbase":return this.accounts[0];case"net_version":return this.chain.id;case"eth_chainId":return N(this.chain.id);case"wallet_getCapabilities":return this.storage.loadObject(ae);case"wallet_switchEthereumChain":return this.handleSwitchChainRequest(e);case"eth_ecRecover":case"personal_sign":case"personal_ecRecover":case"eth_signTransaction":case"eth_sendTransaction":case"eth_signTypedData_v1":case"eth_signTypedData_v3":case"eth_signTypedData_v4":case"eth_signTypedData":case"wallet_addEthereumChain":case"wallet_watchAsset":case"wallet_sendCalls":case"wallet_showCallsStatus":case"wallet_grantPermissions":return this.sendRequestToPopup(e);default:if(!this.chain.rpcUrl)throw f.internal("No RPC URL set for chain");return te(e,this.chain.rpcUrl)}}async sendRequestToPopup(e){var t,n;await(null===(n=(t=this.communicator).waitForPopupLoaded)||void 0===n?void 0:n.call(t));const s=await this.sendEncryptedRequest(e),i=(await this.decryptResponseMessage(s)).result;if("error"in i)throw i.error;return i.value}async cleanup(){var e,t;this.storage.clear(),await this.keyManager.clear(),this.accounts=[],this.chain={id:null!==(t=null===(e=this.metadata.appChainIds)||void 0===e?void 0:e[0])&&void 0!==t?t:1}}async handleSwitchChainRequest(e){var t;const n=e.params;if(!n||!(null===(t=n[0])||void 0===t?void 0:t.chainId))throw f.invalidParams();const s=B(n[0].chainId);if(this.updateChain(s))return null;const i=await this.sendRequestToPopup(e);return null===i&&this.updateChain(s),i}async sendEncryptedRequest(e){const t=await this.keyManager.getSharedSecret();if(!t)throw g.unauthorized("No valid session found, try requestAccounts before other methods");const n=await $({action:e,chainId:this.chain.id},t),s=await this.createRequestMessage({encrypted:n});return this.communicator.postRequestAndWaitForResponse(s)}async createRequestMessage(e){const t=await F("public",await this.keyManager.getOwnPublicKey());return{id:crypto.randomUUID(),sender:t,content:e,timestamp:new Date}}async decryptResponseMessage(e){var t,n;const s=e.content;if("failure"in s)throw s.failure;const i=await this.keyManager.getSharedSecret();if(!i)throw g.unauthorized("Invalid session");const r=await J(s.encrypted,i),a=null===(t=r.data)||void 0===t?void 0:t.chains;if(a){const e=Object.entries(a).map((([e,t])=>({id:Number(e),rpcUrl:t})));this.storage.storeObject(re,e),this.updateChain(this.chain.id,e)}const o=null===(n=r.data)||void 0===n?void 0:n.capabilities;return o&&this.storage.storeObject(ae,o),r}updateChain(e,t){var n;const s=null!=t?t:this.storage.loadObject(re),i=null==s?void 0:s.find((t=>t.id===e));return!!i&&(i!==this.chain&&(this.chain=i,this.storage.storeObject(ie,i),null===(n=this.callback)||void 0===n||n.call(this,"chainChanged",N(i.id))),!0)}}var ce=n(76532);const le="Addresses";function de(e){return void 0!==e.errorMessage}class ue{constructor(e){this.secret=e}async encrypt(e){const t=this.secret;if(64!==t.length)throw Error("secret must be 256 bits");const n=crypto.getRandomValues(new Uint8Array(12)),s=await crypto.subtle.importKey("raw",A(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),i=new TextEncoder,r=await window.crypto.subtle.encrypt({name:"AES-GCM",iv:n},s,i.encode(e)),a=r.slice(r.byteLength-16),o=r.slice(0,r.byteLength-16),c=new Uint8Array(a),l=new Uint8Array(o);return M(new Uint8Array([...n,...c,...l]))}async decrypt(e){const t=this.secret;if(64!==t.length)throw Error("secret must be 256 bits");return new Promise(((n,s)=>{!async function(){const i=await crypto.subtle.importKey("raw",A(t),{name:"aes-gcm"},!1,["encrypt","decrypt"]),r=A(e),a=r.slice(0,12),o=r.slice(12,28),c=r.slice(28),l=new Uint8Array([...c,...o]),d={name:"AES-GCM",iv:new Uint8Array(a)};try{const e=await window.crypto.subtle.decrypt(d,i,l),t=new TextDecoder;n(t.decode(e))}catch(e){s(e)}}()}))}}class he{constructor(e,t,n){this.linkAPIUrl=e,this.sessionId=t;const s=`${t}:${n}`;this.auth=`Basic ${btoa(s)}`}async markUnseenEventsAsSeen(e){return Promise.all(e.map((e=>fetch(`${this.linkAPIUrl}/events/${e.eventId}/seen`,{method:"POST",headers:{Authorization:this.auth}})))).catch((e=>console.error("Unabled to mark event as failed:",e)))}async fetchUnseenEvents(){var e;const t=await fetch(`${this.linkAPIUrl}/events?unseen=true`,{headers:{Authorization:this.auth}});if(t.ok){const{events:n,error:s}=await t.json();if(s)throw new Error(`Check unseen events failed: ${s}`);const i=null!==(e=null==n?void 0:n.filter((e=>"Web3Response"===e.event)).map((e=>({type:"Event",sessionId:this.sessionId,eventId:e.id,event:e.event,data:e.data}))))&&void 0!==e?e:[];return this.markUnseenEventsAsSeen(i),i}throw new Error(`Check unseen events failed: ${t.status}`)}}var pe;!function(e){e[e.DISCONNECTED=0]="DISCONNECTED",e[e.CONNECTING=1]="CONNECTING",e[e.CONNECTED=2]="CONNECTED"}(pe||(pe={}));class fe{setConnectionStateListener(e){this.connectionStateListener=e}setIncomingDataListener(e){this.incomingDataListener=e}constructor(e,t=WebSocket){this.WebSocketClass=t,this.webSocket=null,this.pendingData=[],this.url=e.replace(/^http/,"ws")}async connect(){if(this.webSocket)throw new Error("webSocket object is not null");return new Promise(((e,t)=>{var n;let s;try{this.webSocket=s=new this.WebSocketClass(this.url)}catch(e){return void t(e)}null===(n=this.connectionStateListener)||void 0===n||n.call(this,pe.CONNECTING),s.onclose=e=>{var n;this.clearWebSocket(),t(new Error(`websocket error ${e.code}: ${e.reason}`)),null===(n=this.connectionStateListener)||void 0===n||n.call(this,pe.DISCONNECTED)},s.onopen=t=>{var n;if(e(),null===(n=this.connectionStateListener)||void 0===n||n.call(this,pe.CONNECTED),this.pendingData.length>0){[...this.pendingData].forEach((e=>this.sendData(e))),this.pendingData=[]}},s.onmessage=e=>{var t,n;if("h"===e.data)null===(t=this.incomingDataListener)||void 0===t||t.call(this,{type:"Heartbeat"});else try{const t=JSON.parse(e.data);null===(n=this.incomingDataListener)||void 0===n||n.call(this,t)}catch(e){}}}))}disconnect(){var e;const{webSocket:t}=this;if(t){this.clearWebSocket(),null===(e=this.connectionStateListener)||void 0===e||e.call(this,pe.DISCONNECTED),this.connectionStateListener=void 0,this.incomingDataListener=void 0;try{t.close()}catch(e){}}}sendData(e){const{webSocket:t}=this;if(!t)return this.pendingData.push(e),void this.connect();t.send(e)}clearWebSocket(){const{webSocket:e}=this;e&&(this.webSocket=null,e.onclose=null,e.onerror=null,e.onmessage=null,e.onopen=null)}}class ge{constructor({session:e,linkAPIUrl:t,listener:n}){this.destroyed=!1,this.lastHeartbeatResponse=0,this.nextReqId=E(1),this._connected=!1,this._linked=!1,this.shouldFetchUnseenEventsOnConnect=!1,this.requestResolutions=new Map,this.handleSessionMetadataUpdated=e=>{if(!e)return;new Map([["__destroyed",this.handleDestroyed],["EthereumAddress",this.handleAccountUpdated],["WalletUsername",this.handleWalletUsernameUpdated],["AppVersion",this.handleAppVersionUpdated],["ChainId",t=>e.JsonRpcUrl&&this.handleChainUpdated(t,e.JsonRpcUrl)]]).forEach(((t,n)=>{const s=e[n];void 0!==s&&t(s)}))},this.handleDestroyed=e=>{var t;"1"===e&&(null===(t=this.listener)||void 0===t||t.resetAndReload())},this.handleAccountUpdated=async e=>{var t;const n=await this.cipher.decrypt(e);null===(t=this.listener)||void 0===t||t.accountUpdated(n)},this.handleMetadataUpdated=async(e,t)=>{var n;const s=await this.cipher.decrypt(t);null===(n=this.listener)||void 0===n||n.metadataUpdated(e,s)},this.handleWalletUsernameUpdated=async e=>{this.handleMetadataUpdated("walletUsername",e)},this.handleAppVersionUpdated=async e=>{this.handleMetadataUpdated("AppVersion",e)},this.handleChainUpdated=async(e,t)=>{var n;const s=await this.cipher.decrypt(e),i=await this.cipher.decrypt(t);null===(n=this.listener)||void 0===n||n.chainUpdated(s,i)},this.session=e,this.cipher=new ue(e.secret),this.listener=n;const s=new fe(`${t}/rpc`,WebSocket);s.setConnectionStateListener((async e=>{let t=!1;switch(e){case pe.DISCONNECTED:if(!this.destroyed){const e=async()=>{await new Promise((e=>setTimeout(e,5e3))),this.destroyed||s.connect().catch((()=>{e()}))};e()}break;case pe.CONNECTED:t=await this.handleConnected(),this.updateLastHeartbeat(),setInterval((()=>{this.heartbeat()}),1e4),this.shouldFetchUnseenEventsOnConnect&&this.fetchUnseenEventsAPI();case pe.CONNECTING:}this.connected!==t&&(this.connected=t)})),s.setIncomingDataListener((e=>{var t;switch(e.type){case"Heartbeat":return void this.updateLastHeartbeat();case"IsLinkedOK":case"Linked":{const t="IsLinkedOK"===e.type?e.linked:void 0;this.linked=t||e.onlineGuests>0;break}case"GetSessionConfigOK":case"SessionConfigUpdated":this.handleSessionMetadataUpdated(e.metadata);break;case"Event":this.handleIncomingEvent(e)}void 0!==e.id&&(null===(t=this.requestResolutions.get(e.id))||void 0===t||t(e))})),this.ws=s,this.http=new he(t,e.id,e.key)}connect(){if(this.destroyed)throw new Error("instance is destroyed");this.ws.connect()}async destroy(){this.destroyed||(await this.makeRequest({type:"SetSessionConfig",id:E(this.nextReqId++),sessionId:this.session.id,metadata:{__destroyed:"1"}},{timeout:1e3}),this.destroyed=!0,this.ws.disconnect(),this.listener=void 0)}get connected(){return this._connected}set connected(e){this._connected=e}get linked(){return this._linked}set linked(e){var t,n;this._linked=e,e&&(null===(t=this.onceLinked)||void 0===t||t.call(this)),null===(n=this.listener)||void 0===n||n.linkedUpdated(e)}setOnceLinked(e){return new Promise((t=>{this.linked?e().then(t):this.onceLinked=()=>{e().then(t),this.onceLinked=void 0}}))}async handleIncomingEvent(e){var t;if("Event"!==e.type||"Web3Response"!==e.event)return;const n=await this.cipher.decrypt(e.data),s=JSON.parse(n);if("WEB3_RESPONSE"!==s.type)return;const{id:i,response:r}=s;null===(t=this.listener)||void 0===t||t.handleWeb3ResponseMessage(i,r)}async checkUnseenEvents(){if(this.connected){await new Promise((e=>setTimeout(e,250)));try{await this.fetchUnseenEventsAPI()}catch(e){console.error("Unable to check for unseen events",e)}}else this.shouldFetchUnseenEventsOnConnect=!0}async fetchUnseenEventsAPI(){this.shouldFetchUnseenEventsOnConnect=!1;(await this.http.fetchUnseenEvents()).forEach((e=>this.handleIncomingEvent(e)))}async publishEvent(e,t,n=!1){const s=await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({},t),{origin:location.origin,relaySource:"coinbaseWalletExtension"in window&&window.coinbaseWalletExtension?"injected_sdk":"sdk"}))),i={type:"PublishEvent",id:E(this.nextReqId++),sessionId:this.session.id,event:e,data:s,callWebhook:n};return this.setOnceLinked((async()=>{const e=await this.makeRequest(i);if("Fail"===e.type)throw new Error(e.error||"failed to publish event");return e.eventId}))}sendData(e){this.ws.sendData(JSON.stringify(e))}updateLastHeartbeat(){this.lastHeartbeatResponse=Date.now()}heartbeat(){if(Date.now()-this.lastHeartbeatResponse>2e4)this.ws.disconnect();else try{this.ws.sendData("h")}catch(e){}}async makeRequest(e,t={timeout:6e4}){const n=e.id;let s;return this.sendData(e),Promise.race([new Promise(((e,i)=>{s=window.setTimeout((()=>{i(new Error(`request ${n} timed out`))}),t.timeout)})),new Promise((e=>{this.requestResolutions.set(n,(t=>{clearTimeout(s),e(t),this.requestResolutions.delete(n)}))}))])}async handleConnected(){return"Fail"!==(await this.makeRequest({type:"HostSession",id:E(this.nextReqId++),sessionId:this.session.id,sessionKey:this.session.key})).type&&(this.sendData({type:"IsLinked",id:E(this.nextReqId++),sessionId:this.session.id}),this.sendData({type:"GetSessionConfig",id:E(this.nextReqId++),sessionId:this.session.id}),!0)}}class me{constructor(){this._nextRequestId=0,this.callbacks=new Map}makeRequestId(){this._nextRequestId=(this._nextRequestId+1)%2147483647;const e=this._nextRequestId,t=U(e.toString(16));return this.callbacks.get(t)&&this.callbacks.delete(t),e}}function _e(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ye(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function be(e,t){_e(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const we=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ve=(e,t)=>e<<32-t|e>>>t;const ke=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function Ie(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),_e(e),e}class Ee{clone(){return this._cloneInto()}}function Ce(e){const t=t=>e().update(Ie(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}const xe=(e,t,n)=>e&t^e&n^t&n;class Se extends Ee{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=we(this.buffer)}update(e){ye(this);const{view:t,buffer:n,blockLen:s}=this,i=(e=Ie(e)).length;for(let r=0;r<i;){const a=Math.min(s-this.pos,i-r);if(a!==s)n.set(e.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===s&&(this.process(t,0),this.pos=0);else{const t=we(e);for(;s<=i-r;r+=s)this.process(t,r)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){ye(this),be(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:s,isLE:i}=this;let{pos:r}=this;t[r++]=128,this.buffer.subarray(r).fill(0),this.padOffset>s-r&&(this.process(n,0),r=0);for(let e=r;e<s;e++)t[e]=0;!function(e,t,n,s){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,s);const i=BigInt(32),r=BigInt(4294967295),a=Number(n>>i&r),o=Number(n&r),c=s?4:0,l=s?0:4;e.setUint32(t+c,a,s),e.setUint32(t+l,o,s)}(n,s-8,BigInt(8*this.length),i),this.process(n,0);const a=we(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=o/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)a.setUint32(4*e,l[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:s,finished:i,destroyed:r,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=r,s%t&&e.buffer.set(n),e}}const Me=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ae=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pe=new Uint32Array(64);class Le extends Se{constructor(){super(64,32,8,!1),this.A=0|Ae[0],this.B=0|Ae[1],this.C=0|Ae[2],this.D=0|Ae[3],this.E=0|Ae[4],this.F=0|Ae[5],this.G=0|Ae[6],this.H=0|Ae[7]}get(){const{A:e,B:t,C:n,D:s,E:i,F:r,G:a,H:o}=this;return[e,t,n,s,i,r,a,o]}set(e,t,n,s,i,r,a,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|s,this.E=0|i,this.F=0|r,this.G=0|a,this.H=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)Pe[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Pe[e-15],n=Pe[e-2],s=ve(t,7)^ve(t,18)^t>>>3,i=ve(n,17)^ve(n,19)^n>>>10;Pe[e]=i+Pe[e-7]+s+Pe[e-16]|0}let{A:n,B:s,C:i,D:r,E:a,F:o,G:c,H:l}=this;for(let e=0;e<64;e++){const t=l+(ve(a,6)^ve(a,11)^ve(a,25))+((d=a)&o^~d&c)+Me[e]+Pe[e]|0,u=(ve(n,2)^ve(n,13)^ve(n,22))+xe(n,s,i)|0;l=c,c=o,o=a,a=r+t|0,r=i,i=s,s=n,n=t+u|0}var d;n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,r=r+this.D|0,a=a+this.E|0,o=o+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,s,i,r,a,o,c,l)}roundClean(){Pe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const De=Ce((()=>new Le)),Ne="session:id",Re="session:secret",Te="session:linked";class Ue{constructor(e,t,n,s=!1){this.storage=e,this.id=t,this.secret=n,this.key=function(e){_e(e);let t="";for(let n=0;n<e.length;n++)t+=ke[e[n]];return t}(De(`${t}, ${n} WalletLink`)),this._linked=!!s}static create(e){const t=S(16),n=S(32);return new Ue(e,t,n).save()}static load(e){const t=e.getItem(Ne),n=e.getItem(Te),s=e.getItem(Re);return t&&s?new Ue(e,t,s,"1"===n):null}get linked(){return this._linked}set linked(e){this._linked=e,this.persistLinked()}save(){return this.storage.setItem(Ne,this.id),this.storage.setItem(Re,this.secret),this.persistLinked(),this}persistLinked(){this.storage.setItem(Te,this._linked?"1":"0")}}function je(){try{return function(){try{return null!==window.frameElement}catch(e){return!1}}()&&window.top?window.top.location:window.location}catch(e){return window.location}}function Oe(){var e,t;return null!==(t=null===(e=null===window||void 0===window?void 0:window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)").matches)&&void 0!==t&&t}function We(){const e=document.createElement("style");e.type="text/css",e.appendChild(document.createTextNode('@namespace svg "http://www.w3.org/2000/svg";.-cbwsdk-css-reset,.-cbwsdk-css-reset *{animation:none;animation-delay:0;animation-direction:normal;animation-duration:0;animation-fill-mode:none;animation-iteration-count:1;animation-name:none;animation-play-state:running;animation-timing-function:ease;backface-visibility:visible;background:0;background-attachment:scroll;background-clip:border-box;background-color:rgba(0,0,0,0);background-image:none;background-origin:padding-box;background-position:0 0;background-position-x:0;background-position-y:0;background-repeat:repeat;background-size:auto auto;border:0;border-style:none;border-width:medium;border-color:inherit;border-bottom:0;border-bottom-color:inherit;border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-style:none;border-bottom-width:medium;border-collapse:separate;border-image:none;border-left:0;border-left-color:inherit;border-left-style:none;border-left-width:medium;border-radius:0;border-right:0;border-right-color:inherit;border-right-style:none;border-right-width:medium;border-spacing:0;border-top:0;border-top-color:inherit;border-top-left-radius:0;border-top-right-radius:0;border-top-style:none;border-top-width:medium;box-shadow:none;box-sizing:border-box;caption-side:top;clear:none;clip:auto;color:inherit;columns:auto;column-count:auto;column-fill:balance;column-gap:normal;column-rule:medium none currentColor;column-rule-color:currentColor;column-rule-style:none;column-rule-width:none;column-span:1;column-width:auto;counter-increment:none;counter-reset:none;direction:ltr;empty-cells:show;float:none;font:normal;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;height:auto;hyphens:none;letter-spacing:normal;line-height:normal;list-style:none;list-style-image:none;list-style-position:outside;list-style-type:disc;margin:0;margin-bottom:0;margin-left:0;margin-right:0;margin-top:0;opacity:1;orphans:0;outline:0;outline-color:invert;outline-style:none;outline-width:medium;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;padding-bottom:0;padding-left:0;padding-right:0;padding-top:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;perspective:none;perspective-origin:50% 50%;pointer-events:auto;position:static;quotes:"\\201C" "\\201D" "\\2018" "\\2019";tab-size:8;table-layout:auto;text-align:inherit;text-align-last:auto;text-decoration:none;text-decoration-color:inherit;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-shadow:none;text-transform:none;transform:none;transform-style:flat;transition:none;transition-delay:0s;transition-duration:0s;transition-property:none;transition-timing-function:ease;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:0;word-spacing:normal;z-index:auto}.-cbwsdk-css-reset strong{font-weight:bold}.-cbwsdk-css-reset *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;line-height:1}.-cbwsdk-css-reset [class*=container]{margin:0;padding:0}.-cbwsdk-css-reset style{display:none}')),document.documentElement.appendChild(e)}var qe=n(20053),Be=n(50172),ze=n(45994);class Ke{constructor(){this.items=new Map,this.nextItemKey=0,this.root=null,this.darkMode=Oe()}attach(e){this.root=document.createElement("div"),this.root.className="-cbwsdk-snackbar-root",e.appendChild(this.root),this.render()}presentItem(e){const t=this.nextItemKey++;return this.items.set(t,e),this.render(),()=>{this.items.delete(t),this.render()}}clear(){this.items.clear(),this.render()}render(){this.root&&(0,Be.render)((0,Be.h)("div",null,(0,Be.h)(He,{darkMode:this.darkMode},Array.from(this.items.entries()).map((([e,t])=>(0,Be.h)(Fe,Object.assign({},t,{key:e})))))),this.root)}}const He=e=>(0,Be.h)("div",{class:(0,qe.clsx)("-cbwsdk-snackbar-container")},(0,Be.h)("style",null,".-cbwsdk-css-reset .-gear-container{margin-left:16px !important;margin-right:9px !important;display:flex;align-items:center;justify-content:center;width:24px;height:24px;transition:opacity .25s}.-cbwsdk-css-reset .-gear-container *{user-select:none}.-cbwsdk-css-reset .-gear-container svg{opacity:0;position:absolute}.-cbwsdk-css-reset .-gear-icon{height:12px;width:12px;z-index:10000}.-cbwsdk-css-reset .-cbwsdk-snackbar{align-items:flex-end;display:flex;flex-direction:column;position:fixed;right:0;top:0;z-index:2147483647}.-cbwsdk-css-reset .-cbwsdk-snackbar *{user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance{display:flex;flex-direction:column;margin:8px 16px 0 16px;overflow:visible;text-align:left;transform:translateX(0);transition:opacity .25s,transform .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header:hover .-gear-container svg{opacity:1}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header{display:flex;align-items:center;background:#fff;overflow:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-cblogo{margin:8px 8px 8px 8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-message{color:#000;font-size:13px;line-height:1.5;user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu{background:#fff;transition:opacity .25s ease-in-out,transform .25s linear,visibility 0s;visibility:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;opacity:0;flex-direction:column;padding-left:8px;padding-right:8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:last-child{margin-bottom:8px !important}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover{background:#f5f7f8;border-radius:6px;transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover span{color:#050f19;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover svg path{fill:#000;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item{visibility:inherit;height:35px;margin-top:8px;margin-bottom:0;display:flex;flex-direction:row;align-items:center;padding:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item *{visibility:inherit;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover{background:rgba(223,95,103,.2);transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover svg path{fill:#df5f67;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover span{color:#df5f67;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-info{color:#aaa;font-size:13px;margin:0 8px 0 32px;position:absolute}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-hidden{opacity:0;text-align:left;transform:translateX(25%);transition:opacity .5s linear}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-expanded .-cbwsdk-snackbar-instance-menu{opacity:1;display:flex;transform:translateY(8px);visibility:visible}"),(0,Be.h)("div",{class:"-cbwsdk-snackbar"},e.children)),Fe=({autoExpand:e,message:t,menuItems:n})=>{const[s,i]=(0,ze.useState)(!0),[r,a]=(0,ze.useState)(null!=e&&e);(0,ze.useEffect)((()=>{const e=[window.setTimeout((()=>{i(!1)}),1),window.setTimeout((()=>{a(!0)}),1e4)];return()=>{e.forEach(window.clearTimeout)}}));return(0,Be.h)("div",{class:(0,qe.clsx)("-cbwsdk-snackbar-instance",s&&"-cbwsdk-snackbar-instance-hidden",r&&"-cbwsdk-snackbar-instance-expanded")},(0,Be.h)("div",{class:"-cbwsdk-snackbar-instance-header",onClick:()=>{a(!r)}},(0,Be.h)("img",{src:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEuNDkyIDEwLjQxOWE4LjkzIDguOTMgMCAwMTguOTMtOC45M2gxMS4xNjNhOC45MyA4LjkzIDAgMDE4LjkzIDguOTN2MTEuMTYzYTguOTMgOC45MyAwIDAxLTguOTMgOC45M0gxMC40MjJhOC45MyA4LjkzIDAgMDEtOC45My04LjkzVjEwLjQxOXoiIGZpbGw9IiMxNjUyRjAiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwLjQxOSAwSDIxLjU4QzI3LjMzNSAwIDMyIDQuNjY1IDMyIDEwLjQxOVYyMS41OEMzMiAyNy4zMzUgMjcuMzM1IDMyIDIxLjU4MSAzMkgxMC40MkM0LjY2NSAzMiAwIDI3LjMzNSAwIDIxLjU4MVYxMC40MkMwIDQuNjY1IDQuNjY1IDAgMTAuNDE5IDB6bTAgMS40ODhhOC45MyA4LjkzIDAgMDAtOC45MyA4LjkzdjExLjE2M2E4LjkzIDguOTMgMCAwMDguOTMgOC45M0gyMS41OGE4LjkzIDguOTMgMCAwMDguOTMtOC45M1YxMC40MmE4LjkzIDguOTMgMCAwMC04LjkzLTguOTNIMTAuNDJ6IiBmaWxsPSIjZmZmIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNS45OTggMjYuMDQ5Yy01LjU0OSAwLTEwLjA0Ny00LjQ5OC0xMC4wNDctMTAuMDQ3IDAtNS41NDggNC40OTgtMTAuMDQ2IDEwLjA0Ny0xMC4wNDYgNS41NDggMCAxMC4wNDYgNC40OTggMTAuMDQ2IDEwLjA0NiAwIDUuNTQ5LTQuNDk4IDEwLjA0Ny0xMC4wNDYgMTAuMDQ3eiIgZmlsbD0iI2ZmZiIvPjxwYXRoIGQ9Ik0xMi43NjIgMTQuMjU0YzAtLjgyMi42NjctMS40ODkgMS40ODktMS40ODloMy40OTdjLjgyMiAwIDEuNDg4LjY2NiAxLjQ4OCAxLjQ4OXYzLjQ5N2MwIC44MjItLjY2NiAxLjQ4OC0xLjQ4OCAxLjQ4OGgtMy40OTdhMS40ODggMS40ODggMCAwMS0xLjQ4OS0xLjQ4OHYtMy40OTh6IiBmaWxsPSIjMTY1MkYwIi8+PC9zdmc+",class:"-cbwsdk-snackbar-instance-header-cblogo"})," ",(0,Be.h)("div",{class:"-cbwsdk-snackbar-instance-header-message"},t),(0,Be.h)("div",{class:"-gear-container"},!r&&(0,Be.h)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,Be.h)("circle",{cx:"12",cy:"12",r:"12",fill:"#F5F7F8"})),(0,Be.h)("img",{src:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDYuNzV2LTEuNWwtMS43Mi0uNTdjLS4wOC0uMjctLjE5LS41Mi0uMzItLjc3bC44MS0xLjYyLTEuMDYtMS4wNi0xLjYyLjgxYy0uMjQtLjEzLS41LS4yNC0uNzctLjMyTDYuNzUgMGgtMS41bC0uNTcgMS43MmMtLjI3LjA4LS41My4xOS0uNzcuMzJsLTEuNjItLjgxLTEuMDYgMS4wNi44MSAxLjYyYy0uMTMuMjQtLjI0LjUtLjMyLjc3TDAgNS4yNXYxLjVsMS43Mi41N2MuMDguMjcuMTkuNTMuMzIuNzdsLS44MSAxLjYyIDEuMDYgMS4wNiAxLjYyLS44MWMuMjQuMTMuNS4yMy43Ny4zMkw1LjI1IDEyaDEuNWwuNTctMS43MmMuMjctLjA4LjUyLS4xOS43Ny0uMzJsMS42Mi44MSAxLjA2LTEuMDYtLjgxLTEuNjJjLjEzLS4yNC4yMy0uNS4zMi0uNzdMMTIgNi43NXpNNiA4LjVhMi41IDIuNSAwIDAxMC01IDIuNSAyLjUgMCAwMTAgNXoiIGZpbGw9IiMwNTBGMTkiLz48L3N2Zz4=",class:"-gear-icon",title:"Expand"}))),n&&n.length>0&&(0,Be.h)("div",{class:"-cbwsdk-snackbar-instance-menu"},n.map(((e,t)=>(0,Be.h)("div",{class:(0,qe.clsx)("-cbwsdk-snackbar-instance-menu-item",e.isRed&&"-cbwsdk-snackbar-instance-menu-item-is-red"),onClick:e.onClick,key:t},(0,Be.h)("svg",{width:e.svgWidth,height:e.svgHeight,viewBox:"0 0 10 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,Be.h)("path",{"fill-rule":e.defaultFillRule,"clip-rule":e.defaultClipRule,d:e.path,fill:"#AAAAAA"})),(0,Be.h)("span",{class:(0,qe.clsx)("-cbwsdk-snackbar-instance-menu-item-info",e.isRed&&"-cbwsdk-snackbar-instance-menu-item-info-is-red")},e.info))))))};class Ge{constructor(){this.attached=!1,this.snackbar=new Ke}attach(){if(this.attached)throw new Error("Coinbase Wallet SDK UI is already attached");const e=document.documentElement,t=document.createElement("div");t.className="-cbwsdk-css-reset",e.appendChild(t),this.snackbar.attach(t),this.attached=!0,We()}showConnecting(e){let t;return t=e.isUnlinkedErrorState?{autoExpand:!0,message:"Connection lost",menuItems:[{isRed:!1,info:"Reset connection",svgWidth:"10",svgHeight:"11",path:"M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",defaultFillRule:"evenodd",defaultClipRule:"evenodd",onClick:e.onResetConnection}]}:{message:"Confirm on phone",menuItems:[{isRed:!0,info:"Cancel transaction",svgWidth:"11",svgHeight:"11",path:"M10.3711 1.52346L9.21775 0.370117L5.37109 4.21022L1.52444 0.370117L0.371094 1.52346L4.2112 5.37012L0.371094 9.21677L1.52444 10.3701L5.37109 6.53001L9.21775 10.3701L10.3711 9.21677L6.53099 5.37012L10.3711 1.52346Z",defaultFillRule:"inherit",defaultClipRule:"inherit",onClick:e.onCancel},{isRed:!1,info:"Reset connection",svgWidth:"10",svgHeight:"11",path:"M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",defaultFillRule:"evenodd",defaultClipRule:"evenodd",onClick:e.onResetConnection}]},this.snackbar.presentItem(t)}}class $e{constructor(){this.root=null,this.darkMode=Oe()}attach(){const e=document.documentElement;this.root=document.createElement("div"),this.root.className="-cbwsdk-css-reset",e.appendChild(this.root),We()}present(e){this.render(e)}clear(){this.render(null)}render(e){this.root&&((0,Be.render)(null,this.root),e&&(0,Be.render)((0,Be.h)(Je,Object.assign({},e,{onDismiss:()=>{this.clear()},darkMode:this.darkMode})),this.root))}}const Je=({title:e,buttonText:t,darkMode:n,onButtonClick:s,onDismiss:i})=>{const r=n?"dark":"light";return(0,Be.h)(He,{darkMode:n},(0,Be.h)("div",{class:"-cbwsdk-redirect-dialog"},(0,Be.h)("style",null,".-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;transition:opacity .25s;background-color:rgba(10,11,13,.5)}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop-hidden{opacity:0}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box{display:block;position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);padding:20px;border-radius:8px;background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box p{display:block;font-weight:400;font-size:14px;line-height:20px;padding-bottom:12px;color:#5b636e}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box button{appearance:none;border:none;background:none;color:#0052ff;padding:0;text-decoration:none;display:block;font-weight:600;font-size:16px;line-height:24px}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark{background-color:#0a0b0d;color:#fff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark button{color:#0052ff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light{background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light button{color:#0052ff}"),(0,Be.h)("div",{class:"-cbwsdk-redirect-dialog-backdrop",onClick:i}),(0,Be.h)("div",{class:(0,qe.clsx)("-cbwsdk-redirect-dialog-box",r)},(0,Be.h)("p",null,e),(0,Be.h)("button",{onClick:s},t))))},Ye="https://www.walletlink.org";class Ve{constructor(){this.attached=!1,this.redirectDialog=new $e}attach(){if(this.attached)throw new Error("Coinbase Wallet SDK UI is already attached");this.redirectDialog.attach(),this.attached=!0}redirectToCoinbaseWallet(e){const t=new URL("https://go.cb-w.com/walletlink");t.searchParams.append("redirect_url",je().href),e&&t.searchParams.append("wl_url",e);const n=document.createElement("a");n.target="cbw-opener",n.href=t.href,n.rel="noreferrer noopener",n.click()}openCoinbaseWalletDeeplink(e){this.redirectDialog.present({title:"Redirecting to Coinbase Wallet...",buttonText:"Open",onButtonClick:()=>{this.redirectToCoinbaseWallet(e)}}),setTimeout((()=>{this.redirectToCoinbaseWallet(e)}),99)}showConnecting(e){return()=>{this.redirectDialog.clear()}}}class Qe{constructor(e){var t;this.chainCallbackParams={chainId:"",jsonRpcUrl:""},this.isMobileWeb=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(null===(t=null===window||void 0===window?void 0:window.navigator)||void 0===t?void 0:t.userAgent),this.linkedUpdated=e=>{this.isLinked=e;const t=this.storage.getItem(le);if(e&&(this._session.linked=e),this.isUnlinkedErrorState=!1,t){const n=t.split(" "),s="true"===this.storage.getItem("IsStandaloneSigning");""===n[0]||e||!this._session.linked||s||(this.isUnlinkedErrorState=!0)}},this.metadataUpdated=(e,t)=>{this.storage.setItem(e,t)},this.chainUpdated=(e,t)=>{this.chainCallbackParams.chainId===e&&this.chainCallbackParams.jsonRpcUrl===t||(this.chainCallbackParams={chainId:e,jsonRpcUrl:t},this.chainCallback&&this.chainCallback(t,Number.parseInt(e,10)))},this.accountUpdated=e=>{this.accountsCallback&&this.accountsCallback([e]),Qe.accountRequestCallbackIds.size>0&&(Array.from(Qe.accountRequestCallbackIds.values()).forEach((t=>{this.invokeCallback(t,{method:"requestEthereumAccounts",result:[e]})})),Qe.accountRequestCallbackIds.clear())},this.resetAndReload=this.resetAndReload.bind(this),this.linkAPIUrl=e.linkAPIUrl,this.storage=e.storage,this.metadata=e.metadata,this.accountsCallback=e.accountsCallback,this.chainCallback=e.chainCallback;const{session:n,ui:s,connection:i}=this.subscribe();this._session=n,this.connection=i,this.relayEventManager=new me,this.ui=s,this.ui.attach()}subscribe(){const e=Ue.load(this.storage)||Ue.create(this.storage),{linkAPIUrl:t}=this,n=new ge({session:e,linkAPIUrl:t,listener:this}),s=this.isMobileWeb?new Ve:new Ge;return n.connect(),{session:e,ui:s,connection:n}}resetAndReload(){this.connection.destroy().then((()=>{const e=Ue.load(this.storage);(null==e?void 0:e.id)===this._session.id&&s.clearAll(),document.location.reload()})).catch((e=>{}))}signEthereumTransaction(e){return this.sendRequest({method:"signEthereumTransaction",params:{fromAddress:e.fromAddress,toAddress:e.toAddress,weiValue:D(e.weiValue),data:P(e.data,!0),nonce:e.nonce,gasPriceInWei:e.gasPriceInWei?D(e.gasPriceInWei):null,maxFeePerGas:e.gasPriceInWei?D(e.gasPriceInWei):null,maxPriorityFeePerGas:e.gasPriceInWei?D(e.gasPriceInWei):null,gasLimit:e.gasLimit?D(e.gasLimit):null,chainId:e.chainId,shouldSubmit:!1}})}signAndSubmitEthereumTransaction(e){return this.sendRequest({method:"signEthereumTransaction",params:{fromAddress:e.fromAddress,toAddress:e.toAddress,weiValue:D(e.weiValue),data:P(e.data,!0),nonce:e.nonce,gasPriceInWei:e.gasPriceInWei?D(e.gasPriceInWei):null,maxFeePerGas:e.maxFeePerGas?D(e.maxFeePerGas):null,maxPriorityFeePerGas:e.maxPriorityFeePerGas?D(e.maxPriorityFeePerGas):null,gasLimit:e.gasLimit?D(e.gasLimit):null,chainId:e.chainId,shouldSubmit:!0}})}submitEthereumTransaction(e,t){return this.sendRequest({method:"submitEthereumTransaction",params:{signedTransaction:P(e,!0),chainId:t}})}getWalletLinkSession(){return this._session}sendRequest(e){let t=null;const n=S(8),s=s=>{this.publishWeb3RequestCanceledEvent(n),this.handleErrorResponse(n,e.method,s),null==t||t()};return new Promise(((i,r)=>{t=this.ui.showConnecting({isUnlinkedErrorState:this.isUnlinkedErrorState,onCancel:s,onResetConnection:this.resetAndReload}),this.relayEventManager.callbacks.set(n,(e=>{if(null==t||t(),de(e))return r(new Error(e.errorMessage));i