|
- {"version":3,"sources":["components/ConnectWallet.tsx","components/DisconnectWallet.tsx","config.ts","components/BuyButton.tsx","App.tsx","serviceWorker.js","index.js"],"names":["ConnectButton","Tezos","setWallet","setContract","setUserAddress","setUserBalance","setBeaconConnection","setStorage","setPublicToken","wallet","useState","loadingNano","setLoadingNano","setup","userAddress","a","tz","getBalance","balance","toNumber","connectWallet","requestPermissions","network","type","NetworkType","MAINNET","rpcUrl","getPKH","console","log","connectNano","TransportU2F","create","transport","ledgerSigner","LedgerSigner","setSignerProvider","signer","publicKeyHash","useEffect","BeaconWallet","name","preferredNetwork","disableDefaultEvents","eventHandlers","BeaconEvent","PAIR_INIT","handler","defaultEventCallbacks","PAIR_SUCCESS","data","publicKey","setWalletProvider","client","getActiveAccount","className","onClick","disabled","DisconnectButton","disconnectWallet","removeAllAccounts","removeAllPeers","destroy","config","defaultTezPrice","last_updated_at","usd","usd_24h_change","usd_24h_vol","usd_market_cap","defaultTokenPrice","storageLimitSurcharge","lpTokenDecimals","FLORENCENET","CUSTOM","ButtonState","BeaconConnection","BuyButton","FA2address","swapContract","sender","receiver","amountUsd","redirectSuccess","tezUsd","setTezUsd","tezPool","setTezPool","tokenPool","setTokenPool","fiat2Token","setFiat2Token","symbol","decimals","tokenDetails","setTokenDetails","CALCULATING_PRICE","status","setStatus","opHash","setOpHash","tezMultiplyer","tokenMultiplyer","setTokenMultiplyer","initTokenContract","coinContract","at","newContract","storage","newStorage","assets","token_metadata","get","metdata","totalSupply","parseInt","total_supply","bytes2Char","description","thumbnailUri","shouldPreferSymbol","coinContractAddress","error","getTezosPrice","getPoolSizes","READY_TO_PAY","fetch","then","res","json","tezos","item","code","parseFloat","tez_pool","token_pool","buyMethod","makePayment","window","location","href","contract","transfer_params","from_","txs","to_","token_id","amount","Math","round","methods","transfer","send","op","AWAITING_CONFIRMATION","confirmation","App","fa2Contract","setTezos","undefined","publicToken","userBalance","isNaN","id","Boolean","hostname","match","appNodes","document","getElementsByClassName","TezosToolkit","i","length","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10484aec.chunk.js","sourcesContent":["import React, { Dispatch, SetStateAction, useState, useEffect } from \"react\";\nimport { TezosToolkit } from \"@taquito/taquito\";\nimport { BeaconWallet } from \"@taquito/beacon-wallet\";\nimport {\n NetworkType,\n BeaconEvent,\n defaultEventCallbacks\n} from \"@airgap/beacon-sdk\";\nimport TransportU2F from \"@ledgerhq/hw-transport-u2f\";\nimport { LedgerSigner } from \"@taquito/ledger-signer\";\n\ntype ButtonProps = {\n Tezos: TezosToolkit;\n setContract: Dispatch<SetStateAction<any>>;\n setWallet: Dispatch<SetStateAction<any>>;\n setUserAddress: Dispatch<SetStateAction<string>>;\n setUserBalance: Dispatch<SetStateAction<number>>;\n setStorage: Dispatch<SetStateAction<number>>;\n// contractAddress: string;\n setBeaconConnection: Dispatch<SetStateAction<boolean>>;\n setPublicToken: Dispatch<SetStateAction<string | null>>;\n wallet: BeaconWallet;\n};\n\nconst ConnectButton = ({\n Tezos,\n setContract,\n setWallet,\n setUserAddress,\n setUserBalance,\n setStorage,\n// contractAddress,\n setBeaconConnection,\n setPublicToken,\n wallet\n}: ButtonProps): JSX.Element => {\n const [loadingNano, setLoadingNano] = useState<boolean>(false);\n\n const setup = async (userAddress: string): Promise<void> => {\n setUserAddress(userAddress);\n // updates balance\n const balance = await Tezos.tz.getBalance(userAddress);\n setUserBalance(balance.toNumber());\n // creates contract instance\n //const contract = await Tezos.wallet.at(contractAddress);\n //const storage: any = await contract.storage();\n //setContract(contract);\n //setStorage(storage.toNumber());\n };\n\n const connectWallet = async (): Promise<void> => {\n try {\n await wallet.requestPermissions({\n network: {\n type: NetworkType.MAINNET,\n rpcUrl: \"https://mainnet.api.tez.ie/\"\n }\n });\n // gets user's address\n const userAddress = await wallet.getPKH();\n await setup(userAddress);\n setBeaconConnection(true);\n } catch (error) {\n console.log(error);\n }\n };\n\n const connectNano = async (): Promise<void> => {\n try {\n setLoadingNano(true);\n const transport = await TransportU2F.create();\n const ledgerSigner = new LedgerSigner(transport, \"44'/1729'/0'/0'\", true);\n\n Tezos.setSignerProvider(ledgerSigner);\n\n //Get the public key and the public key hash from the Ledger\n const userAddress = await Tezos.signer.publicKeyHash();\n await setup(userAddress);\n } catch (error) {\n console.log(\"Error!\", error);\n setLoadingNano(false);\n }\n };\n\n useEffect(() => {\n (async () => {\n // creates a wallet instance\n const wallet = new BeaconWallet({\n name: \"Taquito Boilerplate\",\n preferredNetwork: NetworkType.MAINNET,\n disableDefaultEvents: true, // Disable all events / UI. This also disables the pairing alert.\n eventHandlers: {\n // To keep the pairing alert, we have to add the following default event handlers back\n [BeaconEvent.PAIR_INIT]: {\n handler: defaultEventCallbacks.PAIR_INIT\n },\n [BeaconEvent.PAIR_SUCCESS]: {\n handler: data => setPublicToken(data.publicKey)\n }\n }\n });\n Tezos.setWalletProvider(wallet);\n setWallet(wallet);\n // checks if wallet was connected before\n const activeAccount = await wallet.client.getActiveAccount();\n if (activeAccount) {\n const userAddress = await wallet.getPKH();\n await setup(userAddress);\n setBeaconConnection(true);\n }\n })();\n }, []);\n\n return (\n <div className=\"buttons\">\n <button className=\"button\" onClick={connectWallet}>\n <span>\n <i className=\"fas fa-wallet\"></i> Connect with wallet\n </span>\n </button>\n <button className=\"button\" disabled={loadingNano} onClick={connectNano}>\n {loadingNano ? (\n <span>\n <i className=\"fas fa-spinner fa-spin\"></i> Loading, please\n wait\n </span>\n ) : (\n <span>\n <i className=\"fab fa-usb\"></i> Connect with Ledger Nano\n </span>\n )}\n </button>\n </div>\n );\n};\n\nexport default ConnectButton;\n","import React, { Dispatch, SetStateAction } from \"react\";\nimport { BeaconWallet } from \"@taquito/beacon-wallet\";\nimport { TezosToolkit } from \"@taquito/taquito\";\n\ninterface ButtonProps {\n wallet: BeaconWallet | null;\n setPublicToken: Dispatch<SetStateAction<string | null>>;\n setUserAddress: Dispatch<SetStateAction<string>>;\n setUserBalance: Dispatch<SetStateAction<number>>;\n setWallet: Dispatch<SetStateAction<any>>;\n //setTezos: Dispatch<SetStateAction<TezosToolkit>>;\n setBeaconConnection: Dispatch<SetStateAction<boolean>>;\n}\n\nconst DisconnectButton = ({\n wallet,\n setPublicToken,\n setUserAddress,\n setUserBalance,\n setWallet,\n //setTezos,\n setBeaconConnection\n}: ButtonProps): JSX.Element => {\n const disconnectWallet = async (): Promise<void> => {\n //window.localStorage.clear();\n setUserAddress(\"\");\n setUserBalance(0);\n setWallet(null);\n //const tezosTK = new TezosToolkit(\"https://api.tez.ie/rpc/granadanet\");\n //setTezos(tezosTK);\n setBeaconConnection(false);\n setPublicToken(null);\n console.log(\"disconnecting wallet\");\n if (wallet) {\n await wallet.client.removeAllAccounts();\n await wallet.client.removeAllPeers();\n await wallet.client.destroy();\n }\n };\n\n return (\n <div className=\"buttons\">\n <button className=\"button\" onClick={disconnectWallet}>\n <i className=\"fas fa-times\"></i> Disconnect wallet\n </button>\n </div>\n );\n};\n\nexport default DisconnectButton;\n","import { NetworkType } from \"@airgap/beacon-sdk\";\n\nconst config = {\n network: NetworkType.MAINNET,\n rpcUrl: \"\",\n defaultTezPrice: {\n last_updated_at: 1621264908,\n usd: 5.24,\n usd_24h_change: -10.701803732742505,\n usd_24h_vol: 410319278.74019855,\n usd_market_cap: 4367588701.058423,\n },\n defaultTokenPrice: {\n last_updated_at: 1621264908,\n usd: 0.0,\n usd_24h_change: 0,\n usd_24h_vol: 0,\n usd_market_cap: 0,\n },\n storageLimitSurcharge: 1.2, // multiplier\n lpTokenDecimals: 1000000\n};\n\nswitch (config.network) {\n case NetworkType.MAINNET:\n config.rpcUrl = \"https://mainnet.api.tez.ie\";\n break;\n case NetworkType.FLORENCENET:\n config.rpcUrl = \"https://rpc.florence.tzstats.com/\";\n break;\n case NetworkType.CUSTOM:\n config.rpcUrl = \"http://localhost:8732/\";\n break;\n}\n\nexport default config;\n","import React, { Dispatch, SetStateAction, useState, useEffect } from \"react\";\n\nimport { TezosToolkit } from \"@taquito/taquito\";\nimport { BeaconWallet } from \"@taquito/beacon-wallet\";\nimport { bytes2Char } from '@taquito/utils';\n\n\nimport config from \"./../config\";\n\n\ninterface BuyButtonProps {\n Tezos: TezosToolkit,\n FA2address: string,\n swapContract: string,\n sender: string,\n receiver: string,\n amountUsd: number,\n redirectSuccess: string\n}\n\ninterface CoinGeckoPrice {\n last_updated_at: number;\n usd: number;\n usd_24h_change: number;\n usd_24h_vol: number;\n usd_market_cap: number;\n}\n\nenum ButtonState {\n CALCULATING_PRICE,\n READY_TO_PAY,\n AWAITING_CONFIRMATION\n}\n\n// interface TokenDetails {\n// \n// }\n\nconst BuyButton = ({\n Tezos,\n FA2address,\n swapContract,\n sender,\n receiver,\n amountUsd,\n redirectSuccess\n}: BuyButtonProps ): JSX.Element => {\n \n const [tezUsd, setTezUsd] = useState<CoinGeckoPrice>(config.defaultTezPrice);\n const [tezPool, setTezPool] = useState<number>(0);\n const [tokenPool, setTokenPool] = useState<number>(0);\n const [fiat2Token, setFiat2Token] = useState<number>(0);\n const [tokenDetails, setTokenDetails] = useState<any>({\n symbol:\"\",\n decimals:6\n });\n const [status, setStatus] = useState<ButtonState>(ButtonState.CALCULATING_PRICE);\n const [opHash, setOpHash] = useState<string>(\"\");\n const tezMultiplyer = 10 ** 6;\n const [tokenMultiplyer, setTokenMultiplyer] = useState<number>(10 ** 6);\n\n \n async function initTokenContract(coinContract:string) {\n try {\n const newContract = await Tezos.wallet.at(coinContract);\n const newStorage: any = await newContract.storage();\n const metdata: any = await newStorage.assets.token_metadata.get(0);\n console.log(metdata);\n const tokenDetails = {\n totalSupply: parseInt(newStorage.assets.total_supply),\n name: bytes2Char(metdata['token_info'].get('name')),\n symbol: bytes2Char(metdata['token_info'].get('symbol')),\n description: bytes2Char(metdata['token_info'].get('description')),\n thumbnailUri: bytes2Char(metdata['token_info'].get('thumbnailUri')),\n decimals: parseInt(bytes2Char(metdata['token_info'].get('decimals'))),\n shouldPreferSymbol: bytes2Char(metdata['token_info'].get('shouldPreferSymbol')) === 'true',\n coinContractAddress: coinContract,\n swapContract: swapContract,\n }\n setTokenMultiplyer(10 ** tokenDetails.decimals)\n setTokenDetails(tokenDetails)\n } catch (e) {\n console.error(e)\n }\n }\n \n useEffect(() => {\n (async () => {\n await initTokenContract(FA2address);\n })();\n },[])\n \n useEffect(() => {\n getTezosPrice();\n getPoolSizes();\n }, [tokenDetails])\n \n // calculate Price in Token\n useEffect(() => {\n if( tezUsd.usd > 0 &&\n tezPool > 0 &&\n tokenPool > 0 ) {\n setFiat2Token( tokenPool / tezPool / tezUsd.usd);\n if (status<ButtonState.READY_TO_PAY) {\n setStatus(ButtonState.READY_TO_PAY);\n }\n } else {\n \n }\n \n })\n \n const getTezosPrice = async (): Promise<void> => {\n // https://www.coingecko.com/en/api#explore-api\n 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\")\n .then(res => res.json())\n .then(res => setTezUsd(res.tezos))\n }\n \n const getPoolSizes = async (): Promise<void> => {\n \n fetch(\"https://api.tzkt.io/v1/contracts/\"+tokenDetails.swapContract+\"/storage\")\n .then(res => res.json())\n .then(item => {\n if (item.code == 400) { } else {\n setTezPool( parseFloat(item.storage.tez_pool) / tezMultiplyer);\n setTokenPool( parseFloat(item.storage.token_pool) / tokenMultiplyer);\n //console.log(tokenPool + \" -- \" + parseFloat(item.storage.token_pool)) \n }\n }\n )\n }\n \n const buyMethod = async (): Promise<void> => {\n makePayment().then(\n ()=>window.location.href = redirectSuccess,\n ()=>console.log(\"something went wrong\")\n );\n }\n \n const makePayment = async (): Promise<void> => {\n\tconst contract = await Tezos.wallet.at(FA2address);\n const transfer_params = [\n {\n from_: sender,\n txs: [{\n to_: receiver,\n token_id:0,\n amount: Math.round(amountUsd * fiat2Token * tokenMultiplyer)\n }]\n }\n ];\n \n \n const op = await contract.methods.transfer(transfer_params).send()\n .then((op)=>{\n setOpHash(op.opHash);\n setStatus(ButtonState.AWAITING_CONFIRMATION);\n op.confirmation(); \n });\n }\n \n return (<div className=\"freaPay\"><div className=\"info\">\n {status === ButtonState.CALCULATING_PRICE && <span>calculating price</span>}\n {status === ButtonState.READY_TO_PAY && <span>{amountUsd} USD = {amountUsd * fiat2Token} {tokenDetails.symbol}</span>}\n {status === ButtonState.AWAITING_CONFIRMATION && <span>waiting for confirmation of transaction hash {opHash}</span>}\n </div>\n {status === ButtonState.READY_TO_PAY && \n <button \n className=\"button pay-button\"\n onClick={buyMethod}>Pay\n </button>\n }\n </div>);\n \n// if (status == ButtonState.READY_TO_PAY) {\n// return (<div className=\"freaPay\"><div className=\"info\">{amountUsd} USD = {amountUsd * fiat2Token} {tokenDetails.symbol}</div>\n// <div className=\"buttons\">\n// \n// \n// <button\n// \tclassName=\"button pay-button\"\n// \tonClick={buyMethod}\n// \t >Pay {amountUsd * fiat2Token} {tokenDetails.symbol}\n// </button>\n// </div></div>\n// );\n// } else if (status == ButtonState.CALCULATING_PRICE) {\n// return (<div> calculating price</div>);\n// } else if (status == ButtonState.AWAITING_CONFIRMATION) {\n// return (<div>waiting for confirmation</div>);\n// } else return (<div>an error has occured...</div>);\n};\n\nexport default BuyButton; \n","import React, { useState, useEffect } from \"react\";\nimport { TezosToolkit } from \"@taquito/taquito\";\n\n\nimport \"./App.css\";\nimport ConnectButton from \"./components/ConnectWallet\";\nimport DisconnectButton from \"./components/DisconnectWallet\";\nimport qrcode from \"qrcode-generator\";\nimport UpdateContract from \"./components/UpdateContract\";\nimport Transfers from \"./components/Transfers\";\nimport BuyButton from \"./components/BuyButton\";\n\nenum BeaconConnection {\n NONE = \"\",\n LISTENING = \"Listening to P2P channel\",\n CONNECTED = \"Channel connected\",\n PERMISSION_REQUEST_SENT = \"Permission request sent, waiting for response\",\n PERMISSION_REQUEST_SUCCESS = \"Wallet is connected\"\n}\n\ntype AppProps = {\n swapContract: string,\n fa2Contract: string,\n receiver: string,\n amount: number,\n Tezos: TezosToolkit\n setTezos: any, \n redirectSuccess: string\n}\n\nconst App = ({\n swapContract,\n fa2Contract,\n receiver,\n amount,\n Tezos,\n setTezos,\n redirectSuccess\n}: AppProps) => {\n \n const [contract, setContract] = useState<any>(undefined);\n const [publicToken, setPublicToken] = useState<string | null>(\"\");\n const [wallet, setWallet] = useState<any>(null);\n const [userAddress, setUserAddress] = useState<string>(\"\");\n const [userBalance, setUserBalance] = useState<number>(0);\n const [storage, setStorage] = useState<number>(0);\n const [copiedPublicToken, setCopiedPublicToken] = useState<boolean>(false);\n const [beaconConnection, setBeaconConnection] = useState<boolean>(false);\n\n \n const generateQrCode = (): { __html: string } => {\n const qr = qrcode(0, \"L\");\n qr.addData(publicToken || \"\");\n qr.make();\n\n return { __html: qr.createImgTag(4) };\n };\n \n\n\n if (publicToken && (!userAddress || isNaN(userBalance))) {\n return (\n <div className=\"main-box\">\nconnecting\n </div>\n );\n } else if (userAddress && !isNaN(userBalance)) {\n return (\n <div className=\"main-box\">\n\n\n <div id=\"dialog\">\n <BuyButton\n Tezos={Tezos}\n sender={userAddress}\n FA2address={fa2Contract}\n swapContract={swapContract}\n receiver={receiver}\n amountUsd={amount}\n redirectSuccess={redirectSuccess}\n />\n <DisconnectButton \n wallet={wallet}\n setPublicToken={setPublicToken}\n setUserAddress={setUserAddress}\n setWallet={setWallet}\n setBeaconConnection={setBeaconConnection}\n setUserBalance={setUserBalance}\n />\n </div>\n </div>\n );\n } else if (!publicToken && !userAddress && !userBalance) {\n return (\n <div className=\"main-box\">\n <div id=\"dialog\">\n <ConnectButton\n Tezos={Tezos}\n setContract={setContract}\n setPublicToken={setPublicToken}\n setWallet={setWallet}\n setUserAddress={setUserAddress}\n setUserBalance={setUserBalance}\n setStorage={setStorage}\n// contractAddress={contractAddress}\n setBeaconConnection={setBeaconConnection}\n wallet={wallet}\n />\n </div>\n </div>\n );\n } else {\n return <div>An error has occurred</div>;\n }\n};\n\nexport default App;\n","// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on subsequent visits to a page, after all the\n// existing tabs open on the page have been closed, since previously cached\n// resources are updated in the background.\n\n// To learn more about the benefits of this model and instructions on how to\n// opt-in, read https://bit.ly/CRA-PWA\n\nconst isLocalhost = Boolean(\n window.location.hostname === 'localhost' ||\n // [::1] is the IPv6 localhost address.\n window.location.hostname === '[::1]' ||\n // 127.0.0.0/8 are considered localhost for IPv4.\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\n\nexport function register(config) {\n if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n // The URL constructor is available in all browsers that support SW.\n const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);\n if (publicUrl.origin !== window.location.origin) {\n // Our service worker won't work if PUBLIC_URL is on a different origin\n // from what our page is served on. This might happen if a CDN is used to\n // serve assets; see https://github.com/facebook/create-react-app/issues/2374\n return;\n }\n\n window.addEventListener('load', () => {\n const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n if (isLocalhost) {\n // This is running on localhost. Let's check if a service worker still exists or not.\n checkValidServiceWorker(swUrl, config);\n\n // Add some additional logging to localhost, pointing developers to the\n // service worker/PWA documentation.\n navigator.serviceWorker.ready.then(() => {\n console.log(\n 'This web app is being served cache-first by a service ' +\n 'worker. To learn more, visit https://bit.ly/CRA-PWA'\n );\n });\n } else {\n // Is not localhost. Just register service worker\n registerValidSW(swUrl, config);\n }\n });\n }\n}\n\nfunction registerValidSW(swUrl, config) {\n navigator.serviceWorker\n .register(swUrl)\n .then(registration => {\n registration.onupdatefound = () => {\n const installingWorker = registration.installing;\n if (installingWorker == null) {\n return;\n }\n installingWorker.onstatechange = () => {\n if (installingWorker.state === 'installed') {\n if (navigator.serviceWorker.controller) {\n // At this point, the updated precached content has been fetched,\n // but the previous service worker will still serve the older\n // content until all client tabs are closed.\n console.log(\n 'New content is available and will be used when all ' +\n 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\n );\n\n // Execute callback\n if (config && config.onUpdate) {\n config.onUpdate(registration);\n }\n } else {\n // At this point, everything has been precached.\n // It's the perfect time to display a\n // \"Content is cached for offline use.\" message.\n console.log('Content is cached for offline use.');\n\n // Execute callback\n if (config && config.onSuccess) {\n config.onSuccess(registration);\n }\n }\n }\n };\n };\n })\n .catch(error => {\n console.error('Error during service worker registration:', error);\n });\n}\n\nfunction checkValidServiceWorker(swUrl, config) {\n // Check if the service worker can be found. If it can't reload the page.\n fetch(swUrl, {\n headers: { 'Service-Worker': 'script' },\n })\n .then(response => {\n // Ensure service worker exists, and that we really are getting a JS file.\n const contentType = response.headers.get('content-type');\n if (\n response.status === 404 ||\n (contentType != null && contentType.indexOf('javascript') === -1)\n ) {\n // No service worker found. Probably a different app. Reload the page.\n navigator.serviceWorker.ready.then(registration => {\n registration.unregister().then(() => {\n window.location.reload();\n });\n });\n } else {\n // Service worker found. Proceed as normal.\n registerValidSW(swUrl, config);\n }\n })\n .catch(() => {\n console.log(\n 'No internet connection found. App is running in offline mode.'\n );\n });\n}\n\nexport function unregister() {\n if ('serviceWorker' in navigator) {\n navigator.serviceWorker.ready\n .then(registration => {\n registration.unregister();\n })\n .catch(error => {\n console.error(error.message);\n });\n }\n}\n","import React, {useState} from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App from \"./App.tsx\";\nimport * as serviceWorker from \"./serviceWorker\";\n\nimport { TezosToolkit } from \"@taquito/taquito\";\nimport { BeaconWallet } from \"@taquito/beacon-wallet\";\nimport {\n NetworkType,\n BeaconEvent,\n defaultEventCallbacks\n} from \"@airgap/beacon-sdk\";\n\n\nconst appNodes = document.getElementsByClassName(\"pay-button\");\n\nfunction setPublicToken(pubKey) {\n console.log(\"successfully connected to \"+pubKey);\n}\n\nif (appNodes) {\n// const [Tezos, setTezos] = useState<TezosToolkit>(\n// new TezosToolkit(\"https://mainnet.api.tez.ie/\")\n// );\n const Tezos = new TezosToolkit(\"https://mainnet.api.tez.ie/\");\n// const wallet = new BeaconWallet({\n// name: \"freaPay\",\n// preferredNetwork: NetworkType.MAINNET,\n// disableDefaultEvents: true, // Disable all events / UI. This also disables the pairing alert.\n// eventHandlers: {\n// // To keep the pairing alert, we have to add the following default event handlers back\n// [BeaconEvent.PAIR_INIT]: {\n// handler: defaultEventCallbacks.PAIR_INIT\n// },\n// [BeaconEvent.PAIR_SUCCESS]: {\n// handler: data => setPublicToken(data.publicKey)\n// }\n// }\n// });\n\n for (var i = 0; i<appNodes.length; i++) {\n let appNode = appNodes[i];\n \n ReactDOM.render(\n <React.StrictMode>\n <App \n swapContract={appNode.dataset.swapContract}\n fa2Contract={appNode.dataset.fa2Contract}\n receiver={appNode.dataset.receiver}\n amount={appNode.dataset.amount}\n redirectSuccess={appNode.dataset.redirectSuccess}\n Tezos={Tezos}\n \n />\n </React.StrictMode>,\n appNode\n //document.getElementsByClassName(\"c\")\n );\n }\n}\n\n// If you want your app to work offline and load faster, you can change\n// unregister() to register() below. Note this comes with some pitfalls.\n// Learn more about service workers: https://bit.ly/CRA-PWA\n//serviceWorker.unregister();\n"],"sourceRoot":""}
|