-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathnewwallet.py
More file actions
346 lines (308 loc) · 13.7 KB
/
newwallet.py
File metadata and controls
346 lines (308 loc) · 13.7 KB
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/usr/bin/python
# -*- coding: utf-8 -*-
# # Copyright (c) 2017-2019, The Sumokoin Project (www.sumokoin.org)
'''
New wallet HTML
'''
html ="""
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./scripts/jquery-1.9.1.min.js"></script>
<script src="./scripts/utils.js"></script>
<script type="text/javascript">
function app_ready(){
app_hub.on_new_wallet_show_progress_event.connect(show_progress);
app_hub.on_new_wallet_show_info_event.connect(show_wallet_info);
app_hub.on_new_wallet_ui_reset_event.connect(reset_ui);
app_hub.on_new_wallet_update_processed_block_height_event.connect(update_processed_block_height);
app_hub.on_paste_seed_words_event.connect(function(text){
$('#seed').val(text);
});
}
function create_new_wallet(){
app_hub.create_new_wallet();
return false;
}
function restore_wallet(){
var seed = $('#seed').val();
var restore_height = $('#restore_height_txt').val();
var seed_offset_passphrase = $('#seed_offset_passphrase_txt').val();
var h = !isNaN(parseInt(restore_height)) ? parseInt(restore_height) : 0;
if(h < 0) h = 0;
seed = replaceAll(seed, "\\n", " ");
app_hub.restore_deterministic_wallet(seed, h, seed_offset_passphrase)
return false;
}
function import_wallet(){
app_hub.import_wallet();
return false;
}
function show_progress(header){
$('#gen_wallet_btn').disable(true);
$('#restore_wallet_btn').disable(true);
$('#import_wallet_btn').disable(true);
$('#container').hide();
$('#progress_header').html(header);
$('#progress').show();
}
function show_wallet_info(info_json){
var wallet_info = $.parseJSON(info_json);
$('#wallet_address').val(wallet_info['address']);
$('#wallet_seed_words').val(wallet_info['seed']);
$('#wallet_viewkey').val(wallet_info['view_key']);
$('#balance').html(wallet_info['balance']);
$('#unlocked_balance').html(wallet_info['unlocked_balance']);
$('#progress').hide();
$('#container').show();
$('#main_page').hide();
$('#wallet_info').show();
}
function close_dialog(){
app_hub.close_new_wallet_dialog();
return false;
}
function reset_ui(){
$('#gen_wallet_btn').disable(false);
$('#restore_wallet_btn').disable(false);
$('#import_wallet_btn').disable(false);
$('#progress').hide();
$('#container').show();
$('#main_page').show();
$('#wallet_info').hide();
}
function update_processed_block_height(height, target_height, block_hash){
var html = height;
if(target_height > 0 && target_height > height){
sync_pct = target_height > 0 ? (height*100.0/target_height).toFixed(1) : 0;
$('#progress_header').html("Restoring wallet..." + " (" + sync_pct + "%)");
html = height + "/" + target_height;
$('#processing_block').show();
}
$('#processed_block_height').html(html);
$('#processed_block_hash').html('< ' + block_hash + ' >');
}
function paste_seed(){
app_hub.paste_seed_words();
return false;
}
function copy_seed(){
app_hub.copy_seed($('#wallet_seed_words').val());
return false;
}
</script>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/font-awesome.min.css" rel="stylesheet">
<style type="text/css">
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
/* Disable text selection */
-webkit-user-select: none; /* webkit all */
user-select: none; /* regular */
cursor: default;
background-color: #666;
color: #76A500;
background-position: center center;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
a, a:hover, a:active, a:focus {
text-decoration: none;
outline: 0;
cursor: default;
}
a, a:active, a:focus{
color: #337AB7;
}
a:hover{
color: #fff;
}
table {
border-spacing: 0;
border-collapse: collapse;
font-size: 90%;
}
table thead tr{
height: 4.5em;
}
table tbody tr {
color: #aaa;
height: 6em;
line-height: 1.6em;
border-top: 1px solid #aaa;
}
table thead tr th{
text-align: center;
border-bottom: 1px solid #aaa;
text-size: 18px;
padding: auto 1em;
}
table tr td {
text-align: center;
}
.row {
margin: 5px;
}
.row .col-sm-12 {
background: #fff;
padding: 10px 30px;
}
input[type="file"] {
display: inline-block;
visibility: hidden;
}
.custom-file-upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}
.centered {
position: fixed;
width: 730px;
top: 25%;
left: 5%;
text-align: center;
/* bring your own prefixes */
transform: translate(-50%, -50%);
}
#progress {
background:#fff;
width:800px;
height:550px;
margin: 5px;
text-align:center;
display:none;
}
.progress{
height: 22px;
text-align: center;
background: #ddd;
}
#progress_header{
margin-bottom: 20px;
}
#processing_block{
display: none;
font-family: Consolas, "Courier New", monospace;
margin-top: 20px;
font-size: 16px;
}
.form-control.address-box{
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
font-size: 85%;
/*color: #c7254e;*/
color: #000;
}
.container{
padding: 0;
width: 100%;
}
textarea{
border:none;
width:100%;
resize:none;
font-weight:bold;
}
.form-group h5 i{
color: #76A500;
font-style: normal;
}
</style>
</head>
<body>
<div id="container" class="container">
<form>
<div id="main_page" style="display:block">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<h4>New Wallet</h4>
<label for="gen_wallet_btn" class="sr-only">New wallet</label>
<button id="gen_wallet_btn" type="button" class="btn btn-primary" onclick="create_new_wallet()"><i class="fa fa-file"></i> Create</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<h4>Restore Wallet from Mnemonic Seed<small></small></h4>
<div class="form-group">
<label for="seed" style="font-weight: bold;margin-right: 20px">Mnemonic Seed:</label> <button id="paste_seed_btn" type="button" class="btn btn-warning btn-sm" style="text-transform: none" onclick="paste_seed()"><i class="fa fa-paste"></i> Paste</button>
<textarea id="seed" class="form-control" placeholder="Paste 26 mnemonic seed words here (use [Paste] button above or press Ctrl+V)" style="height:80px;margin-bottom:10px;margin-top:10px;font-size:100%"></textarea>
<button id="restore_wallet_btn" type="button" class="btn btn-primary" onclick="restore_wallet()"><i class="fa fa-undo"></i> Restore</button>
<input id="restore_height_txt" type="text" class="form-control" style="display: inline-block; float:right; width: 70px" value="0"/> <label for="restore_height_txt" style="font-weight: bold; display:inline-block; float:right; margin-right:20px;">Restore from height#</label>
<input id="seed_offset_passphrase_txt" type="password" class="form-control" style="display: inline-block; float:right; width: 180px" value=""/> <label for="seed_offset_passphrase_txt" style="font-weight: bold; display:inline-block; float:right; margin-right:20px;">Seed offset passphrase</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<h4>Import From Existing Wallet</h4>
<button id="import_wallet_btn" type="button" class="btn btn-primary" onclick="import_wallet()"><i class="fa fa-cloud-upload"></i> Import</button>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12" style="background: transparent; text-align: center;">
<button id="btn_cancel" type="button" class="btn btn-danger center" onclick="close_dialog()"><i class="fa fa-close"></i> Cancel</button>
</div>
</div>
</div>
<div id="wallet_info" style="display: none">
<div class="row">
<div class="col-sm-12">
<div class="alert alert-success" role="alert"><strong>Wallet was successfully created/restored or imported!</strong></div>
<h4 style="margin-bottom:0">Wallet Information</h4>
</div>
<div class="col-sm-12">
<div class="form-group">
<label for="wallet_address">Address</label>
<input id="wallet_address" type="text" class="form-control address-box" style="color:#c7254e;" readonly="readonly" value="Sumoo..."/>
</div>
<div class="form-group">
<label for="wallet_viewkey">View key (private)</label>
<input id="wallet_viewkey" class="form-control address-box" type="text" readonly="readonly" />
</div>
<div class="form-group">
<label for="wallet_seed_words">Mnemonic seed <code style="font-weight: bold; color: red">(NOTICE: Always backup the seed words for wallet recovery!)</code></label>
<button id="copy_seed_btn" type="button" class="btn btn-warning btn-sm" style="text-transform: none" onclick="copy_seed()"><i class="fa fa-copy"></i> Copy Seed Words</button>
<textarea id="wallet_seed_words" class="form-control address-box" style="height:70px;font-size:95%;color:#333" readonly="readonly"></textarea>
</div>
<div class="form-group">
<h5><i>Balance:</i> <span id="balance">0.000000000</span></h5>
<h5><i>Unlocked Balance:</i> <span id="unlocked_balance">0.000000000</span></h5>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12" style="background: transparent; text-align: center;">
<button id="btn_open_wallet" type="button" class="btn btn-success" onclick="close_dialog()">Open Wallet ››</button>
</div>
</div>
</div>
</form>
</div>
<div id="progress">
<div class="centered">
<h3 id="progress_header">Creating/Restoring wallet...</h3>
<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>
<div id="processing_block">
Processed block: <span id="processed_block_height">0</span><br>
<span id="processed_block_hash"></span>
</div>
</div>
</div>
</body>
</html>
"""