Skip to content

Commit 387aa94

Browse files
committed
[#12161] Missing delete wallet option
1 parent ad9dc99 commit 387aa94

File tree

10 files changed

+149
-40
lines changed

10 files changed

+149
-40
lines changed

modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,6 @@ public void run() {
12941294
StatusThreadPoolExecutor.getInstance().execute(r);
12951295
}
12961296

1297-
1298-
12991297
@ReactMethod
13001298
public void deleteMultiaccount(final String keyUID, final Callback callback) {
13011299
Log.d(TAG, "deleteMultiaccount");
@@ -1317,6 +1315,27 @@ public void run() {
13171315
StatusThreadPoolExecutor.getInstance().execute(r);
13181316
}
13191317

1318+
@ReactMethod
1319+
public void deleteImportedKey(final String keyUID, final String address, final String password, final Callback callback) {
1320+
Log.d(TAG, "deleteImportedKey");
1321+
if (!checkAvailability()) {
1322+
callback.invoke(false);
1323+
return;
1324+
}
1325+
1326+
final String keyStoreDir = this.getKeyStorePath(keyUID);
1327+
Runnable r = new Runnable() {
1328+
@Override
1329+
public void run() {
1330+
String res = Statusgo.deleteImportedKey(address, password, keyStoreDir);
1331+
1332+
callback.invoke(res);
1333+
}
1334+
};
1335+
1336+
StatusThreadPoolExecutor.getInstance().execute(r);
1337+
}
1338+
13201339
@ReactMethod(isBlockingSynchronousMethod = true)
13211340
public String generateAlias(final String seed) {
13221341
return Statusgo.generateAlias(seed);

modules/react-native-status/ios/RCTStatus/RCTStatus.m

+14-1
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,26 @@ - (void)handleSignal:(NSString *)signal
204204
RCT_EXPORT_METHOD(deleteMultiaccount:(NSString *)keyUID
205205
callback:(RCTResponseSenderBlock)callback) {
206206
#if DEBUG
207-
NSLog(@"MultiAccountImportPrivateKey() method called");
207+
NSLog(@"DeleteMultiaccount() method called");
208208
#endif
209209
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
210210
NSString *result = StatusgoDeleteMultiaccount(keyUID, multiaccountKeystoreDir.path);
211211
callback(@[result]);
212212
}
213213

214+
////////////////////////////////////verify//////////////////////////////// multiAccountImportPrivateKey
215+
RCT_EXPORT_METHOD(deleteImportedKey:(NSString *)keyUID
216+
address:(NSString *)address
217+
password:(NSString *)password
218+
callback:(RCTResponseSenderBlock)callback) {
219+
#if DEBUG
220+
NSLog(@"DeleteImportedKey() method called");
221+
#endif
222+
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
223+
NSString *result = StatusgoDeleteImportedKey(address, password, multiaccountKeystoreDir.path);
224+
callback(@[result]);
225+
}
226+
214227
//////////////////////////////////////////////////////////////////// multiAccountGenerateAndDeriveAddresses
215228
RCT_EXPORT_METHOD(multiAccountGenerateAndDeriveAddresses:(NSString *)json
216229
callback:(RCTResponseSenderBlock)callback) {

src/status_im/keycard/unpair.cljs

+6-12
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
[status-im.utils.fx :as fx]
77
[taoensso.timbre :as log]
88
[status-im.keycard.common :as common]
9-
[status-im.native-module.core :as native-module]
10-
[status-im.utils.types :as types]
11-
[clojure.string :as string]))
9+
[status-im.multiaccounts.key-storage.core :as key-storage]))
1210

