mirror of
https://github.com/status-im/status-react.git
synced 2025-01-09 18:46:19 +00:00
use ens name for granting permissions
Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
f5ab49a4a4
commit
1f2e2728cb
@ -14,8 +14,7 @@ function sendAPIrequest(permission, params) {
|
|||||||
bridgeSend({
|
bridgeSend({
|
||||||
type: 'api-request',
|
type: 'api-request',
|
||||||
permission: permission,
|
permission: permission,
|
||||||
messageId: messageId,
|
messageId: messageId
|
||||||
host: window.location.hostname
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
@ -145,8 +144,7 @@ ReadOnlyProvider.prototype.sendAsync = function (payload, callback) {
|
|||||||
for (var i in payload) {
|
for (var i in payload) {
|
||||||
bridgeSend({type: 'web3-send-async-read-only',
|
bridgeSend({type: 'web3-send-async-read-only',
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
payload: payload[i],
|
payload: payload[i]});
|
||||||
host: window.location.hostname});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -154,8 +152,7 @@ ReadOnlyProvider.prototype.sendAsync = function (payload, callback) {
|
|||||||
callbacks[messageId] = {callback: callback};
|
callbacks[messageId] = {callback: callback};
|
||||||
bridgeSend({type: 'web3-send-async-read-only',
|
bridgeSend({type: 'web3-send-async-read-only',
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
payload: payload,
|
payload: payload});
|
||||||
host: window.location.hostname});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@
|
|||||||
|
|
||||||
(defn check-if-dapp-in-list [{:keys [history history-index] :as browser}]
|
(defn check-if-dapp-in-list [{:keys [history history-index] :as browser}]
|
||||||
(let [history-host (http/url-host (try (nth history history-index) (catch js/Error _)))
|
(let [history-host (http/url-host (try (nth history history-index) (catch js/Error _)))
|
||||||
dapp (first (filter #(= history-host (http/url-host (:dapp-url %))) (apply concat (mapv :data default-dapps/all))))]
|
dapp (first (filter #(= history-host (http/url-host (http/normalize-url (:dapp-url %))))
|
||||||
|
(apply concat (mapv :data default-dapps/all))))]
|
||||||
(if dapp
|
(if dapp
|
||||||
;;TODO(yenda): the consequence of this is that if user goes to a different
|
;;TODO(yenda): the consequence of this is that if user goes to a different
|
||||||
;;url from a dapp browser, the name of the browser in the home screen will
|
;;url from a dapp browser, the name of the browser in the home screen will
|
||||||
@ -88,8 +89,8 @@
|
|||||||
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))))
|
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))))
|
||||||
|
|
||||||
(fx/defn resolve-url
|
(fx/defn resolve-url
|
||||||
[{{:keys [web3 network] :as db} :db} {:keys [loading? error? resolved-url]}]
|
[{{:keys [web3 network] :as db} :db} {:keys [error? resolved-url]}]
|
||||||
(when (and (not loading?) (not error?))
|
(when (not error?)
|
||||||
(let [current-url (get-current-url (get-current-browser db))
|
(let [current-url (get-current-url (get-current-browser db))
|
||||||
host (http/url-host current-url)]
|
host (http/url-host current-url)]
|
||||||
(if (and (not resolved-url) (ens/is-valid-eth-name? host))
|
(if (and (not resolved-url) (ens/is-valid-eth-name? host))
|
||||||
@ -137,24 +138,15 @@
|
|||||||
(resolve-url nil)))))
|
(resolve-url nil)))))
|
||||||
|
|
||||||
(fx/defn update-browser-history
|
(fx/defn update-browser-history
|
||||||
;; TODO: not clear how this works
|
[cofx browser url]
|
||||||
[{db :db :as cofx} browser url loading?]
|
(let [history-index (:history-index browser)
|
||||||
(when-not loading?
|
history (:history browser)]
|
||||||
(let [history-index (:history-index browser)
|
(let [new-history (conj (subvec history 0 (inc history-index)) url)
|
||||||
history (:history browser)
|
new-index (dec (count new-history))]
|
||||||
current-url (get-in db [:browser/options :url])]
|
(update-browser cofx
|
||||||
(when (and (not= current-url url) (not= (str current-url "/") url))
|
(assoc browser
|
||||||
(let [slash? (= url (str current-url "/"))
|
:history new-history
|
||||||
new-history (if slash?
|
:history-index new-index)))))
|
||||||
(assoc history history-index url)
|
|
||||||
(conj (subvec history 0 (inc history-index)) url))
|
|
||||||
new-index (if slash?
|
|
||||||
history-index
|
|
||||||
(dec (count new-history)))]
|
|
||||||
(update-browser cofx
|
|
||||||
(assoc browser
|
|
||||||
:history new-history
|
|
||||||
:history-index new-index)))))))
|
|
||||||
|
|
||||||
(fx/defn resolve-ens-multihash-success
|
(fx/defn resolve-ens-multihash-success
|
||||||
[{:keys [db] :as cofx} hash]
|
[{:keys [db] :as cofx} hash]
|
||||||
@ -189,8 +181,8 @@
|
|||||||
(let [resolved-ens (first (filter #(not= (.indexOf url (second %)) -1) (:resolved-ens options)))
|
(let [resolved-ens (first (filter #(not= (.indexOf url (second %)) -1) (:resolved-ens options)))
|
||||||
resolved-url (if resolved-ens (string/replace url (second resolved-ens) (first resolved-ens)) url)]
|
resolved-url (if resolved-ens (string/replace url (second resolved-ens) (first resolved-ens)) url)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(update-browser-history browser resolved-url loading?)
|
(update-browser-history browser resolved-url)
|
||||||
(resolve-url {:loading? loading? :error? error? :resolved-url (when resolved-ens url)}))))))
|
(resolve-url {:error? error? :resolved-url (when resolved-ens url)}))))))
|
||||||
|
|
||||||
(fx/defn navigation-state-changed
|
(fx/defn navigation-state-changed
|
||||||
[cofx event error?]
|
[cofx event error?]
|
||||||
@ -211,7 +203,7 @@
|
|||||||
normalized-url (http/normalize-and-decode-url url)]
|
normalized-url (http/normalize-and-decode-url url)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(update-browser-option :url-editing? false)
|
(update-browser-option :url-editing? false)
|
||||||
(update-browser-history browser normalized-url false)
|
(update-browser-history browser normalized-url)
|
||||||
(resolve-url nil))))
|
(resolve-url nil))))
|
||||||
|
|
||||||
(fx/defn open-url
|
(fx/defn open-url
|
||||||
@ -288,19 +280,18 @@
|
|||||||
|
|
||||||
(fx/defn process-bridge-message
|
(fx/defn process-bridge-message
|
||||||
[{:keys [db] :as cofx} message]
|
[{:keys [db] :as cofx} message]
|
||||||
(let [{:browser/keys [options browsers]} db
|
(let [browser (get-current-browser db)
|
||||||
{:keys [browser-id]} options
|
url-original (get-current-url browser)
|
||||||
browser (get browsers browser-id)
|
|
||||||
data (types/json->clj message)
|
data (types/json->clj message)
|
||||||
{{:keys [url]} :navState :keys [type host permission payload messageId]} data
|
{{:keys [url]} :navState :keys [type permission payload messageId]} data
|
||||||
{:keys [dapp? name]} browser
|
{:keys [dapp? name]} browser
|
||||||
dapp-name (if dapp? name host)]
|
dapp-name (if dapp? name (http/url-host url-original))]
|
||||||
(cond
|
(cond
|
||||||
(and (= type constants/history-state-changed)
|
(and (= type constants/history-state-changed)
|
||||||
platform/ios?
|
platform/ios?
|
||||||
(not= "about:blank" url))
|
(not= "about:blank" url))
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
(update-browser-history browser url false)
|
(update-browser-history browser url)
|
||||||
(resolve-url nil))
|
(resolve-url nil))
|
||||||
|
|
||||||
(= type constants/web3-send-async)
|
(= type constants/web3-send-async)
|
||||||
|
@ -158,7 +158,7 @@
|
|||||||
:photo-path "contacts://snt-voting"
|
:photo-path "contacts://snt-voting"
|
||||||
:description "Let your SNT be heard! Vote on decisions exclusive to SNT holders, or create a poll of your own."}
|
:description "Let your SNT be heard! Vote on decisions exclusive to SNT holders, or create a poll of your own."}
|
||||||
{:name "Status Test DApp"
|
{:name "Status Test DApp"
|
||||||
:dapp-url "https://status-im.github.io/dapp/"
|
:dapp-url "simpledapp.eth"
|
||||||
:description "Request test assets and test basic web3 functionality."
|
:description "Request test assets and test basic web3 functionality."
|
||||||
:developer? true}]}])
|
:developer? true}]}])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user