Skip to content

Commit

Permalink
Refactor usage of localStorage vars
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Nov 13, 2020
1 parent d8f0cdb commit 9f13a8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
11 changes: 6 additions & 5 deletions app/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import CryptoProviderFactory from './wallet/byron/crypto-provider-factory'
import ShelleyCryptoProviderFactory from './wallet/shelley/shelley-crypto-provider-factory'
import {ShelleyWallet} from './wallet/shelley-wallet'
import getDonationAddress from './helpers/getDonationAddress'
import {localStorageVars} from './localStorage'

let wallet: ReturnType<typeof CardanoWallet | typeof ShelleyWallet>

Expand Down Expand Up @@ -1091,7 +1092,7 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF

const closeWelcome = (state, dontShowDisclaimer) => {
// we may get an ignored click event as the second argument, check only against booleans
window.localStorage.setItem('dontShowDisclaimer', dontShowDisclaimer)
window.localStorage.setItem(localStorageVars.WELCOME, dontShowDisclaimer)
setState({
displayWelcome: false,
})
Expand All @@ -1103,23 +1104,23 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
})
}

const closeInfoModal = (state, dontShowDisclaimer) => {
const closeInfoModal = (state, dontShowInfoModal) => {
// we may get an ignored click event as the second argument, check only against booleans
window.localStorage.setItem('dontShowInfoModal', dontShowDisclaimer)
window.localStorage.setItem(localStorageVars.INFO_MODAL, dontShowInfoModal)
setState({
displayInfoModal: false,
})
}

const closeStakingBanner = (state) => {
window.localStorage.setItem('dontShowStakingBannerTestnet3', 'true')
window.localStorage.setItem(localStorageVars.STAKING_BANNER, 'true')
setState({
shouldShowStakingBanner: false,
})
}

const closePremiumBanner = (state) => {
window.localStorage.setItem('dontShowPremiumBanner', 'true')
window.localStorage.setItem(localStorageVars.PREMIUM_BANNER, 'true')
setState({
shouldShowPremiumBanner: false,
})
Expand Down
8 changes: 8 additions & 0 deletions app/frontend/localStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const localStorageVars = {
WELCOME: 'dontShowDisclaimer',
INFO_MODAL: 'dontShowInfoModal',
PREMIUM_BANNER: 'dontShowPremiumBanner',
STAKING_BANNER: 'dontShowStakingBannerTestnet3',
}

export {localStorageVars}
11 changes: 7 additions & 4 deletions app/frontend/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ADALITE_CONFIG} from './config'
import {localStorageVars} from './localStorage'

interface Transaction {}

Expand Down Expand Up @@ -147,15 +148,17 @@ const initialState: State = {
hint: 'Hint: Ensure that your mnemonic is without mistake.',
},
displayWelcome:
!(window.localStorage.getItem('dontShowDisclaimer') === 'true') &&
!(window.localStorage.getItem(localStorageVars.WELCOME) === 'true') &&
ADALITE_CONFIG.ADALITE_DEVEL_AUTO_LOGIN !== 'true',
currentTab: 'wallet-info',
walletIsLoaded: false,
shouldShowStakingBanner: !(
window.localStorage.getItem('dontShowStakingBannerTestnet3') === 'true'
window.localStorage.getItem(localStorageVars.STAKING_BANNER) === 'true'
),
shouldShowPremiumBanner: !(window.localStorage.getItem('dontShowPremiumBanner') === 'true'),
displayInfoModal: !(window.localStorage.getItem('dontShowInfoModal') === 'true'),
shouldShowPremiumBanner: !(
window.localStorage.getItem(localStorageVars.PREMIUM_BANNER) === 'true'
),
displayInfoModal: !(window.localStorage.getItem(localStorageVars.INFO_MODAL) === 'true'),
errorBannerContent: '',
visibleAddresses: [],
// todo - object (sub-state) from send-ada form
Expand Down

0 comments on commit 9f13a8c

Please sign in to comment.