1311
(fx/defn unpair-card-pressed
1412
{:events [:keycard-settings.ui/unpair-card-pressed]}
@@ -127,16 +125,12 @@
127125
:keycard/persist-pairings (dissoc pairings (keyword instance-uid))
128126
:utils/show-popup {:title (i18n/label (if keys-removed-from-card? :t/profile-deleted-title :t/database-reset-title))
129127
:content (i18n/label (if keys-removed-from-card? :t/profile-deleted-keycard :t/database-reset-content))
130-
:on-dismiss #(re-frame/dispatch [:logout])}}
128+
:on-dismiss #(re-frame/dispatch [:logout])}
129+
::key-storage/delete-multiaccount {:key-uid key-uid
130+
:on-success #(log/debug "[keycard] remove account ok")
131+
:on-error #(log/warn "[keycard] remove account: " %)}}
131132
(common/clear-on-card-connected)
132-
(common/hide-connection-sheet)
133-
(native-module/delete-multiaccount
134-
key-uid
135-
(fn [result]
136-
(let [{:keys [error]} (types/json->clj result)]
137-
(if-not (string/blank? error)
138-
(log/warn "[keycard] remove account: " error)
139-
(log/debug "[keycard] remove account ok"))))))))
133+
(common/hide-connection-sheet))))
140134

141135
(fx/defn on-remove-key-success
142136
{:events [:keycard.callback/on-remove-key-success]}

src/status_im/multiaccounts/key_storage/core.cljs

+14
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@
140140
(on-error error)
141141
(on-success)))))))
142142

143+
(re-frame/reg-fx
144+
::delete-imported-key
145+
(fn [{:keys [key-uid address password on-success on-error]}]
146+
(let [hashed-pass (ethereum/sha3 (security/safe-unmask-data password))]
147+
(native-module/delete-imported-key
148+
key-uid
149+
(string/lower-case (subs address 2))
150+
hashed-pass
151+
(fn [result]
152+
(let [{:keys [error]} (types/json->clj result)]
153+
(if-not (string/blank? error)
154+
(on-error error)
155+
(on-success))))))))
156+
143157
(fx/defn delete-multiaccount-and-init-keycard-onboarding
144158
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
145159
[{:keys [db] :as cofx}]

src/status_im/native_module/core.cljs

+6
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@
400400
(log/debug "[native-module] delete-multiaccount")
401401
(.deleteMultiaccount ^js (status) key-uid callback))
402402

403+
(defn delete-imported-key
404+
"Delete imported key file."
405+
[key-uid address hashed-password callback]
406+
(log/debug "[native-module] delete-imported-key")
407+
(.deleteImportedKey ^js (status) key-uid address hashed-password callback))
408+
403409
(defn activate-keep-awake []
404410
(log/debug "[native-module] activateKeepAwake")
405411
(.activateKeepAwake ^js (status)))

src/status_im/ui/screens/chat/message/command.cljs

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[status-im.ui.components.colors :as colors]
99
[status-im.ui.components.icons.icons :as icons]
1010
[status-im.ui.components.react :as react]
11-
[status-im.utils.money :as money]))
11+
[status-im.utils.money :as money]
12+
[status-im.utils.utils :as utils]))
1213

