소스 검색

expose essential variables to be set via html attribute

master
Dom SP 3 년 전
부모
커밋
3442c2cd07
3개의 변경된 파일48개의 추가작업 그리고 47개의 파일을 삭제
  1. +5
    -1
      public/index.html
  2. +19
    -44
      src/App.tsx
  3. +24
    -2
      src/components/BuyButton.tsx

+ 5
- 1
public/index.html 파일 보기

@@ -19,7 +19,11 @@
</head>
<body>
<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.
If you open it directly in the browser, you will see an empty page.

+ 19
- 44
src/App.tsx 파일 보기

@@ -16,7 +16,19 @@ enum BeaconConnection {
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>(
new TezosToolkit("https://mainnet.api.tez.ie/")
);
@@ -94,7 +106,7 @@ const App = () => {
} else if (userAddress && !isNaN(userBalance)) {
return (
<div className="main-box">
<h1>Taquito Boilerplate</h1>
<div id="tabs">
<div
id="transfer"
@@ -112,23 +124,13 @@ const App = () => {
</div>
</div>
<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
Tezos={Tezos}
sender={userAddress}
FA2address="KT1BB1uMwVvJ1M3vVHXWALs1RWdgTp1rnXTR"
receiver="tz1hJncvXvL2VyctPE685GJPXDaRJ7dtiwjm"
amount={100}
FA2address={fa2Contract}
receiver={receiver}
amount={amount}
/>
<DisconnectButton
wallet={wallet}
@@ -148,36 +150,9 @@ const App = () => {
} else if (!publicToken && !userAddress && !userBalance) {
return (
<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">
<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
Tezos={Tezos}
setContract={setContract}

+ 24
- 2
src/components/BuyButton.tsx 파일 보기

@@ -16,7 +16,29 @@ const BuyButton = ({
receiver: string,
amount: number
}): 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 contract = await Tezos.wallet.at(FA2address);
@@ -39,7 +61,7 @@ const BuyButton = ({
<div className="buttons">
<button
className="myButton"
onClick={makePayment}
onClick={getTokenPrice}
>Transfer {amount}&nbsp;
µ-tokens from: &nbsp;
{sender}

Loading…
취소
저장