|
18 | 18 |
|
19 | 19 | (rf/reg-event-fx :wallet/show-account-created-toast
|
20 | 20 | (fn [{:keys [db]} [address]]
|
21 |
| - (let [{:keys [name]} (get-in db [:wallet :accounts address])] |
| 21 | + (let [account (get-in db [:wallet :accounts address])] |
22 | 22 | {:db (update db :wallet dissoc :navigate-to-account :new-account?)
|
23 | 23 | :fx [[:dispatch
|
24 | 24 | [:toasts/upsert
|
25 | 25 | {:id :new-wallet-account-created
|
26 | 26 | :icon :i/correct
|
27 | 27 | :icon-color colors/success-50
|
28 |
| - :text (i18n/label :t/account-created {:name name})}]]]}))) |
| 28 | + :text (i18n/label :t/account-created {:name (:name account)})}]]]}))) |
29 | 29 |
|
30 | 30 | (rf/reg-event-fx :wallet/navigate-to-account
|
31 | 31 | (fn [{:keys [db]} [address]]
|
32 |
| - (let [new-account? (get-in db [:wallet :new-account?])] |
33 |
| - (cond-> {:db (assoc-in db [:wallet :current-viewing-account-address] address) |
34 |
| - :fx [[:dispatch [:navigate-to :wallet-accounts address]]]} |
| 32 | + {:db (assoc-in db [:wallet :current-viewing-account-address] address) |
| 33 | + :fx [[:dispatch [:navigate-to :wallet-accounts address]]]})) |
35 | 34 |
|
36 |
| - new-account? |
37 |
| - (update :fx conj [:dispatch [:wallet/show-account-created-toast address]]))))) |
| 35 | +(rf/reg-event-fx :wallet/navigate-to-new-account |
| 36 | + (fn [{:keys [db]} [address]] |
| 37 | + {:db (assoc-in db [:wallet :current-viewing-account-address] address) |
| 38 | + :fx [[:dispatch [:hide-bottom-sheet]] |
| 39 | + [:dispatch-later |
| 40 | + [{:dispatch [:navigate-back] |
| 41 | + :ms 100} |
| 42 | + {:dispatch [:navigate-back] |
| 43 | + :ms 100} |
| 44 | + {:dispatch [:navigate-to :wallet-accounts address] |
| 45 | + :ms 300}]] |
| 46 | + [:dispatch [:wallet/show-account-created-toast address]]]})) |
38 | 47 |
|
39 | 48 | (rf/reg-event-fx :wallet/close-account-page
|
40 | 49 | (fn [{:keys [db]}]
|
|
44 | 53 | (rf/reg-event-fx
|
45 | 54 | :wallet/get-accounts-success
|
46 | 55 | (fn [{:keys [db]} [accounts]]
|
47 |
| - (let [wallet-db (get db :wallet) |
| 56 | + (let [wallet-accounts (filter #(not (:chat %)) accounts) |
| 57 | + wallet-db (get db :wallet) |
48 | 58 | new-account? (:new-account? wallet-db)
|
49 | 59 | navigate-to-account (:navigate-to-account wallet-db)]
|
50 |
| - (cond-> {:db (reduce (fn [db {:keys [address] :as account}] |
51 |
| - (assoc-in db [:wallet :accounts address] account)) |
52 |
| - db |
53 |
| - (data-store/rpc->accounts accounts)) |
54 |
| - :fx [[:dispatch [:wallet/get-wallet-token]]]} |
55 |
| - |
56 |
| - new-account? |
57 |
| - (update :fx |
58 |
| - conj |
59 |
| - [:dispatch [:hide-bottom-sheet]] |
60 |
| - [:dispatch-later |
61 |
| - [{:dispatch [:navigate-back] |
62 |
| - :ms 100} |
63 |
| - {:dispatch [:wallet/navigate-to-account navigate-to-account] |
64 |
| - :ms 300}]]))))) |
| 60 | + {:db (reduce (fn [db {:keys [address] :as account}] |
| 61 | + (assoc-in db [:wallet :accounts address] account)) |
| 62 | + db |
| 63 | + (data-store/rpc->accounts wallet-accounts)) |
| 64 | + :fx [[:dispatch [:wallet/get-wallet-token]] |
| 65 | + (when new-account? |
| 66 | + [:dispatch [:wallet/navigate-to-new-account navigate-to-account]])]}))) |
65 | 67 |
|
66 | 68 | (rf/reg-event-fx
|
67 | 69 | :wallet/get-accounts
|
|
144 | 146 | :on-success on-success
|
145 | 147 | :on-error #(log/info "failed to derive address " %)}]]]})))
|
146 | 148 |
|
147 |
| -(rf/reg-event-fx |
148 |
| - :wallet/add-account |
149 |
| - (fn [{:keys [db]} [password {:keys [emoji account-name color]} {:keys [public-key address path]}]] |
150 |
| - (let [key-uid (get-in db [:profile/profile :key-uid]) |
151 |
| - sha3-pwd (native-module/sha3 (security/safe-unmask-data password)) |
152 |
| - account-config {:key-uid key-uid |
153 |
| - :wallet false |
154 |
| - :chat false |
155 |
| - :type :generated |
156 |
| - :name account-name |
157 |
| - :emoji emoji |
158 |
| - :path path |
159 |
| - :address address |
160 |
| - :public-key public-key |
161 |
| - :colorID color}] |
162 |
| - {:db (update db |
163 |
| - :wallet assoc |
164 |
| - :navigate-to-account address |
165 |
| - :new-account? true) |
166 |
| - :fx [[:json-rpc/call |
| 149 | +(rf/reg-event-fx :wallet/add-account-success |
| 150 | + (fn [{:keys [db]} [address]] |
| 151 | + {:db (update db |
| 152 | + :wallet assoc |
| 153 | + :navigate-to-account address |
| 154 | + :new-account? true) |
| 155 | + :fx [[:dispatch [:wallet/get-accounts]]]})) |
| 156 | + |
| 157 | +(rf/reg-event-fx :wallet/add-account |
| 158 | + (fn [{:keys [db]} |
| 159 | + [password {:keys [emoji account-name color type] :or {type :generated}} |
| 160 | + {:keys [public-key address path]}]] |
| 161 | + (let [lowercase-address (if address (string/lower-case address) address) |
| 162 | + key-uid (get-in db [:profile/profile :key-uid]) |
| 163 | + sha3-pwd (native-module/sha3 (security/safe-unmask-data password)) |
| 164 | + account-config {:key-uid (when (= type :generated) key-uid) |
| 165 | + :wallet false |
| 166 | + :chat false |
| 167 | + :type type |
| 168 | + :name account-name |
| 169 | + :emoji emoji |
| 170 | + :path path |
| 171 | + :address lowercase-address |
| 172 | + :public-key public-key |
| 173 | + :colorID color}] |
| 174 | + {:fx [[:json-rpc/call |
167 | 175 | [{:method "accounts_addAccount"
|
168 |
| - :params [sha3-pwd account-config] |
169 |
| - :on-success [:wallet/get-accounts] |
| 176 | + :params [(when (= type :generated) sha3-pwd) account-config] |
| 177 | + :on-success [:wallet/add-account-success lowercase-address] |
170 | 178 | :on-error #(log/info "failed to create account " %)}]]]})))
|
171 | 179 |
|
172 | 180 | (rf/reg-event-fx
|
|
0 commit comments