Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vkjr committed Nov 15, 2023
1 parent 7153e4d commit 5128e2e
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 20 deletions.
6 changes: 4 additions & 2 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,11 @@ - (void) migrateKeystore:(NSString *)accountData
#endif

NSString *filePath = [self getExportDbFilePath];
StatusgoExportUnencryptedDatabase(accountData, password, filePath);
//StatusgoExportUnencryptedDatabase(accountData, password, filePath);
//callback(@[filePath]);

callback(@[filePath]);
NSString *result = StatusgoExportUnencryptedDatabase(accountData, password, filePath);
callback(@[result]);
}

RCT_EXPORT_METHOD(importUnencryptedDatabase:(NSString *)accountData
Expand Down
6 changes: 6 additions & 0 deletions src/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
key-uid
#(.exportUnencryptedDatabase ^js (status) account-data hashed-password callback)))

(defn export-db-2
"NOTE: beware, the password has to be sha3 hashed"
[account-data hashed-password callback]
(log/debug "[native-module] export-db-2")
(.exportUnencryptedDatabase ^js (status) account-data hashed-password callback))

(defn import-db
"NOTE: beware, the password has to be sha3 hashed"
[key-uid account-data hashed-password]
Expand Down
3 changes: 3 additions & 0 deletions src/status_im/ethereum/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
[:wallet/owned-collectibles-filtering-done
event]]]}
"wallet-get-collectibles-details-done" {:fx [[:dispatch
[:wallet/get-collectible-details-done
event]]]}
(log/warn ::unknown-wallet-event :type type :event event)))
47 changes: 47 additions & 0 deletions src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[react-native.platform :as platform]
[status-im.ui.components.react :as react]
[status-im.utils.deprecated-types :as types]
[taoensso.timbre :as log]
[utils.re-frame :as rf]
[utils.security.core :as security]))

Expand All @@ -13,6 +14,11 @@
(fn [[key-uid account-data hashed-password callback]]
(native-module/export-db key-uid account-data hashed-password callback)))

(re-frame/reg-fx
::export-db-2
(fn [[key-uid account-data hashed-password callback]]
(native-module/export-db-2 account-data hashed-password callback)))

(re-frame/reg-fx
::import-db
(fn [[key-uid account-data hashed-password]]
Expand All @@ -22,6 +28,9 @@
{:events [:multiaccounts.login.ui/export-db-submitted]}
[{:keys [db]}]
(let [{:keys [key-uid password name]} (:profile/login db)]
(log/info "=== name" name)
(log/info "=== password" (security/safe-unmask-data password))
(log/info "=== key-uid" key-uid)
{::export-db [key-uid
(types/clj->json {:name name
:key-uid key-uid})
Expand All @@ -33,6 +42,44 @@
(clj->js {:title "Unencrypted database"
:url uri})))))]}))

(rf/defn export-db-submitted-after-login
{:events [:multiaccounts.login.ui/export-db-submitted-after-login]}
[{:keys [db]} password]
(let [{:keys [key-uid]} (:profile/profile db)]
(log/info "=== name" nil)
(log/info "=== password" password)
(log/info "=== key-uid" key-uid)
{::export-db-2 [key-uid
(types/clj->json {:kdfIterations 256000
:key-uid key-uid})
(native-module/sha3 password)
(fn [path]
(when platform/ios?
(let [uri (str "file://" path)]
(.share ^js react/sharing
(clj->js {:title "Unencrypted database"
:url uri})))))]}))

(comment

0x6e6bb77759939511105c87efcce524d3fc389fba23583ada411b62c891c0619a
0x761bd780af40095f2cb44d5cf2d55f84f506779994859a6766d5d706e8a13317
"0x761bd780af40095f2cb44d5cf2d55f84f506779994859a6766d5d706e8a13317"

(rf/dispatch [:multiaccounts.login.ui/export-db-submitted-after-login "*"])
(rf/dispatch [:multiaccounts.login.ui/export-db-submitted])


(native-module/export-db-2
(types/clj->json {:kdfIterations 3200
:key-uid "0x6e6bb77759939511105c87efcce524d3fc389fba23583ada411b62c891c0619a"})
(native-module/sha3 "*")
(fn [result]
(log/info "=== result" result)
))
0x761bd780af40095f2cb44d5cf2d55f84f506779994859a6766d5d706e8a13317
)

