-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwallet.dart
323 lines (306 loc) · 11.5 KB
/
wallet.dart
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import 'package:flutter/material.dart';
import 'package:walletconnect_dart/walletconnect_dart.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'whoareyou.dart';
class wallet extends StatefulWidget {
@override
_walletState createState() => _walletState();
}
class _walletState extends State<wallet> {
var connector = WalletConnect(
bridge: 'https://bridge.walletconnect.org',
clientMeta: const PeerMeta(
name: 'My App',
description: 'An app for converting pictures to NFT',
url: 'https://pamplnet.org',
icons: [
'https://files.gitbook.com/v0/b/gitbook-legacy-files/o/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
]));
var _session, _uri, _signature;
loginUsingMetamask(BuildContext context) async {
if (!connector.connected) {
try {
var session = await connector.createSession(onDisplayUri: (uri) async {
_uri = uri;
await launchUrlString(uri, mode: LaunchMode.externalApplication);
});
print(session.accounts[0]);
print(session.chainId);
setState(() {
_session = session;
});
} catch (exp) {
print(exp);
}
}
}
@override
Widget build(BuildContext context) {
connector.on(
'connect',
(session) => setState(
() {
_session = _session;
},
));
connector.on(
'session_update',
(payload) => setState(() {
_session = payload;
print(_session.accounts[0]);
print(_session.chainId);
}));
connector.on(
'disconnect',
(payload) => setState(() {
_session = null;
}));
final deviceWidth = MediaQuery.of(context).size.width;
final standardDeviceWidth = 375;
final Factor_Width = deviceWidth / standardDeviceWidth;
final deviceHeight = MediaQuery.of(context).size.height;
final standardDeviceHeight = 812;
final Factor_Height = deviceHeight / standardDeviceHeight;
bool isconnected = false;
return GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 29 * Factor_Height,
),
Container(
height: 52 * Factor_Height,
),
Container(
// 사진
height: 205 * Factor_Height,
width: 312 * Factor_Height,
child: Image.asset(
'assets/wallet.png',
height: 205 * Factor_Height,
width: 312 * Factor_Height,
),
),
Container(
// 공백
height: 47 * Factor_Height,
),
Container(
// '가상 지갑 연동' 텍스트
height: 35 * Factor_Height,
child: Text(
'가상 지갑 연동',
style: TextStyle(
fontSize: 32 * Factor_Height,
fontFamily: 'Spoqa-Bold',
color: Color(0xFF3C3C3C),
),
textAlign: TextAlign.center,
),
),
Container(
// 공백
height: 19 * Factor_Height,
),
Container(
height: 46 * Factor_Height,
child: Column(
children: [
Expanded(
child: Text(
'NFT 서비스를 이용하기 위해서는',
style: TextStyle(
fontSize: 18 * Factor_Height,
fontFamily: 'Spoqa-Medium',
color: Color(0xFF797979),
),
textAlign: TextAlign.center,
),
),
Expanded(
child: Text(
'NFT를 보관할 지갑이 필요합니다!',
style: TextStyle(
fontSize: 18 * Factor_Height,
fontFamily: 'Spoqa-Medium',
color: Color(0xFF797979),
),
textAlign: TextAlign.center,
),
),
],
),
),
Container(
// 공백
height: 63 * Factor_Height,
),
Container(
// MetaMask 버튼
height: 53 * Factor_Height,
child: GestureDetector(
onTap: () {
if(_session == null) {
print("_session: null");
loginUsingMetamask(context);
}// metamask 웹 페이지로 넘어가도록 추후 구현
else print("_session: !null");
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Color(0xFFD9D9D9),
),
width: 253 * Factor_Width,
child: Row(
children: <Widget>[
Container(width: 7 * Factor_Width),
Container(
//MetaMask 연동 이미지
// 사진
height: 25 * Factor_Height,
width: 25 * Factor_Height,
child: Image.asset(
'assets/metamask_logo.png',
height: 25 * Factor_Height,
width: 25 * Factor_Height,
),
),
Container(width: 10 * Factor_Width),
Container(
child: Center(
child: Text(
'MetaMask',
style: TextStyle(
fontSize: 15 * Factor_Height,
fontFamily: 'Spoqa-Bold',
color: Colors.black,
),
),
),
),
],
),
),
),
),
Container(
height: 13 * Factor_Height,
),
Container(
// MetaMask 지갑이 없다면? 버튼
height: 53 * Factor_Height,
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
whoareyou())); // metamask 웹 페이지로 넘어가도록 추후 구현
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Color(0xFFD9D9D9),
),
width: 253 * Factor_Width,
child: Row(
children: <Widget>[
Container(width: 7 * Factor_Width),
Container(
//MetaMask 연동 이미지
// 사진
height: 25 * Factor_Height,
width: 25 * Factor_Height,
child: Image.asset(
'assets/metamask_connect.png',
height: 25 * Factor_Height,
width: 25 * Factor_Height,
),
),
Container(width: 10 * Factor_Width),
Container(
child: Center(
child: Text(
'MetaMask 지갑이 없다면?',
style: TextStyle(
fontSize: 15 * Factor_Height,
fontFamily: 'Spoqa-Bold',
color: Colors.black,
),
),
),
),
],
),
),
),
),
Container(
// 공백
height: 61 * Factor_Height,
),
Container(
// 다음으로 버튼
height: 53 * Factor_Height,
child: Container(
height: 53 * Factor_Height,
width: 300 * Factor_Width,
child: GestureDetector(
onTap: () {
_session = true; //디버깅용, 추후 삭제 바람
if(_session!=null)
Navigator.push( // 연동된 경우 true를 return하는 isconnected가 true일 경우 다음으로 버튼을 눌렀을 때 다음 페이지로 넘어가고, false일 경우 버튼을 눌렀을 때 반응이 없도록 설계
context,
MaterialPageRoute(
builder: (context) => whoareyou()));
// whoareyou 페이지로 넘어감
},
child: Stack(
children: [
Center(
child: Opacity(
opacity: 0.73,
child: Container(
decoration: BoxDecoration(
color: Color(0xFFCD0051),
borderRadius: BorderRadius.circular(12),
),
width: 253 * Factor_Width,
),
),
),
Center(
child: Text(
'다음으로',
style: TextStyle(
fontSize: 17 * Factor_Width,
fontFamily: 'Spoqa-Bold',
color: Colors.white,
),
),
),
],
),
),
),
),
Container(
height: 83 * Factor_Height,
),
],
),
),
),
);
}
}