-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb3-input.js
33 lines (33 loc) · 15.3 KB
/
web3-input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(()=>{var E=Object.create;var S=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var I=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var N=(o,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of O(e))!P.call(o,s)&&s!==i&&S(o,s,{get:()=>e[s],enumerable:!(t=A(e,s))||t.enumerable});return o};var U=(o,e,i)=>(i=o!=null?E(x(o)):{},N(e||!o||!o.__esModule?S(i,"default",{value:o,enumerable:!0}):i,o));var C=I((q,v)=>{"use strict";function $({mustBeMetaMask:o=!1,silent:e=!1,timeout:i=3e3}={}){s();let t=!1;return new Promise(n=>{window.ethereum?r():(window.addEventListener("ethereum#initialized",r,{once:!0}),setTimeout(()=>{r()},i));function r(){if(t)return;t=!0,window.removeEventListener("ethereum#initialized",r);let{ethereum:c}=window;c&&(!o||c.isMetaMask)?n(c):(!e&&console.error("@metamask/detect-provider:",o&&c?"Non-MetaMask window.ethereum detected.":"Unable to detect window.ethereum."),n(null))}});function s(){if(typeof o!="boolean")throw new Error("@metamask/detect-provider: Expected option 'mustBeMetaMask' to be a boolean.");if(typeof e!="boolean")throw new Error("@metamask/detect-provider: Expected option 'silent' to be a boolean.");if(typeof i!="number")throw new Error("@metamask/detect-provider: Expected option 'timeout' to be a number.")}}v.exports=$});var T=U(C(),1);var B=function(o){let e=arguments,i=this,t,s,n=1,r="",c="",a=[0],l=h=>{n===1&&(h||(r=r.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?a.push(h?e[h]:r):n===3&&(h||r)?(a[1]=h?e[h]:r,n=2):n===2&&r==="..."&&h?a[2]=Object.assign(a[2]||{},e[h]):n===2&&r&&!h?(a[2]=a[2]||{})[r]=!0:n>=5&&(n===5?((a[2]=a[2]||{})[s]=h?r?r+e[h]:e[h]:r,n=6):(h||r)&&(a[2][s]+=h?r+e[h]:r)),r=""};for(let h=0;h<o.length;h++){h&&(n===1&&l(),l(h));for(let d=0;d<o[h].length;d++)t=o[h][d],n===1?t==="<"?(l(),a=[a,"",null],n=3):r+=t:n===4?r==="--"&&t===">"?(n=1,r=""):r=t+r[0]:c?t===c?c="":r+=t:t==='"'||t==="'"?c=t:t===">"?(l(),n=1):n&&(t==="="?(n=5,s=r,r=""):t==="/"&&(n<5||o[h][d+1]===">")?(l(),n===3&&(a=a[0]),n=a,(a=a[0]).push(i.apply(null,n.slice(1))),n=0):t===" "||t===" "||t===`
`||t==="\r"?(l(),n=2):r+=t),n===3&&r==="!--"&&(n=4,a=a[0])}return l(),a.length>2?a.slice(1):a[1]},u=B.bind((o,e,...i)=>{let t=null,s=!1;["svg","use","symbol","path","g","defs","title"].indexOf(o)>-1?(t=document.createElementNS("http://www.w3.org/2000/svg",o),s=!0):t=document.createElement(o);for(let n in e)if(n.slice(0,2)==="on"){let r=n.slice(2),c=e[n];if(c==null)continue;t.addEventListener(r,c)}else if(["disabled","selected","checked"].indexOf(n)>-1)e[n]&&t.setAttribute(n,n);else if(n==="xlinkHref"&&s)e[n]&&t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e[n]);else if(n==="href"&&s)e[n]&&t.setAttributeNS("http://www.w3.org/1999/xlink","href",e[n]);else{if(e[n]==null)continue;t.setAttribute(n,e[n])}return i.length===0?t:(i.flat(1).forEach(n=>{n instanceof Node?t.appendChild(n):t.appendChild(document.createTextNode(n))}),o==null?t.children:t)});function b(o,e){for(;e.firstChild;)e.removeChild(e.firstChild);Array.isArray(o)?o.forEach(i=>e.appendChild(i)):e.appendChild(o)}function p(o){return o.replace(/([A-Z])/g,"-$1").toLowerCase()}function f(o){return(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}function g(o,e){let i=function(t){if(!t)return[];let s=[];return Object.keys(t).forEach(n=>{(t[n].observed==null||t[n].observed)&&s.push(p(n))}),s}(e.props);globalThis.customElements.get(o)||globalThis.customElements.define(o,class extends globalThis.HTMLElement{static get observedAttributes(){return i}get componentTagName(){return o}connectedCallback(){this.connectedCallbackCount==null&&(this.connectedCallbackCount=0),this.connectedCallbackCount=this.connectedCallbackCount+1,this._checkInit(),this._preprocess()}disconnectedCallback(){typeof this.removed=="function"&&(this.removed(),this.isRemovedCalled=!0)}attributeChangedCallback(){this.connectedCallbackCount!=null&&(this._checkInit(),this._preprocess())}get initialised(){return this._props&&this._state&&this._computed&&this.templateRenderer}_checkInit(){this.initialised||this._init(e)}_init(t){if(this._props=t.props||{},this._computed=t.computed||{},t.state&&typeof t.state!="function")throw new Error("State must be a function!");this._state=t.state||{},this.computedCache={},this.status="render",this.connectedCallbackCount=0,this.props=this._processProps(),typeof this._state=="function"&&(this._state=this._state.bind(this)()),this.state=this._monitorState(this._state),this.root=this._processRoot(t.root),this.slots=this._processSlots(),this.render=t.render||null,this.templateRenderer=t.renderer,this.template=null,this.created=t.created||null,this.mounted=t.mounted||null,this.updated=t.updated||null,this.removed=t.removed||null,this.isCreatedCalled=!1,this.isMountedCalled=!1,this.isRemovedCalled=!1,this.emit=(s,n)=>{(function(r,c,a={}){let l=Object.assign({},{bubbles:!0,cancelable:!0,composed:!1},a),h;"composed"in CustomEvent.prototype?h=new CustomEvent(c,l):(h=document.createEvent("CustomEvent"),h.initCustomEvent(c,l.bubbles,l.cancelable,l.detail),Object.defineProperty(h,"composed",{value:l.composed})),r.dispatchEvent(h)})(this,s,{detail:n})},this.setState=(s,n)=>{let r=a=>{if(!a||typeof a!="object")return;let l=this.updated;n&&(this.updated=()=>{setTimeout(n),this.updated=l||void 0}),this.status="transaction";for(let h in a)this.state[h]&&this.state[h]===a[h]||(this.state[h]=a[h]);this.status="render",this._processRender()},c=s(this.state);f(c)?c.then(r):r(c)},this._processMethodsAndComputedProps(t),this._processInstanceProps(this._props),typeof this.created!="function"||this.isCreatedCalled||(this.created(),this.isCreatedCalled=!0)}_processProps(){let t={};return Object.keys(this._props).forEach(s=>{let n={},r=this._props[s],c=this._getAttribute(s),a=null;if(r.default!=null&&(a=r.default),r.required&&c==null)a!=null?(console.info(`No biggie, the required prop '${s}' has no value set, so the default has been set`),n[s]=a):(n[s]=null,console.error(`The required prop '${s}' has no value set`));else switch(r.type){case String:default:n[s]=c||a;break;case Number:n[s]=c!=null?parseFloat(c):a??0;break;case Boolean:n[s]=c!=null?c.toString()==="true":a!=null&&a;break;case Object:try{n[s]=c!=null?JSON.parse(c):a??void 0}catch(l){n[s]=a??void 0,console.error("An object parse issue occurred",l)}}t[s]=n[s],this._instanceProps&&this._instanceProps[s]&&(t[s]=this._instanceProps[s])}),t}_processMethodsAndComputedProps(t){let s=this,n=Object.keys(t);n.length&&n.forEach(r=>{s[r]||typeof t[r]!="function"||(s[r]=t[r].bind(s)),r==="computed"&&this._processComputed(t[r])})}_processRoot(t){switch(t){case"standard":default:return this;case"shadow":return this.attachShadow({mode:"open"});case"shadow:closed":return this.attachShadow({mode:"closed"})}}_processComputed(t){let s=this,n=Object.keys(t);n.length&&n.forEach(r=>{s[r]?console.warn(`Computed property '${r}' already exists on the component instance`):Object.defineProperty(s,r,{get:()=>(s.computedCache[r]||(s.computedCache[r]=t[r].bind(s)()),s.computedCache[r])})})}_processRender(){let t=this.render?this.render():void 0;t&&(this.template=t,this._updateRender())}_monitorState(t){let s=this;return new Proxy(t,{set:(n,r,c)=>(n[r]===c||(n[r]=c,s.computedCache={},s.status==="render"&&s._processRender()),!0)})}_processSlots(){let t=this.childNodes,s={default:[]};return t.length>0&&[...t].forEach(n=>{let r=n.getAttribute?n.getAttribute("slot"):null;r?s[r]=n:s.default.push(n)}),s}_getAttribute(t){try{return this.getAttribute(p(t))}catch(s){return console.error("A get prop error occurred",s),""}}_processInstanceProps(t){let s=this,n=Object.keys(t);t&&n.forEach(r=>{let c;s[r]&&(c=s[r],delete s[r]),Object.defineProperty(s,r,{get(){return this._instanceProps&&this._instanceProps[r]?this._instanceProps[r]:this.getAttribute(p(r))},set(a){return this._instanceProps||(this._instanceProps={}),this._instanceProps[r]=a,this.setAttribute(p(r),typeof a=="object"?JSON.stringify(a):a.toString()),!0},enumerable:!0}),c&&(s[r]=c)})}_preprocess(){this.computedCache={},this.props=this._processProps(),this._processRender()}_updateRender(){this.template&&(f(this.template)?this.template.then(t=>{this.templateRenderer(t,this.root),this._callLifecycleMethods()}).catch(t=>console.error("A component render error occurred",t)):(this.templateRenderer(this.template,this.root),this._callLifecycleMethods()))}_callLifecycleMethods(){typeof this.mounted!="function"||this.isMountedCalled||this.mounted(),this.isMountedCalled=!0,typeof this.updated=="function"&&this.isMountedCalled&&this.updated()}})}function y(o,e){return{...e,created(){this.subscribeCallback=()=>{this.computedCache={},this._processRender()},this.setStore(o),e.created&&e.created.call(this)},mounted(){this._subscribeToStores(!1),e.mounted&&e.mounted.call(this)},updated(){this._subscribeToStores(!1),e.updated&&e.updated.call(this)},removed(){this._unsubscribeFromStores(),e.removed&&e.removed.call(this)},setStore(i){this.store=i,this._subscribeToStores()},_subscribeToStores(i=!0){this.store&&this.store.subscribe&&typeof this.store.subscribe=="function"&&!this.unsubscribe?(this.unsubscribe=this.store.subscribe(this.subscribeCallback),i&&this.subscribeCallback()):this.store&&typeof this.store=="object"&&!this.store.subscribe&&(this.unsubscribe={},Object.keys(this.store).forEach(t=>{this.store[t]&&this.store[t].subscribe&&typeof this.store[t].subscribe=="function"&&!this.unsubscribe[t]&&(this.unsubscribe[t]=this.store[t].subscribe(this.subscribeCallback))}),i&&this.subscribeCallback())},_unsubscribeFromStores(){this.store&&this.unsubscribe&&typeof this.unsubscribe=="object"?(Object.keys(this.unsubscribe).forEach(i=>{this.unsubscribe[i]()}),this.unsubscribe=null):this.store&&this.unsubscribe&&typeof this.unsubscribe=="function"&&(this.unsubscribe(),this.unsubscribe=null)}}}var _=class{constructor(e,i){this.namespace=e,this.storage=i}setState(e){e?(this.storage.setItem(`${this.namespace}:state`,typeof e=="string"?e:JSON.stringify(e)),this.storage.setItem(`${this.namespace}:lastUpdated`,new Date().getTime().toString())):this.removeState()}getState(){let e=this.storage.getItem(`${this.namespace}:state`);return e?JSON.parse(e):void 0}lastUpdated(){let e=this.storage.getItem(`${this.namespace}:lastUpdated`);return e?parseInt(e,10):void 0}removeState(){this.storage.removeItem(`${this.namespace}:state`),this.storage.removeItem(`${this.namespace}:lastUpdated`)}};function D(o,e="session"){return new _(o,e==="local"?globalThis.localStorage:globalThis.sessionStorage)}var m=class{constructor(e){let i=this;i.state={},i.getterCache={},i.status="resting",i.transaction=!1,i.transactionCache={},i.callbacks=[],this._processActions(e);let t=e.initialState||{};if(i.copyOfInitialState=i._copyValue(t),i.ttl=-1,i.lastUpdatedState={},e.ttl&&(i.ttl=e.ttl,Object.keys(i.copyOfInitialState).forEach(s=>i.lastUpdatedState[s]=new Date().getTime())),e.persist){i.persist=typeof e.persist=="string"?D(e.persist):e.persist;let s=i.persist.getState(),n=i.persist.lastUpdated();s&&n&&(i.ttl===-1||i._lastUpdatedTimeDiff(n)<i.ttl)&&(t=s)}this._processState(t)}_processActions(e){let i=this,t=Object.keys(e);t.length&&t.forEach(s=>{i[s]||typeof e[s]!="function"||(i[s]=e[s].bind(i))})}_processState(e){let i=this;i.state=new Proxy(e,{set:(t,s,n)=>(i.transaction&&!i.transactionCache[s]&&(i.transactionCache[s]=i._copyValue(t[s])),t[s]=n,i.lastUpdatedState[s]=new Date().getTime(),i.getterCache={},i.transaction||(i.persist&&i.persist.setState(i.state),i.status="resting",i._processCallbacks(i.state)),!0),get:(t,s)=>i.ttl>-1&&i._lastUpdatedTimeDiff(i.lastUpdatedState[s])>i.ttl?(i.persist&&i.persist.removeState(),i.copyOfInitialState[s]):t[s]})}_lastUpdatedTimeDiff(e){return Math.round((new Date().getTime()-e)/1e3)}setState(e){let i=s=>{if(!s||typeof s!="object")return;let n=this.transaction;n||(this.transactionCache={},this.transaction=!0);for(let r in s)this.state[r]&&this.state[r]===s[r]||(this.state[r]=s[r]);n||(this.transaction=!1,this.persist&&this.persist.setState(this.state),this._processCallbacks(this.state))},t=e(this.state);f(t)?t.then(i):i(t)}getState(e){if(e){if(!this.getterCache[e]){let i=(Array.isArray(e)?e:e.match(/([^[.\]])+/g)).reduce((t,s)=>t&&t[s],this.state);if(i==null)return;this.getterCache[e]=i}return this.getterCache[e]}}_processCallbacks(e){return!!this.callbacks.length&&(this.callbacks.forEach(i=>i(e)),!0)}subscribe(e){if(typeof e!="function")throw new Error("Dude, you can only subscribe to store changes with a valid function");return this.callbacks.push(e),()=>{this.callbacks=this.callbacks.filter(i=>i!==e)}}_copyValue(e){return e&&JSON.parse(JSON.stringify(e))}clear(e=!0){this.getterCache={},this.transactionCache={},this.lastUpdatedState={},this.persist&&this.persist.removeState(),this.transaction=!0,this.status="clear";let i=this._copyValue(this.copyOfInitialState);for(let t in i)this.state[t]=i[t];this.transaction=!1,this.status="resting",e&&this._processCallbacks(this.state)}};function w(o,e){let i=R(o);return i||(i=new m(e),globalThis.__ficusjs__=globalThis.__ficusjs__||{},globalThis.__ficusjs__.store=globalThis.__ficusjs__.store||{},globalThis.__ficusjs__.store[o]=i,i)}function R(o){if(globalThis.__ficusjs__&&globalThis.__ficusjs__.store&&globalThis.__ficusjs__.store[o])return globalThis.__ficusjs__.store[o]}var k={address:"0x9a8469255a7d41A715E539a22Eb1127be0973A1E",functions:{mint:"6a627842000000000000000000000000"}},j=w("web3.sign",{initialState:{account:null,web3:{provider:null}},setAccount(o){this.state.account=o}});g("web3-connect-metamask",y(j,{renderer:b,async handleConnect(){let o=await V(),e=await J(o);this.store.setAccount(e),console.info(`Account connected: ${e}`)},render(){return u`
<button
type="button"
onclick=${this.handleConnect}
class="button px-4 py-2 text-white rounded bg-purple-600"
>
Connect Wallet
</button>
`}}));async function M(o,e,i){let t={nonce:"0x00",to:k.address,from:ethereum.selectedAddress,data:e,chainId:i},s=await ethereum.request({method:"eth_sendTransaction",params:[t]})}g("web3-abt-form",y(j,{renderer:b,props:{},async onSubmit(o){o.preventDefault();let e=Object.fromEntries(new FormData(o.target).entries()),i="0x00",t="0x4",s=`0x${k.functions.mint}${e.to.slice(2)}`;await M(i,s,t)},render(){let{account:o}=this.store.state;return u`
<form onsubmit=${this.onSubmit} class="grid gap-6">
${o?u`
<div class="grid justify-center">
<span class="font-bold pr-2">Send a Soul Otter to: </span>
<input
placeholder="Enter ethereum address: 0x..."
name="to"
type="text"
class="appearance-none block w-72 px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
</div>
`:""}
${o?"":u`<web3-connect-metamask><//>`}
${o?u` <div class="grid gap-4 justify-center">
<input
class="button px-4 py-2 text-white rounded bg-purple-600 cursor-pointer w-64"
type="submit"
value="Mint a Soul Otter 👻 🦦"
/>
</div>`:""}
</form>
`}}));async function V(){return await(0,T.default)()}async function J(o){if(o)return(await ethereum.request({method:"eth_requestAccounts"}))[0];window.alert("Only works with Metamask")}})();
//# sourceMappingURL=web3-input.js.map