(rf/defn import-db-submitted
{:events [:multiaccounts.login.ui/import-db-submitted]}
[{:keys [db]}]
Expand Down
3 changes: 1 addition & 2 deletions src/status_im2/contexts/profile/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

(defn login
[]
{;; Temporary fix until https://github.com/status-im/status-go/issues/3024 is
;; resolved
{;; Temporary fix until https://github.com/status-im/status-go/issues/3024 is resolved
:wakuV2Nameserver "8.8.8.8"
:openseaAPIKey config/opensea-api-key
:poktToken config/POKT_TOKEN
Expand Down
10 changes: 9 additions & 1 deletion src/status_im2/contexts/wallet/collectible/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
{:margin-top 100
:margin-bottom 34})

(def preview
(def preview-container
{:margin-horizontal 8
:margin-top 12})

(def preview
{:width "100%"
:aspect-ratio 1
:border-radius 16})

(def header
{:margin-horizontal 20
:margin-top 16
Expand All @@ -17,6 +22,9 @@
{:flex-direction :row
:margin-top 6})

(def collection-avatar-container
{:margin-right 8})

(def buttons-container
{:flex-direction :row
:align-items :stretch
Expand Down
30 changes: 19 additions & 11 deletions src/status_im2/contexts/wallet/collectible/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
[react-native.core :as rn]
[status-im2.common.scroll-page.view :as scroll-page]
[status-im2.contexts.wallet.collectible.style :as style]
[status-im2.contexts.wallet.common.temp :as temp]
[utils.i18n :as i18n]))
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn header
[{:keys [name description collection-image]}]
[{:keys [name description collection-image-url]}]
[rn/view {:style style/header}
[quo/text
{:weight :semi-bold
:size :heading-1} name]
[rn/view style/collection-container
[quo/collection-avatar {:image collection-image}]
[rn/view {:style style/collection-container}
[rn/view {:style style/collection-avatar-container}
[quo/collection-avatar {:image collection-image-url}]]
[quo/text
{:weight :semi-bold
:size :paragraph-1}
Expand Down Expand Up @@ -103,7 +104,8 @@

(defn view
[]
(let [{:keys [name description image traits] :as props} temp/collectible-details]
(let [collectible-details (rf/sub [:wallet/last-collectible-details])
{:keys [name description preview-url traits]} collectible-details]
[scroll-page/scroll-page
{:navigate-back? true
:height 148
Expand All @@ -112,13 +114,19 @@
:description description
:right-side [{:icon-name :i/options
:on-press #(js/alert "pressed")}]
:picture image}}
:picture preview-url}}
[rn/view {:style style/container}
[rn/image
{:source image
:style style/preview}]
[header props]
[rn/view {:style style/preview-container}
[rn/image
{:source preview-url
:style style/preview}]]
[header collectible-details]
[cta-buttons]
[tabs]
[info]
[traits-section traits]]]))

(comment

(rf/dispatch [:multiaccounts.login.ui/export-db-submitted])
)
10 changes: 6 additions & 4 deletions src/status_im2/contexts/wallet/common/collectibles_tab/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
:style {:flex 1}
:content-container-style {:align-items :center}
:num-columns 2
:render-fn (fn [{:keys [preview-url]}]
:render-fn (fn [{:keys [preview-url id]}]
[quo/collectible
{:images [preview-url]
:on-press #(rf/dispatch
[:navigate-to
:wallet-collectible])}])}])))
:on-press (fn []
(rf/dispatch [:wallet/get-collectible-details id])
(rf/dispatch
[:navigate-to
:wallet-collectible]))}])}])))
41 changes: 41 additions & 0 deletions src/status_im2/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@

(rf/reg-event-fx :wallet/clear-stored-collectibles clear-stored-collectibles)

(defn store-last-collectible-details
[{:keys [db]} [collectible]]
{:db (assoc-in db
[:wallet :last-collectible-details]
collectible)})

(rf/reg-event-fx :wallet/store-last-collectible-details store-last-collectible-details)

(defn clear-stored-last-collectible-details
[{:keys [db]}]
{:db (update db :wallet dissoc :last-collectible-details)})

(rf/reg-event-fx :wallet/clear-stored-last-collectible-details clear-stored-last-collectible-details)

(rf/reg-event-fx
:wallet/request-collectibles
(fn [{:keys [db]} [{:keys [start-at-index new-request?]}]]
Expand Down Expand Up @@ -259,6 +273,33 @@
[:wallet/request-collectibles
{:start-at-index start-at-index}]])]})))

(rf/reg-event-fx :wallet/get-collectible-details
(fn [_ [collectible-id]]
(let [request-id 0
collectible-id-converted (cske/transform-keys csk/->PascalCaseKeyword collectible-id)
request-params [request-id [collectible-id-converted]]]
{:json-rpc/call [{:method "wallet_getCollectiblesDetailsAsync"
:params request-params
:on-error (fn [error]
(log/error "failed to request collectible"
{:event :wallet/get-collectible-details
:error error
:params request-params}))}]})))

(rf/reg-event-fx :wallet/get-collectible-details-done
(fn [_ [{:keys [message]}]]
(let [response (cske/transform-keys csk/->kebab-case-keyword
(types/json->clj message))
{:keys [collectibles]} response
collectible (first collectibles)]
(log/info "=== RECEIVED: " collectible)
(if collectible
{:fx
[[:dispatch [:wallet/store-last-collectible-details collectible]]]}
(log/error "failed to get collectible details"
{:event :wallet/get-collectible-details-done
:response response})))))

(rf/reg-event-fx :wallet/fetch-address-suggestions
(fn [{:keys [db]} [address]]
{:db (assoc db
Expand Down
6 changes: 6 additions & 0 deletions src/status_im2/subs/wallet/collectibles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
(assoc collectible :preview-url (preview-url collectible)))
(:collectibles wallet))))

(re-frame/reg-sub
:wallet/last-collectible-details
:<- [:wallet]
(fn [wallet]
(let [last-collectible (:last-collectible-details wallet)]
(assoc last-collectible :preview-url (preview-url last-collectible)))))

0 comments on commit 5128e2e

Please sign in to comment.