-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-near.html
162 lines (153 loc) · 6.18 KB
/
test-near.html
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
<!DOCTYPE html>
<html>
<head>
<title>Near Test</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<v-main>
<h1 style="text-align: center; margin: 20px; color: blue;">{{profile.account}}</h1>
<h3 style="text-align: center; margin: 20px; color: brown;">{{profile.balance}} NEAR</h3>
<!-- <h3 style="text-align: center; margin: 20px; color: darkorange;">{{profile.details}}</h3>
<h3 style="text-align: center; margin: 20px; color: darkgreen;">{{profile.accessKeys}}</h3> -->
<div style="text-align:center; margin: 20px;">
<v-btn style="width: 30%; height: 48px; margin: auto; background-color: green; color: white;" @click="Login()">Login</v-btn>
<v-btn style="width: 30%; height: 48px; margin: auto; background-color: red; color: white;" @click="Logout()">Logout</v-btn>
<v-btn style="width: 30%; height: 48px; margin: auto; background-color: blue; color: white;" @click="SendNear()">Send Near</v-btn>
</div>
<v-dialog
v-model="send.dialog"
persistent
max-width="600px"
>
<v-card>
<div style="text-align: center; padding: 20px;">
<h1>Send 1 NEAR</h1>
<h2>From: {{send.from}} To: {{send.to}}</h2>
<h4 style="color: brown;">Hash TX: {{send.tx.transaction.hash}}</h4>
</div>
<div style="text-align: center; padding: 20px;">
<v-btn style="background-color: green; color: aliceblue;" :disabled="send.btn" @click="send.dialog = false">{{send.txt_btn}}</v-btn>
</div>
</v-card>
</v-dialog>
</v-main>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/near-api-js@0.41.0/dist/near-api-js.min.js"></script>
<script>
// import * as nearAPI from "near-api-js";
new Vue({
el: '#app',
delimiters: ['{{','}}'],
vuetify: new Vuetify(),
data: {
near:"",
wallet:"",
utils:"",
profile:{
"account":"",
"balance": 0,
"details":"",
"accessKeys":"",
},
send : {
"dialog":false,
"btn":false,
"txt_btn":"",
"from":"",
"to":"test.testnet",
"value":"1000000000000000000000000",
"tx":{"transaction":{"hash":"..."}},
}
},
async mounted() {
const { connect, utils, keyStores, WalletConnection } = window.nearApi;
this.utils = utils
const config = {
networkId: "testnet",
keyStore: new keyStores.BrowserLocalStorageKeyStore(),
nodeUrl: "https://rpc.testnet.near.org",
walletUrl: "https://wallet.testnet.near.org",
helperUrl: "https://helper.testnet.near.org",
explorerUrl: "https://explorer.testnet.near.org",
};
this.near = await connect(config);
this.wallet = new WalletConnection(this.near,"test-app");
console.log("SignIn",this.wallet.isSignedIn())
this.GetData()
},
methods: {
async Login(){
console.log("SignIn",this.wallet.isSignedIn())
if(this.wallet.isSignedIn()) {
this.GetData()
}
else{
this.wallet.requestSignIn(
"aofserver.testnet", // Full access in only account
"Test App", // optional
).then((res)=>{
console.log(res)
})
}
},
Logout(){
this.wallet.signOut();
window.location.reload();
},
async GetData(){
const walletAccountId = this.wallet.getAccountId();
const account = await this.near.account(walletAccountId);
let balance = await account.getAccountBalance();
balance = this.utils.format.formatNearAmount(balance.available);
const details = await account.getAccountDetails();
accessKeys = await account.getAccessKeys();
this.profile.account = walletAccountId
this.profile.balance = balance
this.profile.details = details
this.profile.accessKeys = accessKeys
console.log(walletAccountId)
console.log(balance)
console.log(details)
},
async SendNear(){
try {
const account = await this.near.account(this.profile.account);
this.send.dialog = true
this.send.from = this.profile.account
this.send.btn = true
this.send.txt_btn = "wait transaction"
this.send.tx = {"transaction":{"hash":"..."}}
res = await account.sendMoney(
this.send.to,
this.send.value
);
this.send.tx = res
if(res.transaction.hash){
this.send.btn = false
this.send.txt_btn = "ok"
}
let balance = await account.getAccountBalance();
balance = this.utils.format.formatNearAmount(balance.available);
this.profile.balance = balance
} catch (error) {
this.send.tx = {"transaction":{"hash":"Error, Not allowed"}}
this.send.btn = false
this.send.txt_btn = "Set permission and try again"
}
}
}
})
</script>
</body>
</html>