Browse Source

expose essential variables to be set via html attribute

master
Dom SP 3 years ago
parent
commit
3442c2cd07
3 changed files with 48 additions and 47 deletions
  1. +5
    -1
      public/index.html
  2. +19
    -44
      src/App.tsx
  3. +24
    -2
      src/components/BuyButton.tsx

+ 5
- 1
public/index.html View File

</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="root"
data-fa2-contract="KT1BB1uMwVvJ1M3vVHXWALs1RWdgTp1rnXTR"
data-swap-contract="KT1Ed11bNukFdYSc3qQFZ2HGYdF13XU6WZ4A"
data-receiver="tz1hJncvXvL2VyctPE685GJPXDaRJ7dtiwjm"
data-amount="100"></div>
<!-- <!--
This HTML file is a template. This HTML file is a template.
If you open it directly in the browser, you will see an empty page. If you open it directly in the browser, you will see an empty page.

+ 19
- 44
src/App.tsx View File

PERMISSION_REQUEST_SUCCESS = "Wallet is connected" PERMISSION_REQUEST_SUCCESS = "Wallet is connected"
} }


const App = () => {
interface AppProps {
fa2Contract: string,
swapContract: string,
receiver: string,
amount: number
}

const App = ({
fa2Contract,
swapContract,
receiver,
amount
}: AppProps) => {
const [Tezos, setTezos] = useState<TezosToolkit>( const [Tezos, setTezos] = useState<TezosToolkit>(
new TezosToolkit("https://mainnet.api.tez.ie/") new TezosToolkit("https://mainnet.api.tez.ie/")
); );
} else if (userAddress && !isNaN(userBalance)) { } else if (userAddress && !isNaN(userBalance)) {
return ( return (
<div className="main-box"> <div className="main-box">
<h1>Taquito Boilerplate</h1>
<div id="tabs"> <div id="tabs">
<div <div
id="transfer" id="transfer"
</div> </div>
</div> </div>
<div id="dialog"> <div id="dialog">
<div id="content">



<p>
<i className="far fa-address-card"></i>&nbsp; {userAddress}
</p>
<p>
<i className="fas fa-piggy-bank"></i>&nbsp;
{(userBalance / 1000000).toLocaleString("en-US")} ꜩ
</p>
</div>
<BuyButton <BuyButton
Tezos={Tezos} Tezos={Tezos}
sender={userAddress} sender={userAddress}
FA2address="KT1BB1uMwVvJ1M3vVHXWALs1RWdgTp1rnXTR"
receiver="tz1hJncvXvL2VyctPE685GJPXDaRJ7dtiwjm"
amount={100}
FA2address={fa2Contract}
receiver={receiver}
amount={amount}
/> />
<DisconnectButton <DisconnectButton
wallet={wallet} wallet={wallet}
} else if (!publicToken && !userAddress && !userBalance) { } else if (!publicToken && !userAddress && !userBalance) {
return ( return (
<div className="main-box"> <div className="main-box">
<div className="title">
<h1>Taquito Boilerplate</h1>
<a href="https://app.netlify.com/start/deploy?repository=https://github.com/ecadlabs/taquito-boilerplate">
<img
src="https://www.netlify.com/img/deploy/button.svg"
alt="netlify-button"
/>
</a>
</div>

<div id="dialog"> <div id="dialog">
<header>Welcome to Taquito Boilerplate App!</header>
<div id="content">
<p>Hello!</p>
<p>
This is a template Tezos dApp built using Taquito. It's a starting
point for you to hack on and build your own dApp for Tezos.
<br />
If you have not done so already, go to the{" "}
<a
href="https://github.com/ecadlabs/taquito-boilerplate"
target="_blank"
rel="noopener noreferrer"
>
Taquito boilerplate Github page
</a>{" "}
and click the <em>"Use this template"</em> button.
</p>
<p>Go forth and Tezos!</p>
</div>

<ConnectButton <ConnectButton
Tezos={Tezos} Tezos={Tezos}
setContract={setContract} setContract={setContract}

+ 24
- 2
src/components/BuyButton.tsx View File

receiver: string, receiver: string,
amount: number amount: number
}): JSX.Element => { }): JSX.Element => {

const getTokenPrice = async (): Promise<void> => {
const currency = "USD";
if (currency == "USD") {
const timestamp = new Date();
timestamp.setDate(timestamp.getDate() - 1);
const timestampString = timestamp.toISOString();
fetch(`https://api.tzkt.io/v1/contracts/KT1F3BqwEAoa2koYX4Hz7zJ8xfGSxxAGVT8t/storage/history?limit=700`)
.then(res => res.json())
.then(data => data.find((item: any) => item.timestamp < timestampString))
.then(item => {
if (item && item.value) {
console.log(item) ;
//const tez_pool = parseFloat(item.value.storage.tez_pool) / tezMultiplyer;
//const token_pool = parseFloat(item.value.storage.token_pool) / tokenMultiplyer;
//const price_yesterday = tez_pool / token_pool;
//setTokenTezPriceYesterday(price_yesterday);
}
})
}
}
const makePayment = async (): Promise<void> => { const makePayment = async (): Promise<void> => {
const contract = await Tezos.wallet.at(FA2address); const contract = await Tezos.wallet.at(FA2address);
<div className="buttons"> <div className="buttons">
<button <button
className="myButton" className="myButton"
onClick={makePayment}
onClick={getTokenPrice}
>Transfer {amount}&nbsp; >Transfer {amount}&nbsp;
µ-tokens from: &nbsp; µ-tokens from: &nbsp;
{sender} {sender}

Loading…
Cancel
Save