-
Notifications
You must be signed in to change notification settings - Fork 16
/
naming.ls
135 lines (135 loc) · 4.62 KB
/
naming.ls
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
require! {
\react
\./ethnamed.ls
\prelude-ls : { map, join, filter, head }
\./get-record.ls
\./get-name-mask.ls
}
.naming
@import scheme
width: 95%
padding: 0px 0
margin: 0 10px 3px 10px
.custom-domain
input
height: 22px
padding: 2px 13px
width: 100%
text-align: left
width: 70%
position: relative
width: 100%
height: 31px
>.part
width: 100%
background: transparent
position: absolute
text-align: center
&.hidden
z-index: 0
input
color: rgba(black, 0.6)
background: transparent
&.visible
z-index: 1
input
background: transparent
color: #595768
.message
font-size: 11px
background: transparent
border: none !important
text-align: center
height: 15px
overflow: hidden
text-overflow: ellipsis
color: #595768 - 20
resize: none
padding: 0 !important
install-record = (name, record)->
"Please setup html element <meta property='ethnamed' value='#{record}' /> on #{name} to pass verification"
state =
timeout: null
module.exports = ({ store })->
{ setup-record, verify-record } = ethnamed store
price = 0.01ETH
empty = ->
( store.current.nickname ? "" ).length is 0
show-message = (message)->
store.current.message = message
can-buy-nickname = if store.current.can-buy then \active else \disabled
check = (cb)->
return cb? "Nickname is empty" if empty!
#err <- verify-network
return cb? err if err?
store.current.checking-name = true
show-message "Loading..."
err, data <- verify-record store.current.nicknamefull
store.current.checking-name = no
return cb? err if err?
can-buy = data is ""
store.current.can-buy = can-buy
return cb? "Address Not Found" if can-buy
cb? null, data
resolve-record = ->
err, data <- check
return show-message err if err?
show-message if data.length > 0 then "Busy" else "Free"
#goto "/resolve/#{store.current.nickname}", store
buy-nickname = (cb)->
name = store.current.nicknamefull
owner =
store.current.account.wallets
|> filter (.coin.token is \eth)
|> map (.address)
|> head
amount-ethers = price
record = get-record store
err, data <- check
return cb err if err? and err isnt "Address Not Found"
return cb "Address is already exists" if err isnt "Address Not Found"
err <- setup-record { name, record, amount-ethers, owner }
return cb install-record name, record if err is "Does not match"
return cb err if err?
cb null, "Your name is registered."
buy-nickname-process = (cb)->
store.current.status = \buy-nickname
err, done <- buy-nickname
return cb err if err?
cb null
buy-nickname-click = (event)->
err, done <- buy-nickname-process
store.current.status = \main
return show-message(err.message ? err) if err?
show-message done
set-mask = ->
store.current.nicknamefull = get-name-mask(store.current.nickname ? "")
enter-nick = (event)->
nickname = (event.target.value ? "").match(/^[a-z0-9\.@]+/)?0 ? ""
show-message "Typing..."
clear-timeout state.timeout
state.timeout = null
store.current.nickname = nickname
set-mask!
state.timeout = set-timeout resolve-record, 2000
change-to-custom = ->
store.current.custom-domain = yes
change-to-ethnamed = ->
store.current.custom-domain = no
.pug.box-container.naming
.pug.box
.pug.custom-domain
.part.hidden.pug
input.pug(value="#{store.current.nicknamefull}")
.part.visible.pug
input.pug(value="#{store.current.nickname}" on-change=enter-nick)
if (store.current.message ? "").length > 0
.pug.message(title="#{store.current.message}") #{store.current.message}
.pug
switch store.current.status
case \verify
.pug Nickname Verification...
case \buy-nickname
.pug Buy Nickname.
else
button.pug(on-click=buy-nickname-click) Register