[#12161] Missing delete wallet option

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-08-13 09:53:40 +02:00
parent 19f3e79ec1
commit d1666a42de
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
10 changed files with 141 additions and 32 deletions

View File

@ -1294,8 +1294,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void deleteMultiaccount(final String keyUID, final Callback callback) {
Log.d(TAG, "deleteMultiaccount");
@ -1317,6 +1315,27 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void deleteImportedKey(final String keyUID, final String address, final String password, final Callback callback) {
Log.d(TAG, "deleteImportedKey");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
final String keyStoreDir = this.getKeyStorePath(keyUID);
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.deleteImportedKey(address, password, keyStoreDir);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod(isBlockingSynchronousMethod = true)
public String generateAlias(final String seed) {
return Statusgo.generateAlias(seed);

View File

@ -204,13 +204,26 @@ RCT_EXPORT_METHOD(addPeer:(NSString *)enode
RCT_EXPORT_METHOD(deleteMultiaccount:(NSString *)keyUID
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"MultiAccountImportPrivateKey() method called");
NSLog(@"DeleteMultiaccount() method called");
#endif
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
NSString *result = StatusgoDeleteMultiaccount(keyUID, multiaccountKeystoreDir.path);
callback(@[result]);
}
////////////////////////////////////verify//////////////////////////////// multiAccountImportPrivateKey
RCT_EXPORT_METHOD(deleteImportedKey:(NSString *)keyUID
address:(NSString *)address
password:(NSString *)password
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"DeleteImportedKey() method called");
#endif
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
NSString *result = StatusgoDeleteImportedKey(address, password, multiaccountKeystoreDir.path);
callback(@[result]);
}
//////////////////////////////////////////////////////////////////// multiAccountGenerateAndDeriveAddresses
RCT_EXPORT_METHOD(multiAccountGenerateAndDeriveAddresses:(NSString *)json
callback:(RCTResponseSenderBlock)callback) {

View File

@ -6,9 +6,7 @@
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]
[status-im.keycard.common :as common]
[status-im.native-module.core :as native-module]
[status-im.utils.types :as types]
[clojure.string :as string]))
[status-im.multiaccounts.key-storage.core :as key-storage]))
(fx/defn unpair-card-pressed
{:events [:keycard-settings.ui/unpair-card-pressed]}
@ -127,16 +125,12 @@
:keycard/persist-pairings (dissoc pairings (keyword instance-uid))
:utils/show-popup {:title (i18n/label (if keys-removed-from-card? :t/profile-deleted-title :t/database-reset-title))
:content (i18n/label (if keys-removed-from-card? :t/profile-deleted-keycard :t/database-reset-content))
:on-dismiss #(re-frame/dispatch [:logout])}}
:on-dismiss #(re-frame/dispatch [:logout])}
::key-storage/delete-multiaccount {:key-uid key-uid
:on-success #(log/debug "[keycard] remove account ok")
:on-error #(log/warn "[keycard] remove account: " %)}}
(common/clear-on-card-connected)
(common/hide-connection-sheet)
(native-module/delete-multiaccount
key-uid
(fn [result]
(let [{:keys [error]} (types/json->clj result)]
(if-not (string/blank? error)
(log/warn "[keycard] remove account: " error)
(log/debug "[keycard] remove account ok"))))))))
(common/hide-connection-sheet))))
(fx/defn on-remove-key-success
{:events [:keycard.callback/on-remove-key-success]}

View File

@ -140,6 +140,20 @@
(on-error error)
(on-success)))))))
(re-frame/reg-fx
::delete-imported-key
(fn [{:keys [key-uid address password on-success on-error]}]
(let [hashed-pass (ethereum/sha3 (security/safe-unmask-data password))]
(native-module/delete-imported-key
key-uid
(string/lower-case (subs address 2))
hashed-pass
(fn [result]
(let [{:keys [error]} (types/json->clj result)]
(if-not (string/blank? error)
(on-error error)
(on-success))))))))
(fx/defn delete-multiaccount-and-init-keycard-onboarding
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
[{:keys [db] :as cofx}]

View File

@ -400,6 +400,12 @@
(log/debug "[native-module] delete-multiaccount")
(.deleteMultiaccount ^js (status) key-uid callback))
(defn delete-imported-key
"Delete imported key file."
[key-uid address hashed-password callback]
(log/debug "[native-module] delete-imported-key")
(.deleteImportedKey ^js (status) key-uid address hashed-password callback))
(defn activate-keep-awake []
(log/debug "[native-module] activateKeepAwake")
(.activateKeepAwake ^js (status)))