1314
(defn- final-status? [command-state]
1415
(or (= command-state constants/command-state-request-address-for-transaction-declined)
@@ -39,7 +40,11 @@
3940
(if (and (or (= command-state constants/command-state-request-transaction)
4041
(= command-state constants/command-state-request-address-for-transaction-accepted))
4142
(= direction :incoming))
42-
(str (i18n/label :t/shared) " '" (:name @(re-frame/subscribe [:account-by-address to])) "'")
43+
(str (i18n/label :t/shared)
44+
" '"
45+
(or (:name @(re-frame/subscribe [:account-by-address to]))
46+
(utils/get-shortened-checksum-address to))
47+
"'")
4348
(i18n/label (cond
4449
(= command-state constants/command-state-transaction-pending)
4550
:t/status-pending

src/status_im/ui/screens/wallet/account_settings/views.cljs

+56-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,44 @@
99
[status-im.ui.components.copyable-text :as copyable-text]
1010
[reagent.core :as reagent]
1111
[quo.core :as quo]
12-
[status-im.ui.components.topbar :as topbar]))
12+
[status-im.ui.components.topbar :as topbar]
13+
[status-im.utils.security :as security]))
14+
15+
(defn not-valid-password? [password]
16+
(< (count (security/safe-unmask-data password)) 6))
17+
18+
(defn delete-account [_]
19+
(let [password (reagent/atom nil)
20+
text-input-ref (atom nil)
21+
error (reagent/atom nil)]
22+
(fn [account]
23+
(when (and @text-input-ref error (not @password))
24+
(.clear ^js @text-input-ref))
25+
[react/view {:padding 20 :width 300}
26+
[quo/text-input
27+
{:style {:margin-bottom 40}
28+
:label (i18n/label :t/password)
29+
:show-cancel false
30+
:secure-text-entry true
31+
:return-key-type :next
32+
:on-submit-editing nil
33+
:auto-focus true
34+
:on-change-text #(reset! password (security/mask-data %))
35+
:get-ref #(reset! text-input-ref %)
36+
:error (when (and @error (not @password))
37+
(if (= :wrong-password @error)
38+
(i18n/label :t/wrong-password)
39+
(str @error)))}]
40+
[quo/button {:on-press (fn []
41+
(re-frame/dispatch [:wallet.accounts/delete-key
42+
account
43+
@password
44+
#(reset! error :wrong-password)])
45+
(reset! password nil))
46+
:theme :negative
47+
:accessibility-label :delete-account-confirm
48+
:disabled (not-valid-password? @password)}
49+
(i18n/label :t/delete)]])))
1350

1451
(defview colors-popover [selected-color on-press]
1552
(letsubs [width [:dimensions/window-width]]
@@ -19,8 +56,8 @@
1956
(for [color colors/account-colors]
2057
^{:key color}
2158
[react/touchable-highlight {:on-press #(on-press color)}
22-
[react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width)
23-
:justify-content :center :padding-left 12 :margin-bottom 16}
59+
[react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width)
60+
:justify-content :center :padding-left 12 :margin-bottom 16}
2461
[react/view {:height 32 :width 32 :border-radius 20 :align-items :center :justify-content :center
2562
:background-color colors/black-transparent}
2663
(when (= selected-color color)
@@ -42,18 +79,18 @@
4279
(letsubs [{:keys [address color path type] :as account} [:multiaccount/current-account]
4380
new-account (reagent/atom nil)
4481
keycard? [:keycard-multiaccount?]]
45-
[react/keyboard-avoiding-view {:style {:flex 1}
82+
[react/keyboard-avoiding-view {:style {:flex 1}
4683
:ignore-offset true}
4784
[topbar/topbar
4885
(cond-> {:title (i18n/label :t/account-settings)}
49-
(and @new-account (not= "" (:name @new-account)))
50-
(assoc :right-accessories [{:label (i18n/label :t/apply)
51-
:on-press
52-
#(do
53-
(re-frame/dispatch [:wallet.accounts/save-account
54-
account
55-
@new-account])
56-
(reset! new-account nil))}]))]
86+
(and @new-account (not= "" (:name @new-account)))
87+
(assoc :right-accessories [{:label (i18n/label :t/apply)
88+
:on-press
89+
#(do
90+
(re-frame/dispatch [:wallet.accounts/save-account
91+
account
92+
@new-account])
93+
(reset! new-account nil))}]))]
5794
[react/scroll-view {:keyboard-should-persist-taps :handled
5895
:style {:flex 1}}
5996
[react/view {:padding-bottom 28 :padding-top 10}
@@ -72,13 +109,13 @@
72109
(swap! new-account assoc :color new-color)
73110
(re-frame/dispatch [:hide-popover]))]
74111
:style {:max-height "60%"}}])}
75-
[react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color)
112+
[react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color)
76113
:border-radius 8
77-
:align-items :flex-end :justify-content :center :padding-right 12}
114+
:align-items :flex-end :justify-content :center :padding-right 12}
78115
[icons/icon :main-icons/dropdown {:color colors/white}]]]
79116
[property (i18n/label :t/type)
80117
(case type
81-
:watch (i18n/label :t/watch-only)
118+
:watch (i18n/label :t/watch-only)
82119
(:key :seed) (i18n/label :t/off-status-tree)
83120
(i18n/label :t/on-status-tree))]
84121
[property (i18n/label :t/wallet-address)
@@ -98,10 +135,12 @@
98135
(i18n/label (if keycard?
99136
:t/keycard
100137
:t/this-device))])]
101-
(when (= type :watch)
138+
(when (#{:key :seed :watch} type)
102139
[react/view
103140
[react/view {:margin-bottom 8 :margin-top 28 :height 1 :background-color colors/gray-lighter}]
104141
[quo/list-item
105142
{:theme :negative
106143
:title (i18n/label :t/delete-account)
107-
:on-press #(re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account])}]])]]]))
144+
:on-press #(if (= :watch type)
145+
(re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account])
146+
(re-frame/dispatch [:show-popover {:view [delete-account account]}]))}]])]]]))

