Skip to content

Commit

Permalink
[#8977] [Multi-account] Allow user to choose wallet for DApp transact…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
  • Loading branch information
flexsurfer committed Oct 11, 2019
1 parent 5fd269f commit df098f8
Show file tree
Hide file tree
Showing 28 changed files with 360 additions and 153 deletions.
4 changes: 4 additions & 0 deletions ICONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# new icons

## Export icons

![](./export-icons.gif)

## android
1. copy files to corresponding directories at `/Users/romanvolosovskyi/clj/status-react/android/app/src/main/res` (one of `drawable-hdpi`, `drawable-mdpi`, `drawable-xhdpi`, `drawable-xxhdpi`, `drawable-xxxhdpi` for corresponding resolution)
If you only have 3 pngs 1x, 2x and 3x put them in mdpi, xhdpi and xxhdpi
Expand Down
Binary file added android/app/src/main/res/drawable-mdpi/account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/drawable-xhdpi/account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/drawable-xxhdpi/account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added export-icons.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ios/StatusIm/Images.xcassets/account.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "account.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "account@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "account@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 42 additions & 15 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
[status-im.utils.types :as types]
[status-im.utils.universal-links.core :as universal-links]
[taoensso.timbre :as log]
[status-im.signing.core :as signing]))
[status-im.signing.core :as signing]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))

(fx/defn update-browser-option
[{:keys [db]} option-key option-value]
Expand Down Expand Up @@ -311,29 +313,37 @@
(ethereum/address? second-param)
[second-param first-param]))))

(fx/defn send-to-bridge
[cofx message]
{:browser/send-to-bridge {:message message
:webview (get-in cofx [:db :webview-bridge])}})

(fx/defn web3-send-async
[cofx {:keys [method params id] :as payload} message-id]
(let [message? (constants/web3-sign-message? method)]
(let [message? (constants/web3-sign-message? method)
dapps-address (get-in cofx [:db :multiaccount :dapps-address])]
(if (or message? (= constants/web3-send-transaction method))
(let [[address data] (when message? (normalize-sign-message-params params))]
(when (or (not message?) (and address data))
(signing/sign cofx (merge
(if message?
{:message {:address address :data data :typed? (not= constants/web3-personal-sign method)}}
{:tx-obj (first params)})
{:message {:address address :data data :typed? (not= constants/web3-personal-sign method)
:from dapps-address}}
{:tx-obj (update (first params) :from #(or % dapps-address))})
{:on-result [:browser.dapp/transaction-on-result message-id id]
:on-error [:browser.dapp/transaction-on-error message-id]}))))
{:browser/call-rpc [payload
#(re-frame/dispatch [:browser.callback/call-rpc
{:type constants/web3-send-async-callback
:messageId message-id
:error %1
:result %2}])]})))

(fx/defn send-to-bridge
[cofx message]
{:browser/send-to-bridge {:message message
:webview (get-in cofx [:db :webview-bridge])}})
(if (#{"eth_accounts" "eth_coinbase"} method)
(send-to-bridge cofx {:type constants/web3-send-async-callback
:messageId message-id
:result {:jsonrpc "2.0"
:id (int id)
:result (if (= method "eth_coinbase") dapps-address [dapps-address])}})
{:browser/call-rpc [payload
#(re-frame/dispatch [:browser.callback/call-rpc
{:type constants/web3-send-async-callback
:messageId message-id
:error %1
:result %2}])]}))))

(fx/defn web3-send-async-read-only
[{:keys [db] :as cofx} dapp-name {:keys [method] :as payload} message-id]
Expand Down Expand Up @@ -437,7 +447,24 @@
(fn [link]
(list-selection/browse-in-web-browser link)))

(re-frame/reg-fx
:browser/clear-web-data
(fn []
(status/clear-web-data)))

(defn share-link [url]
(let [link (universal-links/generate-link :browse :external url)
message (i18n/label :t/share-dapp-text {:link link})]
(list-selection/open-share {:message message})))

(fx/defn dapps-account-selected
{:events [:dapps-account-selected]}
[{:keys [db] :as cofx} address]
(fx/merge cofx
{:browser/clear-web-data nil}
(bottom-sheet/hide-bottom-sheet)
(browser.permissions/clear-dapps-permissions)
(multiaccounts.update/multiaccount-update {:dapps-address address} {})
#(when (= (:view-id db) :browser)
(merge (navigation/navigate-back %)
{:dispatch [:browser.ui/browser-item-selected (get-in db [:browser/options :browser-id])]}))))
21 changes: 15 additions & 6 deletions src/status_im/browser/permissions.cljs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(ns status-im.browser.permissions
(:require [status-im.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.i18n :as i18n]
[status-im.qr-scanner.core :as qr-scanner]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.fx :as fx]
[status-im.ethereum.core :as ethereum]))
[status-im.utils.fx :as fx]))

(declare process-next-permission)
(declare send-response-to-bridge)