View File

@ -8,7 +8,8 @@
[status-im.ui.components.colors :as colors]
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.utils.money :as money]))
[status-im.utils.money :as money]
[status-im.utils.utils :as utils]))
(defn- final-status? [command-state]
(or (= command-state constants/command-state-request-address-for-transaction-declined)
@ -39,7 +40,11 @@
(if (and (or (= command-state constants/command-state-request-transaction)
(= command-state constants/command-state-request-address-for-transaction-accepted))
(= direction :incoming))
(str (i18n/label :t/shared) " '" (:name @(re-frame/subscribe [:account-by-address to])) "'")
(str (i18n/label :t/shared)
" '"
(or (:name @(re-frame/subscribe [:account-by-address to]))
(utils/get-shortened-checksum-address to))
"'")
(i18n/label (cond
(= command-state constants/command-state-transaction-pending)
:t/status-pending

View File

@ -9,7 +9,44 @@
[status-im.ui.components.copyable-text :as copyable-text]
[reagent.core :as reagent]
[quo.core :as quo]
[status-im.ui.components.topbar :as topbar]))
[status-im.ui.components.topbar :as topbar]
[status-im.utils.security :as security]))
(defn not-valid-password? [password]
(< (count (security/safe-unmask-data password)) 6))
(defn delete-account [_]
(let [password (reagent/atom nil)
text-input-ref (atom nil)
error (reagent/atom nil)]
(fn [account]
(when (and @text-input-ref error (not @password))
(.clear ^js @text-input-ref))
[react/view {:padding 20 :width 300}
[quo/text-input
{:style {:margin-bottom 40}
:label (i18n/label :t/password)
:show-cancel false
:secure-text-entry true
:return-key-type :next
:on-submit-editing nil
:auto-focus true
:on-change-text #(reset! password (security/mask-data %))
:get-ref #(reset! text-input-ref %)
:error (when (and @error (not @password))
(if (= :wrong-password @error)
(i18n/label :t/wrong-password)
(str @error)))}]
[quo/button {:on-press (fn []
(re-frame/dispatch [:wallet.accounts/delete-key
account
@password
#(reset! error :wrong-password)])
(reset! password nil))
:theme :negative
:accessibility-label :delete-account-confirm
:disabled (not-valid-password? @password)}
(i18n/label :t/delete)]])))
(defview colors-popover [selected-color on-press]
(letsubs [width [:dimensions/window-width]]
@ -19,8 +56,8 @@
(for [color colors/account-colors]
^{:key color}
[react/touchable-highlight {:on-press #(on-press color)}
[react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width)
:justify-content :center :padding-left 12 :margin-bottom 16}
[react/view {:height 52 :background-color color :border-radius 8 :width (* 0.7 width)
:justify-content :center :padding-left 12 :margin-bottom 16}
[react/view {:height 32 :width 32 :border-radius 20 :align-items :center :justify-content :center
:background-color colors/black-transparent}
(when (= selected-color color)
@ -42,7 +79,7 @@
(letsubs [{:keys [address color path type] :as account} [:multiaccount/current-account]
new-account (reagent/atom nil)
keycard? [:keycard-multiaccount?]]
[react/keyboard-avoiding-view {:style {:flex 1}
[react/keyboard-avoiding-view {:style {:flex 1}
:ignore-offset true}
[topbar/topbar
(cond-> {:title (i18n/label :t/account-settings)}
@ -72,13 +109,13 @@
(swap! new-account assoc :color new-color)
(re-frame/dispatch [:hide-popover]))]
:style {:max-height "60%"}}])}
[react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color)
[react/view {:height 52 :margin-top 12 :background-color (or (:color @new-account) color)
:border-radius 8
:align-items :flex-end :justify-content :center :padding-right 12}
:align-items :flex-end :justify-content :center :padding-right 12}
[icons/icon :main-icons/dropdown {:color colors/white}]]]
[property (i18n/label :t/type)
(case type
:watch (i18n/label :t/watch-only)
:watch (i18n/label :t/watch-only)
(:key :seed) (i18n/label :t/off-status-tree)
(i18n/label :t/on-status-tree))]
[property (i18n/label :t/wallet-address)
@ -98,10 +135,12 @@
(i18n/label (if keycard?
:t/keycard
:t/this-device))])]
(when (= type :watch)
(when (#{:key :seed :watch} type)
[react/view
[react/view {:margin-bottom 8 :margin-top 28 :height 1 :background-color colors/gray-lighter}]
[quo/list-item
{:theme :negative
:title (i18n/label :t/delete-account)
:on-press #(re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account])}]])]]]))
:on-press #(if (= :watch type)
(re-frame/dispatch [:wallet.settings/show-delete-account-confirmation account])
(re-frame/dispatch [:show-popover {:view [delete-account account]}]))}]])]]]))

View File

@ -24,7 +24,8 @@
[status-im.ethereum.ens :as ens]
[status-im.ens.core :as ens.core]
[status-im.ethereum.resolver :as resolver]
[status-im.utils.mobile-sync :as utils.mobile-sync]))
[status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.multiaccounts.key-storage.core :as key-storage]))
(fx/defn start-adding-new-account
{:events [:wallet.accounts/start-adding-new-account]}
@ -292,7 +293,7 @@
[{:keys [db] :as cofx} account]
(let [accounts (:multiaccount/accounts db)
new-accounts (vec (remove #(= account %) accounts))
deleted-address (get-in account [:address])]
deleted-address (:address account)]
(fx/merge cofx
{::json-rpc/call [{:method "accounts_deleteAccount"
:params [(:address account)]
@ -302,6 +303,23 @@
(update-in [:wallet :accounts] dissoc deleted-address))}
(navigation/pop-to-root-tab :wallet-stack))))
(fx/defn delete-account-key
{:events [:wallet.accounts/delete-key]}
[{:keys [db] :as cofx} account password on-error]
(let [deleted-address (:address account)
dapps-address (get-in cofx [:db :multiaccount :dapps-address])]
(if (= (string/lower-case dapps-address) (string/lower-case deleted-address))
{:utils/show-popup {:title (i18n/label :t/warning)
:content (i18n/label :t/account-is-used)}}
{::key-storage/delete-imported-key
{:key-uid (get-in db [:multiaccount :key-uid])
:address (:address account)
:password password
:on-success #(do
(re-frame/dispatch [:hide-popover])
(re-frame/dispatch [:wallet.accounts/delete-account account]))
:on-error on-error}})))
(fx/defn view-only-qr-scanner-result
{:events [:wallet.add-new/qr-scanner-result]}
[{db :db :as cofx} data _]

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.83.11",
"commit-sha1": "fc16588cf1b37a6aea473404495782ca9e0cfff8",
"src-sha256": "0gh0v1v3hcxq99i0szwp8y5395xfcdj920wg2p707s8j3vwrb325"
"version": "v0.83.12",
"commit-sha1": "bc63fa606ea45c5ee3cff835a7a85c99ad35db23",
"src-sha256": "13504xk3lmn9s5dxx6b7nscrbca0b67sq6z3pb00g346mghyb8vq"
}

View File

@ -1647,5 +1647,6 @@
"include": "Include",
"category": "Category",
"edit-chats": "Edit chats",
"hide": "Hide"
"hide": "Hide",
"account-is-used": "The account is being used with Dapps in the browser."
}