forked from cryptobuks1/JsWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu-funcs.ls
More file actions
160 lines (160 loc) · 6.2 KB
/
Copy pathmenu-funcs.ls
File metadata and controls
160 lines (160 loc) · 6.2 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
require! {
\prelude-ls : { filter, find }
\./tools.ls : { cut, money }
\./seed.ls
\./use-network.ls
\./pin.ls : { check }
\./navigate.ls
\./get-primary-info.ls
\copy-to-clipboard
\./pages/confirmation.ls : { confirm, prompt, alert, notify, prompt-password, prompt-choose-token }
\./get-lang.ls
\../web3t/providers/deps.ls : { bip39 }
}
export generate-wallet = ->
bip39.generate-mnemonic!
state =
timeout: null
adjust-color = (col, amt) ->
usePound = false
if col.0 is '#'
col = col.slice 1
usePound = true
num = parseInt col, 16
r = (num .>>. 16) + amt
if r > 255 then r = 255 else if r < 0 then r = 0
b = (num .>>. 8 .&. 255) + amt
if b > 255 then b = 255 else if b < 0 then b = 0
g = (num .&. 255) + amt
if g > 255 then g = 255 else if g < 0 then g = 0
(if usePound then '#' else '') + (g .|. b .<<. 8 .|. r .<<. 16).toString 16
build-schema = (first-color)->
second-color = adjust-color first-color, 50
third-color = adjust-color first-color, 100
background-image: "linear-gradient(90deg, #{first-color} 0%, #{second-color} 89%, #{third-color} 100%)"
module.exports = (store, web3t)->
return null if not store? or not web3t?
{ current } = store
lock = ->
navigate store, web3t, \locked
refresh = ->
<- web3t.refresh
not-in-dictionary = (word)->
word not in bip39.wordlists.EN
check-problem = (seed)->
return "expected seed" if typeof! seed isnt \String
return "expected lowercase" if seed.to-lower-case! isnt seed
words = seed.split(' ')
#return "expected 12/24 words" if words.length not in [12,24]
wrong-words =
words |> filter not-in-dictionary
return "some words are not in dictionary" if wrong-words.length > 0
""
#active-page = (page)->
# if current.page is page then \active
#choose-account = (selected, event)-->
# current.account <<< selected
#manage-accounts = (event)->
# current.page = \accounts
#select-page = (name, event)-->
# current.page = name
#pages =
# * \wallets
# * \history
change-seed = (event)->
state.timeout = clear-timeout state.timeout
current.seed = event.target.value
seedmem.mnemonic = event.target.value
current.seed-problem = check-problem event.target.value
state.timeout = set-timeout refresh, 2000
save-seed = ->
seed.set seedmem.mnemonic
current.saved-seed = yes
lang = get-lang store
edit-seed = ->
agree <- confirm store, lang.secret-phrase-change
return if not agree?
store.current.pin = ""
current.try-edit-seed = yes
#current.saved-seed = no
cancel-try = ->
current.try-edit-seed = no
check-pin = ->
return if not check(store.current.pin)
cancel-try!
current.saved-seed = no
enter-pin = (e)->
store.current.pin = e.target.value
generate = ->
agree <- confirm store, "Are you sure you want to override the current seed?"
return if not agree?
current.seed = generate-wallet!
seedmem.mnemonic = generate-wallet!
create-account!
switch-network = ->
network =
| store.current.network is \mainnet => \testnet
| _ => \mainnet
<- use-network web3t, store, network
activate-s = (name, event)-->
store.menu.active = name
activate-s1 = activate-s \s1
activate-s2 = activate-s \s2
activate-s3 = activate-s \s3
info = get-primary-info store
primary-color = info.color
wallet-style =
| not primary-color? => {}
| _ => build-schema primary-color
open-account = ->
{ account-name } = store.current.account
store.current.manage-account = yes
close-account = ->
store.current.manage-account = no
open-migration = ->
close-migration = ->
store.current.token-migration = null
open-language = ->
store.current.choose-language = yes
close-language = ->
store.current.choose-language = no
account-left = ->
cb = console.log
return alert store, "0 is smallest account index", cb if !(store.current.account-index >= 1)
store.current.account-index -= 1
refresh!
account-right = ->
cb = console.log
return alert store, "999999999 is highest account index", cb if !(store.current.account-index <= 999999999)
store.current.account-index += 1
refresh!
change-account-index = (event)->
return if not event?target
val = event.target.value
return if not val.match(/[0-9]+/)?
val = parse-int val
val = 0 if val < 0 or val > 999999999
store.current.account-index = val
change-account-index.timer = clear-timeout change-account-index.timer
change-account-index.timer = set-timeout refresh, 2000
export-private-key = ->
cb = console.log
pin <- prompt-password store, lang.private-key-enter-pin
return if pin+"".trim!.length is 0
return alert store, "wrong pin", cb if not check pin
index = store.current.account-index
store.current.prompt-answer = "VLX"
token-input <- prompt-choose-token store, lang.private-key-enter-coin
return if token-input+"".trim!.length is 0
if token-input is \VLX
token-input = \VLX2
return alert store, "token is empty", cb if not token-input?
token = (token-input ? "").to-lower-case!
wallets = current.account?wallets ? []
wallet =
wallets |> find (.coin?token is token)
return alert store, "Wallet not found for #{token}", cb if not wallet?
message = "This is your Private KEY"
copy-to-clipboard wallet.private-key
notify store, "Your Private KEY is copied into your clipboard", cb
{ export-private-key, check-pin, change-account-index, account-left, account-right, open-account, close-account, open-migration, close-migration, open-language, close-language, current, wallet-style, info, activate-s1, activate-s2, activate-s3, switch-network, generate, enter-pin, cancel-try, edit-seed, save-seed, change-seed, refresh, lock }