fix: resolve token ens name in EIP-681 links from qr code (#13947)
This commit is contained in:
parent
e4feb36ccc
commit
c0d136d140
|
@ -55,7 +55,7 @@
|
|||
(let [[_ authority-path query] (re-find uri-pattern s)]
|
||||
(when authority-path
|
||||
(let [[_ raw-address chain-id function-name] (re-find authority-path-pattern authority-path)]
|
||||
(when (or (ethereum/address? raw-address)
|
||||
(when (or (or (ens/is-valid-eth-name? raw-address) (ethereum/address? raw-address))
|
||||
(when (string/starts-with? raw-address "pay-")
|
||||
(let [pay-address (string/replace-first raw-address "pay-" "")]
|
||||
(or (ens/is-valid-eth-name? pay-address)
|
||||
|
@ -67,7 +67,7 @@
|
|||
(let [contract-address (get-in arguments [:function-arguments :address])]
|
||||
(if-not (or (not contract-address) (or (ens/is-valid-eth-name? contract-address) (ethereum/address? contract-address)))
|
||||
nil
|
||||
(merge {:address address
|
||||
(merge {:address address
|
||||
:chain-id (if chain-id
|
||||
(js/parseInt chain-id)
|
||||
(ethereum/chain-keyword->chain-id :mainnet))}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
(is (= nil (eip681/parse-uri "ethereum:?value=1")))
|
||||
(is (= nil (eip681/parse-uri "bitcoin:0x1234")))
|
||||
(is (= nil (eip681/parse-uri "ethereum:0x1234")))
|
||||
(is (= nil (eip681/parse-uri "ethereum:gimme.eth?value=1e18")))
|
||||
(is (= nil (eip681/parse-uri "ethereum:gimme.ether?value=1e18")))
|
||||
(is (= nil (eip681/parse-uri "ethereum:pay-gimme.ether?value=1e18")))
|
||||
(is (= nil (eip681/parse-uri "ethereum:pay-snt.thetoken.ether/transfer?address=gimme.eth&uint256=1&gas=100")))
|
||||
|
@ -74,6 +73,10 @@
|
|||
:function-name "transfer" :function-arguments {:address "0x8e23ee67d1332ad560396262c48ffbb01f93d052" :uint256 "1"}}))
|
||||
|
||||
(is (= (eip681/parse-uri "ethereum:pay-snt.thetoken.eth/transfer?address=gimme.eth&uint256=1&gas=100")
|
||||
{:address "snt.thetoken.eth" :chain-id 1 :gas "100"
|
||||
:function-name "transfer" :function-arguments {:address "gimme.eth" :uint256 "1"}}))
|
||||
|
||||
(is (= (eip681/parse-uri "ethereum:snt.thetoken.eth/transfer?address=gimme.eth&uint256=1&gas=100")
|
||||
{:address "snt.thetoken.eth" :chain-id 1 :gas "100"
|
||||
:function-name "transfer" :function-arguments {:address "gimme.eth" :uint256 "1"}})))
|
||||
|
||||
|
@ -141,12 +144,14 @@
|
|||
(is (= "0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7" address)))
|
||||
(is (= (eip681/extract-request-details {:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e" :chain-id 1 :function-name "unknown"} {})
|
||||
{:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e" :chain-id 1 :function-name "unknown"}))
|
||||
(let [{:keys [value symbol address]} (eip681/extract-request-details {:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e" :chain-id 1
|
||||
:function-name "transfer" :function-arguments {:uint256 1000 :address "0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7"}}
|
||||
{"0x744d70fdbe2ba4cf95131626614a1763df805b9e" {:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
|
||||
:name "Status Network Token"
|
||||
:symbol :SNT
|
||||
:decimals 18}})]
|
||||
(let [{:keys [value symbol address]}
|
||||
(eip681/extract-request-details
|
||||
{:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e" :chain-id 1
|
||||
:function-name "transfer" :function-arguments {:uint256 1000 :address "0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7"}}
|
||||
{"0x744d70fdbe2ba4cf95131626614a1763df805b9e" {:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
|
||||
:name "Status Network Token"
|
||||
:symbol :SNT
|
||||
:decimals 18}})]
|
||||
(is (.equals (money/bignumber 1000) value))
|
||||
(is (= :SNT symbol))
|
||||
(is (= "0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7" address))))
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
(ns status-im.ui.screens.qr-scanner.views
|
||||
(:require-macros [status-im.utils.views :refer [defview letsubs]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
(:require ["react-native-camera-kit" :refer (CameraKitCamera)]
|
||||
[clojure.string :as string]
|
||||
[status-im.i18n.i18n :as i18n]
|
||||
[status-im.ui.components.topbar :as topbar]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.screens.qr-scanner.styles :as styles]
|
||||
[quo.design-system.colors :as colors]
|
||||
[status-im.utils.config :as config]
|
||||
[quo.core :as quo]
|
||||
[quo.design-system.colors :as colors]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
["react-native-camera-kit" :refer (CameraKitCamera)]))
|
||||
[status-im.i18n.i18n :as i18n]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.components.topbar :as topbar]
|
||||
[status-im.ui.screens.qr-scanner.styles :as styles]
|
||||
[status-im.utils.config :as config]))
|
||||
|
||||
(def camera (reagent/adapt-react-class CameraKitCamera))
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
|||
{:on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-cancel opts])}
|
||||
"Cancel"]
|
||||
[quo/button
|
||||
{:on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-success opts (when-let [text @text-value] (string/trim text))])}
|
||||
{:on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-success opts (when-let [text @text-value] (-> text string/trim (string/replace #"^Ethereum:" "ethereum:")))])}
|
||||
"Ok"]]]))
|
||||
|
||||
(defn corner [border1 border2 corner]
|
||||
|
|
Loading…
Reference in New Issue