Skip to content

Commit 41a28e4

Browse files
committed
Show 'wallets unavailable' if device does not support IndexedDB
1 parent 8be0b30 commit 41a28e4

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

pages/wallets/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,24 @@ export default function Wallet () {
5454
)
5555
}
5656

57-
if (status === Status.NO_WALLETS && !showWallets) {
57+
if ([Status.NO_WALLETS, Status.WALLETS_UNAVAILABLE].includes(status) && !showWallets) {
5858
return (
5959
<WalletLayout>
6060
<div className='py-5 text-center d-flex flex-column align-items-center justify-content-center flex-grow-1'>
6161
<Button
6262
onClick={() => setShowWallets(true)}
63+
disabled={status === Status.WALLETS_UNAVAILABLE}
6364
size='md' variant='secondary'
6465
>attach wallet
6566
</Button>
66-
<small className='d-block mt-3 text-muted'>attach a wallet to send and receive sats</small>
67+
{status === Status.WALLETS_UNAVAILABLE
68+
? (
69+
<small className='d-block mt-3 text-muted'>
70+
wallets unavailable<br />
71+
this device does not support storage of cryptographic keys
72+
</small>
73+
)
74+
: <small className='d-block mt-3 text-muted'>attach a wallet to send and receive sats</small>}
6775
</div>
6876
</WalletLayout>
6977
)

wallets/client/context/hooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useWalletMigrationMutation, CryptoKeyRequiredError, useIsWrongKey
1010
} from '@/wallets/client/hooks'
1111
import { WalletConfigurationError } from '@/wallets/client/errors'
12-
import { SET_WALLETS, WRONG_KEY, KEY_MATCH, useWalletsDispatch } from '@/wallets/client/context'
12+
import { SET_WALLETS, WRONG_KEY, KEY_MATCH, NO_KEY, useWalletsDispatch } from '@/wallets/client/context'
1313

1414
export function useServerWallets () {
1515
const dispatch = useWalletsDispatch()
@@ -108,7 +108,9 @@ export function useKeyInit () {
108108
const wrongKey = useIsWrongKey()
109109

110110
useEffect(() => {
111-
if (wrongKey) {
111+
if (typeof window.indexedDB === 'undefined') {
112+
dispatch({ type: NO_KEY })
113+
} else if (wrongKey) {
112114
dispatch({ type: WRONG_KEY })
113115
} else {
114116
dispatch({ type: KEY_MATCH })

wallets/client/context/reducer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ export const Status = {
55
LOADING_WALLETS: 'LOADING_WALLETS',
66
NO_WALLETS: 'NO_WALLETS',
77
HAS_WALLETS: 'HAS_WALLETS',
8-
PASSPHRASE_REQUIRED: 'PASSPHRASE_REQUIRED'
8+
PASSPHRASE_REQUIRED: 'PASSPHRASE_REQUIRED',
9+
WALLETS_UNAVAILABLE: 'WALLETS_UNAVAILABLE'
910
}
1011

1112
// wallet actions
1213
export const SET_WALLETS = 'SET_WALLETS'
1314
export const SET_KEY = 'SET_KEY'
1415
export const WRONG_KEY = 'WRONG_KEY'
1516
export const KEY_MATCH = 'KEY_MATCH'
17+
export const NO_KEY = 'KEY_UNAVAILABLE'
1618

1719
export default function reducer (state, action) {
1820
switch (action.type) {
@@ -50,13 +52,18 @@ export default function reducer (state, action) {
5052
? state.status
5153
: walletStatus(state.wallets)
5254
}
55+
case NO_KEY:
56+
return {
57+
...state,
58+
status: Status.WALLETS_UNAVAILABLE
59+
}
5360
default:
5461
return state
5562
}
5663
}
5764

5865
function statusLocked (status) {
59-
return [Status.PASSPHRASE_REQUIRED].includes(status)
66+
return [Status.PASSPHRASE_REQUIRED, Status.WALLETS_UNAVAILABLE].includes(status)
6067
}
6168

6269
function walletStatus (wallets) {

0 commit comments

Comments
 (0)