src/status_im/wallet/accounts/core.cljs

+20-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
[status-im.ethereum.ens :as ens]
2525
[status-im.ens.core :as ens.core]
2626
[status-im.ethereum.resolver :as resolver]
27-
[status-im.utils.mobile-sync :as utils.mobile-sync]))
27+
[status-im.utils.mobile-sync :as utils.mobile-sync]
28+
[status-im.multiaccounts.key-storage.core :as key-storage]))
2829

2930
(fx/defn start-adding-new-account
3031
{:events [:wallet.accounts/start-adding-new-account]}
@@ -292,7 +293,7 @@
292293
[{:keys [db] :as cofx} account]
293294
(let [accounts (:multiaccount/accounts db)
294295
new-accounts (vec (remove #(= account %) accounts))
295-
deleted-address (get-in account [:address])]
296+
deleted-address (:address account)]
296297
(fx/merge cofx
297298
{::json-rpc/call [{:method "accounts_deleteAccount"
298299
:params [(:address account)]
@@ -302,6 +303,23 @@
302303
(update-in [:wallet :accounts] dissoc deleted-address))}
303304
(navigation/pop-to-root-tab :wallet-stack))))
304305

306+
(fx/defn delete-account-key
307+
{:events [:wallet.accounts/delete-key]}
308+
[{:keys [db] :as cofx} account password on-error]
309+
(let [deleted-address (:address account)
310+
dapps-address (get-in cofx [:db :multiaccount :dapps-address])]
311+
(if (= (string/lower-case dapps-address) (string/lower-case deleted-address))
312+
{:utils/show-popup {:title (i18n/label :t/warning)
313+
:content (i18n/label :t/account-is-used)}}
314+
{::key-storage/delete-imported-key
315+
{:key-uid (get-in db [:multiaccount :key-uid])
316+
:address (:address account)
317+
:password password
318+
:on-success #(do
319+
(re-frame/dispatch [:hide-popover])
320+
(re-frame/dispatch [:wallet.accounts/delete-account account]))
321+
:on-error on-error}})))
322+
305323
(fx/defn view-only-qr-scanner-result
306324
{:events [:wallet.add-new/qr-scanner-result]}
307325
[{db :db :as cofx} data _]

status-go-version.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
33
"owner": "status-im",
44
"repo": "status-go",
5-
"version": "v0.83.11",
6-
"commit-sha1": "fc16588cf1b37a6aea473404495782ca9e0cfff8",
7-
"src-sha256": "0gh0v1v3hcxq99i0szwp8y5395xfcdj920wg2p707s8j3vwrb325"
5+
"version": "feature/delete-imported-keys",
6+
"commit-sha1": "463c759d92534e7012a274b50709da8bbc46d525",
7+
"src-sha256": "1k7fkjhr4jq6198giz356ins0akmk85xfb9a8fzrv2jirzv4gjia"
88
}

translations/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1647,5 +1647,6 @@
16471647
"include": "Include",
16481648
"category": "Category",
16491649
"edit-chats": "Edit chats",
1650-
"hide": "Hide"
1650+
"hide": "Hide",
1651+
"account-is-used": "The account is being used with Dapps in the browser."
16511652
}

0 commit comments

Comments
 (0)