parent
53f40b55f2
commit
723573833e
|
@ -1,26 +1,33 @@
|
||||||
(ns status-im.async-storage.core
|
(ns react-native.async-storage
|
||||||
(:require ["@react-native-async-storage/async-storage" :default async-storage]
|
(:require ["@react-native-async-storage/async-storage" :default async-storage]
|
||||||
[goog.functions :as f]
|
[cognitect.transit :as transit]
|
||||||
[re-frame.core :as re-frame]
|
[taoensso.timbre :as log]
|
||||||
[status-im.async-storage.transit :refer [clj->transit transit->clj]]
|
goog.functions))
|
||||||
[taoensso.timbre :as log]))
|
|
||||||
|
|
||||||
(def ^:private debounce-ms 250)
|
(def ^:private debounce-ms 250)
|
||||||
|
|
||||||
(def key->string str)
|
(def ^:private reader (transit/reader :json))
|
||||||
|
(def ^:private writer (transit/writer :json))
|
||||||
|
|
||||||
|
(defn clj->transit [o] (transit/write writer o))
|
||||||
|
(defn transit->clj
|
||||||
|
[o]
|
||||||
|
(try (transit/read reader o)
|
||||||
|
(catch :default e
|
||||||
|
(log/error e))))
|
||||||
|
|
||||||
(defn set-item!
|
(defn set-item!
|
||||||
[k value]
|
[k value]
|
||||||
(-> ^js async-storage
|
(-> ^js async-storage
|
||||||
(.setItem (key->string k)
|
(.setItem (str k)
|
||||||
(clj->transit value))
|
(clj->transit value))
|
||||||
(.catch (fn [error]
|
(.catch (fn [error]
|
||||||
(log/error "[async-storage]" error)))))
|
(log/error "[async-storage]" error)))))
|
||||||
|
|
||||||
(defn- set-item-factory
|
(defn set-item-factory
|
||||||
[]
|
[]
|
||||||
(let [tmp-storage (atom {})
|
(let [tmp-storage (atom {})
|
||||||
debounced (f/debounce (fn []
|
debounced (goog.functions/debounce (fn []
|
||||||
(doseq [[k v] @tmp-storage]
|
(doseq [[k v] @tmp-storage]
|
||||||
(swap! tmp-storage dissoc k)
|
(swap! tmp-storage dissoc k)
|
||||||
(set-item! k v)))
|
(set-item! k v)))
|
||||||
|
@ -32,7 +39,7 @@
|
||||||
(defn get-items
|
(defn get-items
|
||||||
[ks cb]
|
[ks cb]
|
||||||
(-> ^js async-storage
|
(-> ^js async-storage
|
||||||
(.multiGet (to-array (map key->string ks)))
|
(.multiGet (to-array (map str ks)))
|
||||||
(.then (fn [^js data]
|
(.then (fn [^js data]
|
||||||
(cb (->> (js->clj data)
|
(cb (->> (js->clj data)
|
||||||
(map (comp transit->clj second))
|
(map (comp transit->clj second))
|
||||||
|
@ -44,7 +51,7 @@
|
||||||
(defn get-item
|
(defn get-item
|
||||||
[k cb]
|
[k cb]
|
||||||
(-> ^js async-storage
|
(-> ^js async-storage
|
||||||
(.getItem (key->string k))
|
(.getItem (str k))
|
||||||
(.then (fn [^js data]
|
(.then (fn [^js data]
|
||||||
(-> data
|
(-> data
|
||||||
js->clj
|
js->clj
|
||||||
|
@ -53,10 +60,3 @@
|
||||||
(.catch (fn [error]
|
(.catch (fn [error]
|
||||||
(cb nil)
|
(cb nil)
|
||||||
(log/error "[async-storage]" error)))))
|
(log/error "[async-storage]" error)))))
|
||||||
|
|
||||||
(re-frame/reg-fx ::set! (set-item-factory))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::get
|
|
||||||
(fn [{ks :keys cb :cb}]
|
|
||||||
(get-items ks cb)))
|
|
|
@ -1,13 +0,0 @@
|
||||||
(ns status-im.async-storage.transit
|
|
||||||
(:require [cognitect.transit :as transit]
|
|
||||||
[taoensso.timbre :as log]))
|
|
||||||
|
|
||||||
(def reader (transit/reader :json))
|
|
||||||
(def writer (transit/writer :json))
|
|
||||||
|
|
||||||
(defn clj->transit [o] (transit/write writer o))
|
|
||||||
(defn transit->clj
|
|
||||||
[o]
|
|
||||||
(try (transit/read reader o)
|
|
||||||
(catch :default e
|
|
||||||
(log/error e))))
|
|
|
@ -6,7 +6,6 @@
|
||||||
[quo2.foundations.colors :as quo2.colors]
|
[quo2.foundations.colors :as quo2.colors]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.utils.deprecated-types :as types]
|
[status-im.utils.deprecated-types :as types]
|
||||||
[status-im.async-storage.core :as async-storage]
|
|
||||||
[status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles]
|
[status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles]
|
||||||
[status-im.utils.universal-links.core :as universal-links]
|
[status-im.utils.universal-links.core :as universal-links]
|
||||||
[status-im.bottom-sheet.events :as bottom-sheet]
|
[status-im.bottom-sheet.events :as bottom-sheet]
|
||||||
|
@ -815,51 +814,6 @@
|
||||||
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
|
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
|
||||||
:on-error #(log/error "failed to reorder community category" %)}]})
|
:on-error #(log/error "failed to reorder community category" %)}]})
|
||||||
|
|
||||||
(defn category-hash
|
|
||||||
[public-key community-id category-id]
|
|
||||||
(hash (str public-key community-id category-id)))
|
|
||||||
|
|
||||||
(rf/defn store-category-state
|
|
||||||
{:events [::store-category-state]}
|
|
||||||
[{:keys [db]} community-id category-id state-open?]
|
|
||||||
(let [public-key (get-in db [:profile/profile :public-key])
|
|
||||||
hash (category-hash public-key community-id category-id)]
|
|
||||||
{::async-storage/set! {hash state-open?}}))
|
|
||||||
|
|
||||||
(rf/defn update-category-states-in-db
|
|
||||||
{:events [::category-states-loaded]}
|
|
||||||
[{:keys [db]} community-id hashes states]
|
|
||||||
(let [public-key (get-in db [:profile/profile :public-key])
|
|
||||||
categories-old (get-in db [:communities community-id :categories])
|
|
||||||
categories (reduce (fn [acc [category-id category]]
|
|
||||||
(let [hash (get hashes category-id)
|
|
||||||
state (get states hash)
|
|
||||||
category-updated (assoc category :state state)]
|
|
||||||
(assoc acc category-id category-updated)))
|
|
||||||
{}
|
|
||||||
categories-old)]
|
|
||||||
{:db (update-in db [:communities community-id :categories] merge categories)}))
|
|
||||||
|
|
||||||
(rf/defn load-category-states
|
|
||||||
{:events [:communities/load-category-states]}
|
|
||||||
[{:keys [db]} community-id]
|
|
||||||
(let [public-key (get-in db [:profile/profile :public-key])
|
|
||||||
categories (get-in db [:communities community-id :categories])
|
|
||||||
{:keys [keys hashes]} (reduce (fn [acc category]
|
|
||||||
(let [category-id (get category 0)
|
|
||||||
hash (category-hash
|
|
||||||
public-key
|
|
||||||
community-id
|
|
||||||
category-id)]
|
|
||||||
(-> acc
|
|
||||||
(assoc-in [:hashes category-id] hash)
|
|
||||||
(update :keys #(conj % hash)))))
|
|
||||||
{}
|
|
||||||
categories)]
|
|
||||||
{::async-storage/get {:keys keys
|
|
||||||
:cb #(re-frame/dispatch
|
|
||||||
[::category-states-loaded community-id hashes %])}}))
|
|
||||||
|
|
||||||
;; Note - dispatch is used to make sure we are opening community once `pop-to-root` is processed.
|
;; Note - dispatch is used to make sure we are opening community once `pop-to-root` is processed.
|
||||||
;; Don't directly merge effects using `navigation/navigate-to`, because it will work in debug and
|
;; Don't directly merge effects using `navigation/navigate-to`, because it will work in debug and
|
||||||
;; release, but for e2e `pop-to-root` closes even currently opened community
|
;; release, but for e2e `pop-to-root` closes even currently opened community
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
(:require
|
(:require
|
||||||
clojure.set
|
clojure.set
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.async-storage.core :as async-storage]
|
|
||||||
status-im.backup.core
|
status-im.backup.core
|
||||||
status-im.bootnodes.core
|
status-im.bootnodes.core
|
||||||
status-im.browser.core
|
status-im.browser.core
|
||||||
|
@ -193,7 +192,7 @@
|
||||||
(rf/merge cofx
|
(rf/merge cofx
|
||||||
(cond
|
(cond
|
||||||
(= :chat view-id)
|
(= :chat view-id)
|
||||||
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])
|
{:async-storage-set {:chat-id (get-in cofx [:db :current-chat-id])
|
||||||
:key-uid (get-in cofx [:db :profile/profile :key-uid])}
|
:key-uid (get-in cofx [:db :profile/profile :key-uid])}
|
||||||
:db (assoc db :screens/was-focused-once? true)}
|
:db (assoc db :screens/was-focused-once? true)}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[quo.platform :as platform]
|
[quo.platform :as platform]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im.ethereum.decode :as decode]
|
[status-im.ethereum.decode :as decode]
|
||||||
[status-im.ethereum.tokens :as tokens]
|
[status-im.ethereum.tokens :as tokens]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im.bottom-sheet.events :as bottom-sheet]
|
[status-im.bottom-sheet.events :as bottom-sheet]
|
||||||
[status-im.contact.db :as contact.db]
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
|
@ -826,7 +826,7 @@
|
||||||
(rf/defn get-buy-crypto-preference
|
(rf/defn get-buy-crypto-preference
|
||||||
{:events [::get-buy-crypto]}
|
{:events [::get-buy-crypto]}
|
||||||
[_]
|
[_]
|
||||||
{::async-storage/get {:keys [:buy-crypto-hidden]
|
{:async-storage-get {:keys [:buy-crypto-hidden]
|
||||||
:cb #(re-frame/dispatch [::store-buy-crypto-preference %])}})
|
:cb #(re-frame/dispatch [::store-buy-crypto-preference %])}})
|
||||||
|
|
||||||
(rf/defn wallet-will-focus
|
(rf/defn wallet-will-focus
|
||||||
|
@ -849,7 +849,7 @@
|
||||||
{:events [::hide-buy-crypto]}
|
{:events [::hide-buy-crypto]}
|
||||||
[{:keys [db]}]
|
[{:keys [db]}]
|
||||||
{:db (assoc db :wallet/buy-crypto-hidden true)
|
{:db (assoc db :wallet/buy-crypto-hidden true)
|
||||||
::async-storage/set! {:buy-crypto-hidden true}})
|
:async-storage-set {:buy-crypto-hidden true}})
|
||||||
|
|
||||||
(rf/defn store-buy-crypto
|
(rf/defn store-buy-crypto
|
||||||
{:events [::store-buy-crypto-preference]}
|
{:events [::store-buy-crypto-preference]}
|
||||||
|
@ -1025,7 +1025,7 @@
|
||||||
(rf/defn switch-transactions-management-enabled
|
(rf/defn switch-transactions-management-enabled
|
||||||
{:events [:multiaccounts.ui/switch-transactions-management-enabled]}
|
{:events [:multiaccounts.ui/switch-transactions-management-enabled]}
|
||||||
[{:keys [db]} enabled?]
|
[{:keys [db]} enabled?]
|
||||||
{::async-storage/set! {:transactions-management-enabled? enabled?}
|
{:async-storage-set {:transactions-management-enabled? enabled?}
|
||||||
:db (assoc db :wallet/transactions-management-enabled? enabled?)})
|
:db (assoc db :wallet/transactions-management-enabled? enabled?)})
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
(ns status-im2.common.async-storage
|
||||||
|
(:require [re-frame.core :as re-frame]
|
||||||
|
react-native.async-storage))
|
||||||
|
|
||||||
|
(re-frame/reg-fx :async-storage-set (react-native.async-storage/set-item-factory))
|
||||||
|
(re-frame/reg-fx :async-storage-get
|
||||||
|
(fn [{ks :keys cb :cb}] (react-native.async-storage/get-items ks cb)))
|
|
@ -5,7 +5,7 @@
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
[react-native.reanimated :as reanimated]
|
[react-native.reanimated :as reanimated]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im2.contexts.chat.composer.constants :as constants]
|
[status-im2.contexts.chat.composer.constants :as constants]
|
||||||
[status-im2.contexts.chat.composer.keyboard :as kb]
|
[status-im2.contexts.chat.composer.keyboard :as kb]
|
||||||
[status-im2.contexts.chat.composer.utils :as utils]
|
[status-im2.contexts.chat.composer.utils :as utils]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns status-im2.contexts.chat.composer.keyboard
|
(ns status-im2.contexts.chat.composer.keyboard
|
||||||
(:require [oops.core :as oops]
|
(:require [oops.core :as oops]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
[react-native.reanimated :as reanimated]))
|
[react-native.reanimated :as reanimated]))
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[quo2.foundations.colors :as colors]
|
[quo2.foundations.colors :as colors]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
|
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
|
||||||
[status-im2.common.muting.helpers :refer [format-mute-till]]))
|
[status-im2.common.muting.helpers :refer [format-mute-till]]))
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@
|
||||||
(rf/merge cofx
|
(rf/merge cofx
|
||||||
(merge
|
(merge
|
||||||
{:db (dissoc db :current-chat-id)
|
{:db (dissoc db :current-chat-id)
|
||||||
::async-storage/set! {:chat-id nil
|
:async-storage-set {:chat-id nil
|
||||||
:key-uid nil}}
|
:key-uid nil}}
|
||||||
(let [community-id (get-in db [:chats chat-id :community-id])]
|
(let [community-id (get-in db [:chats chat-id :community-id])]
|
||||||
;; When navigating back from community chat to community, update switcher card
|
;; When navigating back from community chat to community, update switcher card
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
:on-press #(rf/dispatch [:communities/navigate-to-community (:id item)])}]
|
:on-press #(rf/dispatch [:communities/navigate-to-community (:id item)])}]
|
||||||
[quo/community-list-item
|
[quo/community-list-item
|
||||||
{:on-press (fn []
|
{:on-press (fn []
|
||||||
(rf/dispatch [:communities/load-category-states (:id item)])
|
|
||||||
(rf/dispatch [:dismiss-keyboard])
|
(rf/dispatch [:dismiss-keyboard])
|
||||||
(rf/dispatch [:communities/navigate-to-community (:id item)]))
|
(rf/dispatch [:communities/navigate-to-community (:id item)]))
|
||||||
:on-long-press #(rf/dispatch
|
:on-long-press #(rf/dispatch
|
||||||
|
@ -147,7 +146,6 @@
|
||||||
|
|
||||||
[quo/community-list-item
|
[quo/community-list-item
|
||||||
{:on-press (fn []
|
{:on-press (fn []
|
||||||
(rf/dispatch [:communities/load-category-states (:id community)])
|
|
||||||
(rf/dispatch [:dismiss-keyboard])
|
(rf/dispatch [:dismiss-keyboard])
|
||||||
(rf/dispatch [:communities/navigate-to-community (:id community)]))
|
(rf/dispatch [:communities/navigate-to-community (:id community)]))
|
||||||
:on-long-press #(js/alert "TODO: to be implemented")}
|
:on-long-press #(js/alert "TODO: to be implemented")}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
[oops.core :refer [oget]]
|
[oops.core :refer [oget]]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
[status-im2.common.resources :as resources]
|
[status-im2.common.resources :as resources]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im2.contexts.shell.jump-to.state :as shell.state]
|
[status-im2.contexts.shell.jump-to.state :as shell.state]
|
||||||
[status-im2.contexts.onboarding.common.carousel.view :as carousel]
|
[status-im2.contexts.onboarding.common.carousel.view :as carousel]
|
||||||
[status-im2.contexts.onboarding.common.background.style :as style]
|
[status-im2.contexts.onboarding.common.background.style :as style]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
[react-native.safe-area :as safe-area]
|
[react-native.safe-area :as safe-area]
|
||||||
[react-native.reanimated :as reanimated]
|
[react-native.reanimated :as reanimated]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[status-im2.contexts.shell.jump-to.state :as state]
|
[status-im2.contexts.shell.jump-to.state :as state]
|
||||||
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
|
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
|
||||||
[quo2.theme :as quo.theme]))
|
[quo2.theme :as quo.theme]))
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
[status-im2.setup.dev :as dev]
|
[status-im2.setup.dev :as dev]
|
||||||
[status-im2.setup.global-error :as global-error]
|
[status-im2.setup.global-error :as global-error]
|
||||||
[status-im2.common.log :as log]
|
[status-im2.common.log :as log]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[react-native.async-storage :as async-storage]
|
||||||
[native-module.core :as native-module]
|
[native-module.core :as native-module]
|
||||||
[status-im.notifications.local :as notifications]
|
[status-im.notifications.local :as notifications]
|
||||||
[status-im.utils.universal-links.core :as utils.universal-links]
|
[status-im.utils.universal-links.core :as utils.universal-links]
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
status-im2.contexts.shell.share.events
|
status-im2.contexts.shell.share.events
|
||||||
status-im2.contexts.syncing.events
|
status-im2.contexts.syncing.events
|
||||||
status-im2.contexts.onboarding.common.overlay.events
|
status-im2.contexts.onboarding.common.overlay.events
|
||||||
|
status-im2.common.async-storage
|
||||||
[status-im2.db :as db]
|
[status-im2.db :as db]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue