fix tokens validation

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2020-07-07 15:48:56 +02:00
parent 1e5288a016
commit 301f1c8cf2
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
17 changed files with 66 additions and 69 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -139,10 +139,6 @@
:name "Tronix" :name "Tronix"
:address "0xf230b790e05390fc8295f4d3f60332c93bed42e2" :address "0xf230b790e05390fc8295f4d3f60332c93bed42e2"
:decimals 6} :decimals 6}
{:symbol :ETHOS
:name "Ethos"
:address "0x5af2be193a6abca9c8817001f45744777db30756"
:decimals 8}
{:symbol :RDN {:symbol :RDN
:name "Raiden Token" :name "Raiden Token"
:address "0x255aa6df07540cb5d3d297f0d0d4d84cb52bc8e6" :address "0x255aa6df07540cb5d3d297f0d0d4d84cb52bc8e6"
@ -356,7 +352,7 @@
:name "district0x Network Token" :name "district0x Network Token"
:address "0x0abdace70d3790235af448c88547603b945604ea" :address "0x0abdace70d3790235af448c88547603b945604ea"
:decimals 18} :decimals 18}
{:symbol :٨ {:symbol :DCN
:name "Dentacoin" :name "Dentacoin"
:address "0x08d32b0da63e2c3bcf8019c9c5d849d7a9d791e6" :address "0x08d32b0da63e2c3bcf8019c9c5d849d7a9d791e6"
:decimals 0} :decimals 0}
@ -429,7 +425,7 @@
:address "0x80046305aaab08f6033b56a360c184391165dc2d" :address "0x80046305aaab08f6033b56a360c184391165dc2d"
:decimals 18} :decimals 18}
{:symbol :USDC {:symbol :USDC
:name "USD//C" :name "USD Coin"
:address "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" :address "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
:decimals 6} :decimals 6}
{:symbol :LPT {:symbol :LPT
@ -500,7 +496,7 @@
{:address "0x80fB784B7eD66730e8b1DBd9820aFD29931aab03" {:address "0x80fB784B7eD66730e8b1DBd9820aFD29931aab03"
:decimals 18 :decimals 18
:symbol :LEND :symbol :LEND
:name "EHTLend"} :name "EthLend Token"}
{:address "0xA15C7Ebe1f07CaF6bFF097D8a589fb8AC49Ae5B3" {:address "0xA15C7Ebe1f07CaF6bFF097D8a589fb8AC49Ae5B3"
:decimals 18 :decimals 18
:symbol :NPXS :symbol :NPXS
@ -508,15 +504,15 @@
{:address "0xA4e8C3Ec456107eA67d3075bF9e3DF3A75823DB0" {:address "0xA4e8C3Ec456107eA67d3075bF9e3DF3A75823DB0"
:decimals 18 :decimals 18
:symbol :LOOM :symbol :LOOM
:name "Loom Network"} :name "LoomToken"}
{:address "0x0e0989b1f9B8A38983c2BA8053269Ca62Ec9B195" {:address "0x0e0989b1f9B8A38983c2BA8053269Ca62Ec9B195"
:decimals 8 :decimals 8
:symbol :POE :symbol :POE
:name "Po.et Tokens"} :name "Po.et"}
{:address "0x5732046A883704404F284Ce41FfADd5b007FD668" {:address "0x5732046A883704404F284Ce41FfADd5b007FD668"
:decimals 18 :decimals 18
:symbol :BLZ :symbol :BLZ
:name "Bluzelle"} :name "Bluzelle Token"}
{:address "0xFA1a856Cfa3409CFa145Fa4e20Eb270dF3EB21ab" {:address "0xFA1a856Cfa3409CFa145Fa4e20Eb270dF3EB21ab"
:decimals 18 :decimals 18
:symbol :IOST :symbol :IOST
@ -524,19 +520,15 @@
{:address "0x1776e1F26f98b1A5dF9cD347953a26dd3Cb46671" {:address "0x1776e1F26f98b1A5dF9cD347953a26dd3Cb46671"
:decimals 18 :decimals 18
:symbol :NMR :symbol :NMR
:name "Numerai"} :name "Numeraire"}
{:address "0x8E870D67F660D95d5be530380D0eC0bd388289E1" {:address "0x8E870D67F660D95d5be530380D0eC0bd388289E1"
:decimals 18 :decimals 18
:symbol :PAX :symbol :PAX
:name "Paxos Standard (PAX)"} :name "Paxos Standard"}
{:address "0x08d32b0da63e2C3bcF8019c9c5d849d7a9d791e6"
:decimals 0
:symbol :DCN
:name "Dentacoin"}
{:address "0xEA26c4aC16D4a5A106820BC8AEE85fd0b7b2b664" {:address "0xEA26c4aC16D4a5A106820BC8AEE85fd0b7b2b664"
:decimals 18 :decimals 18
:symbol :QKC :symbol :QKC
:name "QuarkChain"} :name "QuarkChain Token"}
{:address "0x45804880De22913dAFE09f4980848ECE6EcbAf78" {:address "0x45804880De22913dAFE09f4980848ECE6EcbAf78"
:decimals 18 :decimals 18
:symbol :PAXG :symbol :PAXG
@ -552,11 +544,11 @@
{:address "0x607F4C5BB672230e8672085532f7e901544a7375" {:address "0x607F4C5BB672230e8672085532f7e901544a7375"
:decimals 9 :decimals 9
:symbol :RLC :symbol :RLC
:name "IEx.ec"} :name "iEx.ec Network Token"}
{:address "0x8400D94A5cb0fa0D041a3788e395285d61c9ee5e" {:address "0x8400D94A5cb0fa0D041a3788e395285d61c9ee5e"
:decimals 8 :decimals 8
:symbol :UBT :symbol :UBT
:name "Unibright"} :name "UniBright"}
{:address "0x4f3AfEC4E5a3F2A6a1A411DEF7D7dFe50eE057bF" {:address "0x4f3AfEC4E5a3F2A6a1A411DEF7D7dFe50eE057bF"
:decimals 9 :decimals 9
:symbol :DGX :symbol :DGX
@ -564,7 +556,7 @@
{:address "0xEA38eAa3C86c8F9B751533Ba2E562deb9acDED40" {:address "0xEA38eAa3C86c8F9B751533Ba2E562deb9acDED40"
:decimals 18 :decimals 18
:symbol :FUEL :symbol :FUEL
:name "Etherparty FUEL"} :name "Fuel Token"}
{:address "0x00000100F2A2bd000715001920eB70D229700085" {:address "0x00000100F2A2bd000715001920eB70D229700085"
:decimals 18 :decimals 18
:symbol :TCAD :symbol :TCAD
@ -580,7 +572,7 @@
{:address "0x0E8d6b471e332F140e7d9dbB99E5E3822F728DA6" {:address "0x0E8d6b471e332F140e7d9dbB99E5E3822F728DA6"
:decimals 18 :decimals 18
:symbol :ABYSS :symbol :ABYSS
:name "The Abyss"} :name "ABYSS"}
{:address "0xB62132e35a6c13ee1EE0f84dC5d40bad8d815206" {:address "0xB62132e35a6c13ee1EE0f84dC5d40bad8d815206"
:decimals 18 :decimals 18
:symbol :NEXO :symbol :NEXO
@ -608,11 +600,11 @@
{:address "0x9992eC3cF6A55b00978cdDF2b27BC6882d88D1eC" {:address "0x9992eC3cF6A55b00978cdDF2b27BC6882d88D1eC"
:decimals 18 :decimals 18
:symbol :POLY :symbol :POLY
:name "Polymath Network"} :name "Polymath"}
{:address "0x20F7A3DdF244dc9299975b4Da1C39F8D5D75f05A" {:address "0x20F7A3DdF244dc9299975b4Da1C39F8D5D75f05A"
:decimals 6 :decimals 6
:symbol :SPN :symbol :SPN
:name "Sapien"} :name "Sapien Network"}
{:address "0x1a7a8BD9106F2B8D977E08582DC7d24c723ab0DB" {:address "0x1a7a8BD9106F2B8D977E08582DC7d24c723ab0DB"
:decimals 18 :decimals 18
:symbol :APPC :symbol :APPC
@ -620,7 +612,7 @@
{:address "0xdAC17F958D2ee523a2206206994597C13D831ec7" {:address "0xdAC17F958D2ee523a2206206994597C13D831ec7"
:decimals 6 :decimals 6
:symbol :USDT :symbol :USDT
:name "USD Tether (erc20)"} :name "Tether USD"}
{:address "0xa3d58c4E56fedCae3a7c43A725aeE9A71F0ece4e" {:address "0xa3d58c4E56fedCae3a7c43A725aeE9A71F0ece4e"
:decimals 18 :decimals 18
:symbol :MET :symbol :MET
@ -628,11 +620,11 @@
{:address "0x6f259637dcD74C767781E37Bc6133cd6A68aa161" {:address "0x6f259637dcD74C767781E37Bc6133cd6A68aa161"
:decimals 18 :decimals 18
:symbol :HT :symbol :HT
:name "Huobi Token"} :name "HuobiToken"}
{:address "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" {:address "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
:decimals 18 :decimals 18
:symbol :WETH :symbol :WETH
:name "WETH"} :name "Wrapped Ether"}
{:address "0x8f3470A7388c05eE4e7AF3d01D8C722b0FF52374" {:address "0x8f3470A7388c05eE4e7AF3d01D8C722b0FF52374"
:decimals 18 :decimals 18
:symbol :VERI :symbol :VERI
@ -648,7 +640,7 @@
{:address "0xB24754bE79281553dc1adC160ddF5Cd9b74361a4" {:address "0xB24754bE79281553dc1adC160ddF5Cd9b74361a4"
:decimals 9 :decimals 9
:symbol :XRL :symbol :XRL
:name "XRL"} :name "RIALTO"}
{:address "0xC011A72400E58ecD99Ee497CF89E3775d4bd732F" {:address "0xC011A72400E58ecD99Ee497CF89E3775d4bd732F"
:decimals 18 :decimals 18
:symbol :SNX :symbol :SNX
@ -656,7 +648,7 @@
{:address "0x07e3c70653548B04f0A75970C1F81B4CBbFB606f" {:address "0x07e3c70653548B04f0A75970C1F81B4CBbFB606f"
:decimals 18 :decimals 18
:symbol :DLT :symbol :DLT
:name "Agrello"} :name "Delta"}
{:address "0x8207c1FfC5B6804F6024322CcF34F29c3541Ae26" {:address "0x8207c1FfC5B6804F6024322CcF34F29c3541Ae26"
:decimals 18 :decimals 18
:symbol :OGN :symbol :OGN
@ -667,8 +659,8 @@
:name "Decision Token"} :name "Decision Token"}
{:address "0x286BDA1413a2Df81731D4930ce2F862a35A609fE" {:address "0x286BDA1413a2Df81731D4930ce2F862a35A609fE"
:decimals 18 :decimals 18
:symbol :WABI :symbol :WaBi
:name "Tael"} :name "WaBi"}
{:address "0xE5a3229CCb22b6484594973A03a3851dCd948756" {:address "0xE5a3229CCb22b6484594973A03a3851dCd948756"
:decimals 18 :decimals 18
:symbol :RAE :symbol :RAE
@ -688,7 +680,7 @@
{:address "0xB98d4C97425d9908E66E53A6fDf673ACcA0BE986" {:address "0xB98d4C97425d9908E66E53A6fDf673ACcA0BE986"
:decimals 18 :decimals 18
:symbol :ABT :symbol :ABT
:name "ArcBlock Token"} :name "ArcBlock"}
{:address "0x81c9151de0C8bafCd325a57E3dB5a5dF1CEBf79c" {:address "0x81c9151de0C8bafCd325a57E3dB5a5dF1CEBf79c"
:decimals 18 :decimals 18
:symbol :DAT :symbol :DAT
@ -697,14 +689,6 @@
:decimals 18 :decimals 18
:symbol :EKO :symbol :EKO
:name "EchoLink"} :name "EchoLink"}
{:address "0x2C4e8f2D746113d0696cE89B35F0d8bF88E0AEcA"
:decimals 18
:symbol :OST
:name "Simple Token 'OST'"}
{:address "0xc92D6E3E64302C59d734f3292E2A13A13D7E1817"
:decimals 8
:symbol :FXC
:name "FUTURAX"}
{:address "0x4a57E687b9126435a9B19E4A802113e266AdeBde" {:address "0x4a57E687b9126435a9B19E4A802113e266AdeBde"
:decimals 18 :decimals 18
:symbol :FXC :symbol :FXC
@ -712,21 +696,21 @@
{:address "0xC86D054809623432210c107af2e3F619DcFbf652" {:address "0xC86D054809623432210c107af2e3F619DcFbf652"
:decimals 18 :decimals 18
:symbol :UPP :symbol :UPP
:name "Sentinel Protocol"} :name "SENTINEL PROTOCOL"}
{:address "0x5Af2Be193a6ABCa9c8817001F45744777Db30756" {:address "0x5Af2Be193a6ABCa9c8817001F45744777Db30756"
:decimals 8 :decimals 8
:symbol :BQX :symbol :VGX
:name "Bitquence"} :name "Voyager"}
{:address "0x69b148395ce0015c13e36bffbad63f49ef874e03" {:address "0x69b148395ce0015c13e36bffbad63f49ef874e03"
:symbol :DTA :symbol :DTA
:name "Data" :name "Data Token"
:decimals 18} :decimals 18}
{:address "0x57ab1e02fee23774580c119740129eac7081e9d3" {:address "0x57ab1e02fee23774580c119740129eac7081e9d3"
:symbol :SUSD :symbol :sUSD
:name "Synth sUSD" :name "Synth sUSD"
:decimals 18} :decimals 18}
{:address "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643" {:address "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643"
:symbol :CDAI :symbol :cDAI
:name "Compound Dai" :name "Compound Dai"
:decimals 8} :decimals 8}
{:address "0xba11d00c5f74255f56a5e366f4f77f5a186d7f55" {:address "0xba11d00c5f74255f56a5e366f4f77f5a186d7f55"

View File

@ -88,22 +88,23 @@
(defn- validate-token-symbol! (defn- validate-token-symbol!
[{:keys [address symbol]}] [{:keys [address symbol]}]
(json-rpc/eth-call (when-not (= symbol :DCN) ;; ignore this symbol because it has weird symbol
{:contract address (json-rpc/eth-call
:method "symbol()" {:contract address
:outputs ["string"] :method "symbol()"
:on-success :outputs ["string"]
(fn [[contract-symbol]] :on-success
;;NOTE(goranjovic): skipping check if field not set in contract (fn [[contract-symbol]]
(when (and (seq contract-symbol) ;;NOTE(goranjovic): skipping check if field not set in contract
(not= (clojure.core/name symbol) contract-symbol)) (when (and (seq contract-symbol)
(let [message (i18n/label :t/token-auto-validate-symbol-error (not= (clojure.core/name symbol) contract-symbol))
{:symbol symbol (let [message (i18n/label :t/token-auto-validate-symbol-error
:expected (clojure.core/name symbol) {:symbol symbol
:actual contract-symbol :expected (clojure.core/name symbol)
:address address})] :actual contract-symbol
(log/warn message) :address address})]
(utils.utils/show-popup (i18n/label :t/warning) message))))})) (log/warn message)
(utils.utils/show-popup (i18n/label :t/warning) message))))})))
(defn- validate-token-decimals! (defn- validate-token-decimals!
[{:keys [address symbol decimals nft?]}] [{:keys [address symbol decimals nft?]}]
@ -124,13 +125,24 @@
(log/warn message) (log/warn message)
(utils.utils/show-popup (i18n/label :t/warning) message))))}))) (utils.utils/show-popup (i18n/label :t/warning) message))))})))
(defn dups [seq]
(for [[id freq] (frequencies seq)
:when (> freq 1)]
id))
(re-frame/reg-fx (re-frame/reg-fx
:wallet/validate-tokens :wallet/validate-tokens
(fn [tokens] (fn [[tokens all-default-tokens]]
(doseq [token tokens] (let [symb-dups (dups (map :symbol all-default-tokens))
(validate-token-decimals! token) addr-dups (dups (map :address all-default-tokens))]
(validate-token-symbol! token) (when (seq symb-dups)
(validate-token-name! token)))) (utils.utils/show-popup (i18n/label :t/warning) (str "Duplicated tokens symbols" symb-dups)))
(when (seq addr-dups)
(utils.utils/show-popup (i18n/label :t/warning) (str "Duplicated tokens addresses" addr-dups)))
(doseq [token (vals tokens)]
(validate-token-decimals! token)
(validate-token-symbol! token)
(validate-token-name! token)))))
(defn- clean-up-results (defn- clean-up-results
"remove empty balances "remove empty balances
@ -188,13 +200,14 @@
(fx/defn initialize-tokens (fx/defn initialize-tokens
[{:keys [db]} custom-tokens] [{:keys [db]} custom-tokens]
(let [default-tokens (utils.core/index-by :address (get tokens/all-default-tokens (let [all-default-tokens (get tokens/all-default-tokens
(ethereum/chain-keyword db))) (ethereum/chain-keyword db))
default-tokens (utils.core/index-by :address all-default-tokens)
all-tokens (merge default-tokens (rpc->token custom-tokens))] all-tokens (merge default-tokens (rpc->token custom-tokens))]
(merge (merge
{:db (assoc db :wallet/all-tokens all-tokens)} {:db (assoc db :wallet/all-tokens all-tokens)}
(when config/erc20-contract-warnings-enabled? (when config/erc20-contract-warnings-enabled?
{:wallet/validate-tokens default-tokens})))) {:wallet/validate-tokens [default-tokens all-default-tokens]}))))
(fx/defn update-balances (fx/defn update-balances
[{{:keys [network-status :wallet/all-tokens [{{:keys [network-status :wallet/all-tokens