[refactor] remove allowed-keys macro

The initial purpose of the allowed keys macro was to only accept maps
with a defined set of keys so that the maps can be serialized into the db.
The way maps are serialized has been changed so that only the existing keys
in the db are cherry picked so passing maps with extra keys is no longer a
problem
This commit is contained in:
Eric Dvorsak 2018-10-26 18:01:07 +02:00 committed by yenda
parent 4804d11b0f
commit b7b7806ed1
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
12 changed files with 215 additions and 247 deletions

View File

@ -6,8 +6,7 @@
[clojure.string :as string]
[cljs.spec.alpha :as spec]
[status-im.constants :as const]
[status-im.utils.security :as security])
(:require-macros [status-im.utils.db :refer [allowed-keys]]))
[status-im.utils.security :as security]))
(defn logged-in? [cofx]
(boolean
@ -55,8 +54,7 @@
(spec/def :account/mainnet-warning-shown? (spec/nilable boolean?))
(spec/def :account/desktop-alpha-release-warning-shown? (spec/nilable boolean?))
(spec/def :accounts/account (allowed-keys
:req-un [:account/name :account/address :account/public-key
(spec/def :accounts/account (spec/keys :req-un [:account/name :account/address :account/public-key
:account/photo-path :account/signing-phrase
:account/installation-id]
:opt-un [:account/debug? :account/status :account/last-updated

View File

@ -1,6 +1,5 @@
(ns status-im.browser.db
(:require [cljs.spec.alpha :as spec])
(:require-macros [status-im.utils.db :refer [allowed-keys]]))
(:require [cljs.spec.alpha :as spec]))
(spec/def :browser/browser-id (spec/nilable string?))
(spec/def :browser/timestamp (spec/nilable int?))
@ -22,8 +21,7 @@
(spec/def :browser/options
(spec/nilable
(allowed-keys
:opt-un [:browser/browser-id
(spec/keys :opt-un [:browser/browser-id
:browser/url
:browser/loading?
:browser/resolving?
@ -36,8 +34,7 @@
:browser/error?])))
(spec/def :browser/browser
(allowed-keys
:req-un [:browser/browser-id
(spec/keys :req-un [:browser/browser-id
:browser/timestamp]
:opt-un [:browser/name
:browser/dapp?
@ -51,8 +48,7 @@
(spec/def :dapp/permissions (spec/nilable vector?))
(spec/def :dapp/permission-map
(allowed-keys
:req-un [:dapp/dapp]
(spec/keys :req-un [:dapp/dapp]
:opt-un [:dapp/permissions]))
(spec/def :dapps/permissions (spec/nilable (spec/map-of :global/not-empty-string :dapp/permission-map)))

View File

@ -1,5 +1,4 @@
(ns status-im.contact.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]
status-im.utils.db))
@ -69,8 +68,8 @@
(spec/def :contacts/new-identity-error (spec/nilable string?))
;;on showing this contact's profile (andrey: better to move into profile ns)
(spec/def :contacts/identity (spec/nilable :global/not-empty-string))
(spec/def :contacts/list-ui-props (spec/nilable (allowed-keys :opt-un [:contact-list-ui/edit?])))
(spec/def :contacts/ui-props (spec/nilable (allowed-keys :opt-un [:contacts-ui/edit?])))
(spec/def :contacts/list-ui-props (spec/nilable (spec/keys :opt-un [:contact-list-ui/edit?])))
(spec/def :contacts/ui-props (spec/nilable (spec/keys :opt-un [:contacts-ui/edit?])))
;;used in modal list (for example for wallet)
(spec/def :contacts/click-handler (spec/nilable fn?))
;;used in modal list (for example for wallet)

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.bootnodes-settings.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require
[clojure.string :as string]
[cljs.spec.alpha :as spec]))
@ -10,7 +9,7 @@
(spec/def :bootnode/name ::not-blank-string)
(spec/def :bootnode/id ::not-blank-string)
(spec/def :bootnode/chain ::not-blank-string)
(spec/def :bootnode/bootnode (allowed-keys :req-un [:bootnode/chain
(spec/def :bootnode/bootnode (spec/keys :req-un [:bootnode/chain
:bootnode/address
:bootnode/name
:bootnode/id]))

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]
[status-im.constants :as constants]
[status-im.utils.platform :as platform]
@ -111,22 +110,22 @@
(spec/def :navigation/prev-tab-view-id (spec/nilable keyword?))
(spec/def :navigation/prev-view-id (spec/nilable keyword?))
;; navigation screen params
(spec/def :navigation.screen-params/network-details (allowed-keys :req [:networks/selected-network]))
(spec/def :navigation.screen-params/network-details (spec/keys :req [:networks/selected-network]))
(spec/def :navigation.screen-params/browser (spec/nilable map?))
(spec/def :navigation.screen-params.profile-qr-viewer/contact (spec/nilable map?))
(spec/def :navigation.screen-params.profile-qr-viewer/source (spec/nilable keyword?))
(spec/def :navigation.screen-params.profile-qr-viewer/value (spec/nilable string?))
(spec/def :navigation.screen-params/profile-qr-viewer (allowed-keys :opt-un [:navigation.screen-params.profile-qr-viewer/contact
(spec/def :navigation.screen-params/profile-qr-viewer (spec/keys :opt-un [:navigation.screen-params.profile-qr-viewer/contact
:navigation.screen-params.profile-qr-viewer/source
:navigation.screen-params.profile-qr-viewer/value]))
(spec/def :navigation.screen-params.qr-scanner/current-qr-context (spec/nilable any?))
(spec/def :navigation.screen-params/qr-scanner (allowed-keys :opt-un [:navigation.screen-params.qr-scanner/current-qr-context]))
(spec/def :navigation.screen-params/qr-scanner (spec/keys :opt-un [:navigation.screen-params.qr-scanner/current-qr-context]))
(spec/def :navigation.screen-params.group-contacts/show-search? (spec/nilable any?))
(spec/def :navigation.screen-params/group-contacts (allowed-keys :opt [:group/contact-group-id]
(spec/def :navigation.screen-params/group-contacts (spec/keys :opt [:group/contact-group-id]
:opt-un [:navigation.screen-params.group-contacts/show-search?]))
(spec/def :navigation.screen-params.edit-contact-group/group (spec/nilable any?))
(spec/def :navigation.screen-params.edit-contact-group/group-type (spec/nilable any?))
(spec/def :navigation.screen-params/edit-contact-group (allowed-keys :opt-un [:navigation.screen-params.edit-contact-group/group
(spec/def :navigation.screen-params/edit-contact-group (spec/keys :opt-un [:navigation.screen-params.edit-contact-group/group
:navigation.screen-params.edit-contact-group/group-type]))
(spec/def :navigation.screen-params.dapp-description/dapp :new/open-dapp)
(spec/def :navigation.screen-params/dapp-description map?)
@ -135,7 +134,7 @@
(spec/def :navigation.screen-params/show-extension map?)
(spec/def :navigation/screen-params (spec/nilable (allowed-keys :opt-un [:navigation.screen-params/network-details
(spec/def :navigation/screen-params (spec/nilable (spec/keys :opt-un [:navigation.screen-params/network-details
:navigation.screen-params/browser
:navigation.screen-params/profile-qr-viewer
:navigation.screen-params/qr-scanner
@ -184,9 +183,7 @@
(spec/def ::hardwallet map?)
(spec/def ::db (allowed-keys
:opt
[:contacts/contacts
(spec/def ::db (spec/keys :opt [:contacts/contacts
:contacts/dapps
:contacts/new-identity
:contacts/new-identity-error
@ -247,8 +244,7 @@
:ui/contact
:ui/search
:ui/chat]
:opt-un
[::current-public-key
:opt-un [::current-public-key
::modal
::was-modal?
::rpc-url

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.extensions.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require
[clojure.string :as string]
[cljs.spec.alpha :as spec]))
@ -11,7 +10,7 @@
(spec/def :extension/url ::not-blank-string)
(spec/def :extension/active? boolean?)
(spec/def :extension/data (spec/nilable string?))
(spec/def :extension/extension (allowed-keys :req-un [:extension/id
(spec/def :extension/extension (spec/keys :req-un [:extension/id
:extension/name
:extension/url
:extension/active?]

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.group.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]))
(spec/def :group/selected-contacts (spec/nilable (spec/* string?)))

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.network-settings.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]))
(spec/def :networks/id string?)

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.wallet.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]
[status-im.i18n :as i18n]
status-im.ui.screens.wallet.request.db
@ -8,7 +7,7 @@
(spec/def :wallet.send/recipient string?)
(spec/def :wallet/send (allowed-keys :req-un [:wallet.send/recipient]))
(spec/def :wallet/send (spec/keys :req-un [:wallet.send/recipient]))
(spec/def :wallet/balance-loading? (spec/nilable boolean?))
(spec/def :wallet/transactions-loading? (spec/nilable boolean?))
@ -26,7 +25,7 @@
(spec/def :wallet/currency (spec/nilable any?))
(spec/def :wallet/balance (spec/nilable any?))
(spec/def :wallet/wallet (allowed-keys :opt-un [:wallet/send-transaction :wallet/request-transaction
(spec/def :wallet/wallet (spec/keys :opt-un [:wallet/send-transaction :wallet/request-transaction
:wallet/transactions-queue
:wallet/balance-loading? :wallet/errors :wallet/transactions-loading?
:wallet/transactions-last-updated-at :wallet/chat-transactions

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.wallet.request.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]
[status-im.utils.money :as money]))
@ -8,5 +7,4 @@
(spec/def ::amount-text (spec/nilable string?))
(spec/def ::symbol (spec/nilable keyword?))
(spec/def :wallet/request-transaction (allowed-keys
:opt-un [::amount ::amount-error ::amount-text ::symbol]))
(spec/def :wallet/request-transaction (spec/keys :opt-un [::amount ::amount-error ::amount-text ::symbol]))

View File

@ -1,5 +1,4 @@
(ns status-im.ui.screens.wallet.send.db
(:require-macros [status-im.utils.db :refer [allowed-keys]])
(:require [cljs.spec.alpha :as spec]
[status-im.utils.money :as money]
[status-im.utils.security :as security]))
@ -35,8 +34,7 @@
(spec/def ::on-result (spec/nilable any?))
(spec/def ::on-error (spec/nilable any?))
(spec/def :wallet/send-transaction (allowed-keys
:opt-un [::amount ::to ::to-name ::amount-error ::asset-error ::amount-text
(spec/def :wallet/send-transaction (spec/keys :opt-un [::amount ::to ::to-name ::amount-error ::asset-error ::amount-text
::password ::show-password-input? ::id ::from ::data ::nonce
::camera-flashlight ::in-progress? ::on-result ::on-error
::wrong-password? ::from-chat? ::symbol ::advanced?

View File

@ -1,12 +0,0 @@
(ns status-im.utils.db
(:require [cljs.spec.alpha :as s]))
(defmacro allowed-keys
[& {:keys [req req-un opt opt-un] :as args}]
`(s/merge (s/keys ~@(apply concat (vec args)))
(s/map-of ~(set (concat req
(map (comp keyword name) req-un)
opt
(map (comp keyword name) opt-un)))
any?)))