(def supported-permissions
{constants/dapp-permission-qr-code {:yield-control? true
:allowed? true}
constants/dapp-permission-contact-code {:title (i18n/label :t/wants-to-access-profile)
constants/dapp-permission-contact-code {:type :profile
:title (i18n/label :t/wants-to-access-profile)
:description (i18n/label :t/your-contact-code)
:icon :main-icons/profile}
constants/dapp-permission-web3 {:title (i18n/label :t/dapp-would-like-to-connect-wallet)
constants/dapp-permission-web3 {:type :wallet
:title (i18n/label :t/dapp-would-like-to-connect-wallet)
:description (i18n/label :t/allowing-authorizes-this-dapp)
:icon :main-icons/wallet}})

Expand All @@ -44,7 +44,7 @@
(defn get-permission-data [cofx allowed-permission]
(let [multiaccount (get-in cofx [:db :multiaccount])]
(get {constants/dapp-permission-contact-code (:public-key multiaccount)
constants/dapp-permission-web3 [(:address (ethereum/get-default-account (:accounts multiaccount)))]}
constants/dapp-permission-web3 [(:dapps-address multiaccount)]}
allowed-permission)))

(fx/defn send-response-to-bridge
Expand Down Expand Up @@ -81,6 +81,15 @@
:on-success #()}]}
(navigation/navigate-back)))

(fx/defn clear-dapps-permissions
[{:keys [db]}]
(let [dapp-permissions (keys (:dapps/permissions db))]
{:db (dissoc db :dapps/permissions)
::json-rpc/call (for [dapp dapp-permissions]
{:method "permissions_deleteDappPermissions"
:params [dapp]
:on-success #()})}))

(fx/defn process-next-permission
"Process next permission by removing it from pending permissions and prompting user
if there is no pending permissions left, save all granted permissions
Expand Down
2 changes: 2 additions & 0 deletions src/status_im/multiaccounts/create/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
:photo-path photo-path
; public key of the chat account
:public-key publicKey
; default address for Dapps
:dapps-address (:address wallet-account)
:latest-derived-path 0
:accounts [wallet-account]
:signing-phrase signing-phrase
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@

(fx/defn sign-message
[{{:signing/keys [sign tx] :as db} :db}]
(let [{{:keys [data typed?]} :message} tx
(let [{{:keys [data typed? from]} :message} tx
{:keys [in-progress? password]} sign
from (ethereum/default-address db)
from (or from (ethereum/default-address db))
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
(when-not in-progress?
(merge
Expand Down
13 changes: 13 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@
(or (get sett :log-level)
config/log-level-status-go)))

(re-frame/reg-sub
:dapps-address
:<- [:multiaccount]
(fn [acc]
(get acc :dapps-address)))

(re-frame/reg-sub
:dapps-account
:<- [:multiaccount]
:<- [:dapps-address]
(fn [[acc address]]
(some #(when (= (:address %) address) %) (:accounts acc))))

;;CHAT ==============================================================================================================

(re-frame/reg-sub
Expand Down
10 changes: 5 additions & 5 deletions src/status_im/ui/components/bottom_sheet/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@
height content on-cancel]
:or {on-cancel #(re-frame/dispatch [:bottom-sheet/hide])}
:as opts}]
[react/keyboard-avoiding-view
(merge
(pan-handlers (swipe-pan-responder opts))
{:style styles/container})
[react/keyboard-avoiding-view {:style styles/container}
[react/touchable-highlight
{:on-press #(cancel opts on-cancel)
:style styles/container}

[react/animated-view (styles/shadow opacity-value)]]
[react/animated-view
{:style (styles/content-container height bottom-value)}
[react/view styles/content-header
[react/view
(merge
(pan-handlers (swipe-pan-responder opts))
{:style styles/content-header})
[react/view styles/handle]]
[react/view {:style {:flex 1
:height height}}
Expand Down
19 changes: 14 additions & 5 deletions src/status_im/ui/components/button.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.utils.label :as utils.label]))

(defn style-container [type disabled?]
(defn style-container [type disabled? theme]
(merge
(when (= type :main)
{:margin-vertical 8 :margin-horizontal 16})
Expand All @@ -24,7 +24,10 @@
disabled?
colors/gray-transparent-10
(= type :main)
colors/blue-transparent-10
(case theme
:red colors/red-transparent-10
:green colors/green-transparent-10
colors/blue-transparent-10)
:else
"")}))

Expand All @@ -34,6 +37,9 @@
'type'
:main (default), :secondary, :next, :previous
`theme`
:blue (default), :green, :red
`label`
Any one of string, keyword representing translated string in the form of :t/{translation-key-in-translation-files}
Expand All @@ -45,12 +51,12 @@
Spec: https://www.figma.com/file/cb4p8AxLtTF3q1L6JYDnKN15/Index?node-id=858%3A0"

[{:keys [label type disabled? on-press accessibility-label style] :or {type :main}}]
[{:keys [label type theme disabled? on-press accessibility-label style] :or {type :main theme :blue}}]
(let [label (utils.label/stringify label)]
[react/touchable-opacity (merge {:on-press on-press :disabled disabled? :active-pacity 0.5 :style style}
(when accessibility-label
{:accessibility-label accessibility-label}))
[react/view {:style (style-container type disabled?)}
[react/view {:style (style-container type disabled? theme)}
[react/view {:flex-direction :row :align-items :center}
(when (= type :previous)
[vector-icons/icon :main-icons/back {:container-style {:width 24 :height 24 :margin-right 4}
Expand All @@ -59,7 +65,10 @@
disabled?
colors/gray
(#{:main :secondary :next :previous} type)
colors/blue
(case theme
:green colors/green
:red colors/red
colors/blue)
:else
"")}}
label]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ui/components/list_item/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
:padding-bottom (if (= type :section-header) 4 10)
:align-items :center}
(when selected?
{:background-color colors/gray-transparent-40})))
{:background-color colors/blue-light})))

(def icon-column-container
{:margin-right 14
Expand Down
Loading

0 comments on commit df098f8

Please sign in to comment.