-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve-address.ls
22 lines (22 loc) · 1012 Bytes
/
resolve-address.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require! {
\./web3.ls
\prelude-ls : { map, split, find, head, filter }
\./api.ls : { is-valid-address }
}
module.exports = (config, cb)->
{ store, network, coin, address} = config
return cb "Address not found" if address.trim! is ""
$token = coin.token
$network = network
chosen-network = store.current.send.chosen-network
if store.current.send.isSwap is yes and chosen-network.referTo?
$token = chosen-network.referTo
wallet = store.current.account.wallets |> find (-> it.coin.token is $token)
return cb "Wallet for token #{chosen-network.name} not found!" if not wallet?
$network = wallet.network
err, isValid <- is-valid-address { network: $network, address, token: $token }
return cb null, address if isValid
return cb err if err? if err.index-of("method is not supported") is -1
is-name = address.index-of(\.) isnt -1 or address.index-of(\@) isnt -1
return cb null, address if not is-name
cb "Address is not valid"