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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
import React, { useState } from "react";
import { TezosToolkit } from "@taquito/taquito";
import "./App.css";
import ConnectButton from "./components/ConnectWallet";
import DisconnectButton from "./components/DisconnectWallet";
import qrcode from "qrcode-generator";
import Records from "./components/Records";
import Transfers from "./components/Transfers";
enum BeaconConnection {
NONE = "",
LISTENING = "Listening to P2P channel",
CONNECTED = "Channel connected",
PERMISSION_REQUEST_SENT = "Permission request sent, waiting for response",
PERMISSION_REQUEST_SUCCESS = "Wallet is connected"
}
const App = () => {
const [Tezos, setTezos] = useState<TezosToolkit>(
new TezosToolkit("https://api.tez.ie/rpc/granadanet")
);
const [contract, setContract] = useState<any>(undefined);
const [publicToken, setPublicToken] = useState<string | null>("");
const [wallet, setWallet] = useState<any>(null);
const [userAddress, setUserAddress] = useState<string>("");
const [userBalance, setUserBalance] = useState<number>(0);
const [storage, setStorage] = useState<any>({dates: [], records: [],});
const [copiedPublicToken, setCopiedPublicToken] = useState<boolean>(false);
const [beaconConnection, setBeaconConnection] = useState<boolean>(false);
const [activeTab, setActiveTab] = useState<string>("transfer");
// Granadanet Memoir contract
const contractAddress: string = "KT1XDxSuXHBBtLDZRd2ZpEMYkxgutMc7a6mU";
const generateQrCode = (): { __html: string } => {
const qr = qrcode(0, "L");
qr.addData(publicToken || "");
qr.make();
return { __html: qr.createImgTag(4) };
};
if (publicToken && (!userAddress || isNaN(userBalance))) {
return (
<div className="main-box">
<h1>MyMedMemoir</h1>
<div id="dialog">
<header>Decentralized Medical Reports</header>
<div id="content">
<p className="text-align-center">
<i className="fas fa-broadcast-tower"></i> Connecting to
your wallet
</p>
<div
dangerouslySetInnerHTML={generateQrCode()}
className="text-align-center"
></div>
<p id="public-token">
{copiedPublicToken ? (
<span id="public-token-copy__copied">
<i className="far fa-thumbs-up"></i>
</span>
) : (
<span
id="public-token-copy"
onClick={() => {
if (publicToken) {
navigator.clipboard.writeText(publicToken);
setCopiedPublicToken(true);
setTimeout(() => setCopiedPublicToken(false), 2000);
}
}}
>
<i className="far fa-copy"></i>
</span>
)}
<span>
Public token: <span>{publicToken}</span>
</span>
</p>
<p className="text-align-center">
Status: {beaconConnection ? "Connected" : "Disconnected"}
</p>
</div>
</div>
<div id="footer">
</div>
</div>
);
} else if (userAddress && !isNaN(userBalance)) {
return (
<div className="main-box">
<h1>Memoir</h1>
<div id="tabs">
<div
id="transfer"
className={activeTab === "transfer" ? "active" : ""}
onClick={() => setActiveTab("transfer")}
>
Wallet
</div>
<div
id="contract"
className={activeTab === "contract" ? "active" : ""}
onClick={() => setActiveTab("contract")}
>
New Report
</div>
<div
id="reports"
className={activeTab === "reports" ? "active" : ""}
onClick={() => setActiveTab("reports")}
>
Reports
</div>
</div>
<div id="dialog">
<div id="content">
{activeTab === "transfer" &&
<div id="transfers">
<h3 className="text-align-center">Make a transfer</h3>
<Transfers
Tezos={Tezos}
setUserBalance={setUserBalance}
userAddress={userAddress}
/>
<p>
<i className="far fa-file-code"></i>
<a
href={`https://better-call.dev/granadanet/${contractAddress}/operations`}
target="_blank"
rel="noopener noreferrer"
>
{contractAddress}
</a>
</p>
<p>
<i className="far fa-address-card"></i> {userAddress}
</p>
<p>
<i className="fas fa-piggy-bank"></i>
{(userBalance / 1000000).toLocaleString("en-US")} ꜩ
</p>
<DisconnectButton
wallet={wallet}
setPublicToken={setPublicToken}
setUserAddress={setUserAddress}
setUserBalance={setUserBalance}
setWallet={setWallet}
setTezos={setTezos}
setBeaconConnection={setBeaconConnection}
/>
</div>
}
{activeTab === "contract" &&
<div id="increment-decrement">
<Records
contract={contract}
setUserBalance={setUserBalance}
Tezos={Tezos}
userAddress={userAddress}
setStorage={setStorage}
/>
</div>
}
{activeTab === "reports" &&
<div id="increment-decrement">
{storage.dates.map((val: boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null | undefined, idx: any) =>
<div className="apneReports">
<details>
<summary>
{JSON.parse(storage.records[idx]).date}
</summary>
<b>Name:</b> {JSON.parse(storage.records[idx]).name}<br></br>
<b>Age:</b> {JSON.parse(storage.records[idx]).age}<br></br>
<b>Height:</b> {JSON.parse(storage.records[idx]).height}<br></br>
<b>Weight:</b> {JSON.parse(storage.records[idx]).weight}<br></br>
<b>Prescription:</b> {JSON.parse(storage.records[idx]).prescription}<br></br>
</details>
</div>)}
</div>
}
</div>
</div>
<div id="footer">
</div>
</div>
);
} else if (!publicToken && !userAddress && !userBalance) {
return (
<div className="main-box">
<div className="title">
<h1>MyMedMemoir</h1>
</div>
<div id="dialog">
<header>Welcome to MyMedMemoir!</header>
<div id="content">
<p>Hello!</p>
<p>Go forth and M³!</p>
</div>
<ConnectButton
Tezos={Tezos}
setContract={setContract}
setPublicToken={setPublicToken}
setWallet={setWallet}
setUserAddress={setUserAddress}
setUserBalance={setUserBalance}
setStorage={setStorage}
contractAddress={contractAddress}
setBeaconConnection={setBeaconConnection}
wallet={wallet}
/>
</div>
<div id="footer">
<h1> hi</h1>
<img src="./footer.png"/>
</div>
</div>
);
} else {
return <div>An error has occurred</div>;
}
};
export default App;
|