~Webmodule~ to include a "Buy button" with streamlined crypto-pay transaction.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2 行
11KB

  1. (this["webpackJsonptaquito-boilerplate-react"]=this["webpackJsonptaquito-boilerplate-react"]||[]).push([[0],{115:function(e,t){},198:function(e,t,n){},203:function(e,t){},205:function(e,t){},215:function(e,t){},217:function(e,t){},243:function(e,t){},245:function(e,t){},246:function(e,t){},251:function(e,t){},253:function(e,t){},272:function(e,t){},284:function(e,t){},287:function(e,t){},313:function(e,t){},315:function(e,t){},382:function(e,t,n){"use strict";n.r(t);var a=n(17),c=n.n(a),r=n(187),s=n.n(r),o=n(16),i=(n(198),n(2)),u=n(0),l=n.n(u),p=n(24),d=n(112),f=n(9),b=n(190),j=n(192),O=n(12),h=function(e){var t=e.Tezos,n=(e.setContract,e.setWallet),c=e.setUserAddress,r=e.setUserBalance,s=(e.setStorage,e.setBeaconConnection),u=e.setPublicToken,h=e.wallet,m=Object(a.useState)(!1),v=Object(o.a)(m,2),x=v[0],w=v[1],_=function(){var e=Object(p.a)(l.a.mark((function e(n){var a;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c(n),e.next=3,t.tz.getBalance(n);case 3:a=e.sent,r(a.toNumber());case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),N=function(){var e=Object(p.a)(l.a.mark((function e(){var t;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,h.requestPermissions({network:{type:f.p.MAINNET,rpcUrl:"https://mainnet.api.tez.ie/"}});case 3:return e.next=5,h.getPKH();case 5:return t=e.sent,e.next=8,_(t);case 8:s(!0),e.next=14;break;case 11:e.prev=11,e.t0=e.catch(0),console.log(e.t0);case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(){return e.apply(this,arguments)}}(),A=function(){var e=Object(p.a)(l.a.mark((function e(){var n,a,c;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,w(!0),e.next=4,b.a.create();case 4:return n=e.sent,a=new j.a(n,"44'/1729'/0'/0'",!0),t.setSignerProvider(a),e.next=9,t.signer.publicKeyHash();case 9:return c=e.sent,e.next=12,_(c);case 12:e.next=18;break;case 14:e.prev=14,e.t0=e.catch(0),console.log("Error!",e.t0),w(!1);case 18:case"end":return e.stop()}}),e,null,[[0,14]])})));return function(){return e.apply(this,arguments)}}();return Object(a.useEffect)((function(){Object(p.a)(l.a.mark((function e(){var a,c,r;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c=new d.a({name:"Taquito Boilerplate",preferredNetwork:f.p.MAINNET,disableDefaultEvents:!0,eventHandlers:(a={},Object(i.a)(a,f.e.PAIR_INIT,{handler:f.L.PAIR_INIT}),Object(i.a)(a,f.e.PAIR_SUCCESS,{handler:function(e){return u(e.publicKey)}}),a)}),t.setWalletProvider(c),n(c),e.next=5,c.client.getActiveAccount();case 5:if(!e.sent){e.next=13;break}return e.next=9,c.getPKH();case 9:return r=e.sent,e.next=12,_(r);case 12:s(!0);case 13:case"end":return e.stop()}}),e)})))()}),[]),Object(O.jsxs)("div",{className:"buttons",children:[Object(O.jsx)("button",{className:"button",onClick:N,children:Object(O.jsxs)("span",{children:[Object(O.jsx)("i",{className:"fas fa-wallet"}),"\xa0 Connect with wallet"]})}),Object(O.jsx)("button",{className:"button",disabled:x,onClick:A,children:x?Object(O.jsxs)("span",{children:[Object(O.jsx)("i",{className:"fas fa-spinner fa-spin"}),"\xa0 Loading, please wait"]}):Object(O.jsxs)("span",{children:[Object(O.jsx)("i",{className:"fab fa-usb"}),"\xa0 Connect with Ledger Nano"]})})]})},m=function(e){var t=e.wallet,n=e.setPublicToken,a=e.setUserAddress,c=e.setUserBalance,r=e.setWallet,s=e.setBeaconConnection,o=function(){var e=Object(p.a)(l.a.mark((function e(){return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a(""),c(0),r(null),s(!1),n(null),console.log("disconnecting wallet"),!t){e.next=13;break}return e.next=9,t.client.removeAllAccounts();case 9:return e.next=11,t.client.removeAllPeers();case 11:return e.next=13,t.client.destroy();case 13:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return Object(O.jsx)("div",{className:"buttons",children:Object(O.jsxs)("button",{className:"button",onClick:o,children:[Object(O.jsx)("i",{className:"fas fa-times"}),"\xa0 Disconnect wallet"]})})},v=(n(78),n(5)),x={network:f.p.MAINNET,rpcUrl:"",defaultTezPrice:{last_updated_at:1621264908,usd:5.24,usd_24h_change:-10.701803732742505,usd_24h_vol:410319278.74019855,usd_market_cap:4367588701.058423},defaultTokenPrice:{last_updated_at:1621264908,usd:0,usd_24h_change:0,usd_24h_vol:0,usd_market_cap:0},storageLimitSurcharge:1.2,lpTokenDecimals:1e6};switch(x.network){case f.p.MAINNET:x.rpcUrl="https://mainnet.api.tez.ie";break;case f.p.FLORENCENET:x.rpcUrl="https://rpc.florence.tzstats.com/";break;case f.p.CUSTOM:x.rpcUrl="http://localhost:8732/"}var w,_=x;!function(e){e[e.CALCULATING_PRICE=0]="CALCULATING_PRICE",e[e.READY_TO_PAY=1]="READY_TO_PAY",e[e.AWAITING_CONFIRMATION=2]="AWAITING_CONFIRMATION"}(w||(w={}));var N,A=function(e){var t=e.Tezos,n=e.FA2address,c=e.swapContract,r=e.sender,s=e.receiver,i=e.amountUsd,u=e.redirectSuccess,d=Object(a.useState)(_.defaultTezPrice),f=Object(o.a)(d,2),b=f[0],j=f[1],h=Object(a.useState)(0),m=Object(o.a)(h,2),x=m[0],N=m[1],A=Object(a.useState)(0),C=Object(o.a)(A,2),k=C[0],T=C[1],S=Object(a.useState)(0),g=Object(o.a)(S,2),I=g[0],E=g[1],P=Object(a.useState)({symbol:"",decimals:6}),y=Object(o.a)(P,2),U=y[0],R=y[1],z=Object(a.useState)(w.CALCULATING_PRICE),M=Object(o.a)(z,2),L=M[0],B=M[1],Y=Object(a.useState)(""),D=Object(o.a)(Y,2),W=D[0],F=D[1],G=Math.pow(10,6),q=Object(a.useState)(Math.pow(10,6)),H=Object(o.a)(q,2),K=H[0],J=H[1];function Q(e){return $.apply(this,arguments)}function $(){return($=Object(p.a)(l.a.mark((function e(n){var a,r,s,o;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.wallet.at(n);case 3:return a=e.sent,e.next=6,a.storage();case 6:return r=e.sent,e.next=9,r.assets.token_metadata.get(0);case 9:s=e.sent,console.log(s),o={totalSupply:parseInt(r.assets.total_supply),name:Object(v.e)(s.token_info.get("name")),symbol:Object(v.e)(s.token_info.get("symbol")),description:Object(v.e)(s.token_info.get("description")),thumbnailUri:Object(v.e)(s.token_info.get("thumbnailUri")),decimals:parseInt(Object(v.e)(s.token_info.get("decimals"))),shouldPreferSymbol:"true"===Object(v.e)(s.token_info.get("shouldPreferSymbol")),coinContractAddress:n,swapContract:c},J(Math.pow(10,o.decimals)),R(o),e.next=19;break;case 16:e.prev=16,e.t0=e.catch(0),console.error(e.t0);case 19:case"end":return e.stop()}}),e,null,[[0,16]])})))).apply(this,arguments)}Object(a.useEffect)((function(){Object(p.a)(l.a.mark((function e(){return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Q(n);case 2:case"end":return e.stop()}}),e)})))()}),[]),Object(a.useEffect)((function(){V(),X()}),[U]),Object(a.useEffect)((function(){b.usd>0&&x>0&&k>0&&(E(k/x/b.usd),L<w.READY_TO_PAY&&B(w.READY_TO_PAY))}));var V=function(){var e=Object(p.a)(l.a.mark((function e(){return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:fetch("https://api.coingecko.com/api/v3/simple/price?ids=tezos&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true").then((function(e){return e.json()})).then((function(e){return j(e.tezos)}));case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),X=function(){var e=Object(p.a)(l.a.mark((function e(){return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:fetch("https://api.tzkt.io/v1/contracts/"+U.swapContract+"/storage").then((function(e){return e.json()})).then((function(e){400==e.code||(N(parseFloat(e.storage.tez_pool)/G),T(parseFloat(e.storage.token_pool)/K))}));case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),Z=function(){var e=Object(p.a)(l.a.mark((function e(){return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:ee().then((function(){return window.location.href=u}),(function(){return console.log("something went wrong")}));case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),ee=function(){var e=Object(p.a)(l.a.mark((function e(){var a,c;return l.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.wallet.at(n);case 2:return a=e.sent,c=[{from_:r,txs:[{to_:s,token_id:0,amount:Math.round(i*I*K)}]}],e.next=6,a.methods.transfer(c).send().then((function(e){F(e.opHash),B(w.AWAITING_CONFIRMATION),e.confirmation()}));case 6:e.sent;case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return Object(O.jsxs)("div",{className:"freaPay",children:[Object(O.jsxs)("div",{className:"info",children:[L===w.CALCULATING_PRICE&&Object(O.jsx)("span",{children:"calculating price"}),L===w.READY_TO_PAY&&Object(O.jsxs)("span",{children:[i," USD = ",i*I," ",U.symbol]}),L===w.AWAITING_CONFIRMATION&&Object(O.jsxs)("span",{children:["waiting for confirmation of transaction hash ",W]})]}),L===w.READY_TO_PAY&&Object(O.jsx)("button",{className:"button pay-button",onClick:Z,children:"Pay"})]})};!function(e){e.NONE="",e.LISTENING="Listening to P2P channel",e.CONNECTED="Channel connected",e.PERMISSION_REQUEST_SENT="Permission request sent, waiting for response",e.PERMISSION_REQUEST_SUCCESS="Wallet is connected"}(N||(N={}));var C=function(e){var t=e.swapContract,n=e.fa2Contract,c=e.receiver,r=e.amount,s=e.Tezos,i=(e.setTezos,e.redirectSuccess),u=Object(a.useState)(void 0),l=Object(o.a)(u,2),p=(l[0],l[1]),d=Object(a.useState)(""),f=Object(o.a)(d,2),b=f[0],j=f[1],v=Object(a.useState)(null),x=Object(o.a)(v,2),w=x[0],_=x[1],N=Object(a.useState)(""),C=Object(o.a)(N,2),k=C[0],T=C[1],S=Object(a.useState)(0),g=Object(o.a)(S,2),I=g[0],E=g[1],P=Object(a.useState)(0),y=Object(o.a)(P,2),U=(y[0],y[1]),R=Object(a.useState)(!1),z=Object(o.a)(R,2),M=(z[0],z[1],Object(a.useState)(!1)),L=Object(o.a)(M,2),B=(L[0],L[1]);return!b||k&&!isNaN(I)?k&&!isNaN(I)?Object(O.jsx)("div",{className:"main-box",children:Object(O.jsxs)("div",{id:"dialog",children:[Object(O.jsx)(A,{Tezos:s,sender:k,FA2address:n,swapContract:t,receiver:c,amountUsd:r,redirectSuccess:i}),Object(O.jsx)(m,{wallet:w,setPublicToken:j,setUserAddress:T,setWallet:_,setBeaconConnection:B,setUserBalance:E})]})}):b||k||I?Object(O.jsx)("div",{children:"An error has occurred"}):Object(O.jsx)("div",{className:"main-box",children:Object(O.jsx)("div",{id:"dialog",children:Object(O.jsx)(h,{Tezos:s,setContract:p,setPublicToken:j,setWallet:_,setUserAddress:T,setUserBalance:E,setStorage:U,setBeaconConnection:B,wallet:w})})}):Object(O.jsx)("div",{className:"main-box",children:"connecting"})};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));var k=n(59),T=document.getElementsByClassName("pay-button");if(T)for(var S=new k.a("https://mainnet.api.tez.ie/"),g=0;g<T.length;g++){var I=T[g];s.a.render(Object(O.jsx)(c.a.StrictMode,{children:Object(O.jsx)(C,{swapContract:I.dataset.swapContract,fa2Contract:I.dataset.fa2Contract,receiver:I.dataset.receiver,amount:I.dataset.amount,redirectSuccess:I.dataset.redirectSuccess,Tezos:S})}),I)}}},[[382,1,2]]]);
  2. //# sourceMappingURL=main.10484aec.chunk.js.map