-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
217 lines (179 loc) · 5.97 KB
/
index.tsx
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
import * as React from 'react';
import { useEffect, useState } from 'react';
import styles from "./dashboard.scss";
import { useNavigate, useLocation } from "react-router-dom";
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import DropDown from "../DropDown";
import * as waxjs from "@waxio/waxjs/dist";
import AnchorLink from 'anchor-link';
import AnchorLinkBrowserTransport from 'anchor-link-browser-transport';
import { headerLinkData } from "../../config/constant";
import './style.css';
export interface NFTShow {
setWalletSession: any,
Account: any,
setAccount: any,
userBalance: any,
loginFlag: any,
depositAssets: any,
}
// testnet endpoint - https://waxtestnet.greymass.com
// chainID - f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12
export default function MiddleAppBar({ setWalletSession, Account, setAccount, userBalance, loginFlag, depositAssets }: NFTShow) {
let wallet_session:any;
const navigate = useNavigate();
const location = useLocation();
let totalNFTs: any = [];
const pages = ['Inventory', 'Characters', 'Buildings', 'Leaderboard', 'Daily Winners', 'Open Packs', 'Stake Assets'];
const [headerActive, setHeaderActive] = useState(headerLinkData.characters);
const endpoint = "https://waxtestnet.greymass.com";
const chainID = "f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12";
let display_nft = false;
let loggedIn = false;
const schema = "characters";
const identifier = 'main'
const [showDropDown, setShowDropDown] = useState<boolean>(false);
const [selectCity, setSelectCity] = useState<string>("");
// using anchor for testnet
let walletType = "Anchor";
const wax = new waxjs.WaxJS({
rpcEndpoint: endpoint
});
const main = async () => {
if (loggedIn) {
} else
await autoLogin();
}
const autoLogin = async () => {
let isAutoLoginAvailable = await wax.isAutoLoginAvailable();
if (isAutoLoginAvailable) {
setAccount(wax.userAccount);
let pubKeys = wax.pubKeys;
let str = 'User: ' + wax.userAccount;
console.log(str);
loggedIn = true;
await main();
}
}
const login = async () => {
try {
if (!loggedIn) {
let wallet1_userAccount = await wallet_login();
setAccount(wallet1_userAccount);
loggedIn = true;
let depositassets = await GetAssets(wallet1_userAccount);
let isWork = await wax.rpc
.get_currency_userBalance("eosio.token", Account, "wax")
.then((res) => {
return true;
})
.catch((err) => {
console.log("err", err);
return false;
});
}
} catch (e) {
}
}
const dapp = "stakingdapp";
async function wallet_login() {
var wallet_Account;
const transport = new AnchorLinkBrowserTransport();
const anchorLink = new AnchorLink({
transport,
chains: [{
chainId: chainID,
nodeUrl: endpoint,
}],
});
if (walletType == "Anchor") {
var sessionList = await anchorLink.listSessions(dapp);
if (sessionList && sessionList.length > 0) {
wallet_session = await anchorLink.restoreSession(dapp);
} else {
wallet_session = (await anchorLink.login(dapp)).session;
}
wallet_Account = String(wallet_session.auth).split("@")[0];
let auth = String(wallet_session.auth).split("@")[1];
let anchorAuth = auth;
} else {
wallet_Account = await wax.login();
wallet_session = wax.api;
let anchorAuth = "active";
}
setWalletSession(wallet_session);
return wallet_Account;
}
// getting assets through atomicassets testnet api
const GetAssets = async (account:any) => {
let results = [];
var path = "atomicassets/v1/assets?owner=" + account + "&page=1&limit=1000&order=desc&sort=asset_id";
const response = await fetch("https://" + "test.wax.api.atomicassets.io/" + path, {
headers: {
"Content-Type": "text/plain"
},
method: "POST",
});
const body = await response.json();
if (body.data.length != 0)
results = body.data;
console.log('responsive = = = = =', results);
depositAssets(results);
return results;
}
const logout = async () => {
loggedIn = false;
display_nft = false;
setAccount("");
}
const onClickLogin = () => {
login();
}
const loginClick = () => {
navigate("/manage-wallet");
}
const tokenStyle = {
backgroundImage: `url('../../background.jpg')`,
width: '60px',
height: '60px',
backgroundSize: "100%",
marginRight:"8px",
marginLeft:"8px",
}
const loginBtnStyle = {
backgroundColor: '#2edada',
color: '#189648',
paddingLeft: "30px",
paddingRight: "30px",
fontWeight: 500,
fontSize: "1.4rem",
borderRadius: "10px",
padding: '16px',
}
return (
<Box className = "Navbar" sx={{ flexGrow: 1 }} style={{ position: "sticky", top: 0, zIndex: "100" }}>
<AppBar position="static">
<Toolbar sx = {{justifyContent: "space-between" }}>
<Typography className="logo" variant="h6" component="div" >
<div className="logo-main" >
<h1>Decentralized Application Logo</h1>
</div>
</Typography>
<Box sx={{ display: { xs: 'flex', md: 'flex' }, marginLeft: 3, }}>
<button
className={showDropDown ? "active" : undefined}
onClick={onClickLogin}
style={loginBtnStyle}
>
{Account!=""?Account:"Login"}
</button>
</Box>
</Toolbar>
</AppBar>
</Box>
);
}