diff --git a/components/item-act.js b/components/item-act.js
index 36eaeaf7..36d5a0c7 100644
--- a/components/item-act.js
+++ b/components/item-act.js
@@ -13,7 +13,7 @@ import { usePaidMutation } from './use-paid-mutation'
import { ACT_MUTATION } from '@/fragments/paidAction'
import { meAnonSats } from '@/lib/apollo'
import { BoostItemInput } from './adv-post-form'
-import { useWallet } from '../wallets/common'
+import { useWallet } from '@/wallets/index'
const defaultTips = [100, 1000, 10_000, 100_000]
diff --git a/components/nav/common.js b/components/nav/common.js
index 184c199a..0f0f1763 100644
--- a/components/nav/common.js
+++ b/components/nav/common.js
@@ -22,10 +22,9 @@ import SearchIcon from '../../svgs/search-line.svg'
import classNames from 'classnames'
import SnIcon from '@/svgs/sn.svg'
import { useHasNewNotes } from '../use-has-new-notes'
-import { useWallets } from '@/wallets/common'
+import { useWallets } from '@/wallets/index'
import SwitchAccountList, { useAccounts } from '@/components/account'
import { useShowModal } from '@/components/modal'
-import { unsetLocalKey as resetVaultKey } from '@/components/use-vault'
export function Brand ({ className }) {
return (
@@ -266,7 +265,6 @@ function LogoutObstacle ({ onClose }) {
const { registration: swRegistration, togglePushSubscription } = useServiceWorker()
const wallets = useWallets()
const { multiAuthSignout } = useAccounts()
- const { me } = useMe()
return (
@@ -295,7 +293,6 @@ function LogoutObstacle ({ onClose }) {
}
await wallets.resetClient().catch(console.error)
- await resetVaultKey(me?.id)
await signOut({ callbackUrl: '/' })
}}
diff --git a/components/payment.js b/components/payment.js
index f5eb6e67..8bba56da 100644
--- a/components/payment.js
+++ b/components/payment.js
@@ -1,35 +1,13 @@
import { useCallback, useMemo } from 'react'
import { useMe } from './me'
import { gql, useApolloClient, useMutation } from '@apollo/client'
-import { useWallet } from '@/wallets/common'
+import { useWallet } from '@/wallets/index'
import { FAST_POLL_INTERVAL, JIT_INVOICE_TIMEOUT_MS } from '@/lib/constants'
import { INVOICE } from '@/fragments/wallet'
import Invoice from '@/components/invoice'
import { useFeeButton } from './fee-button'
import { useShowModal } from './modal'
-
-export class InvoiceCanceledError extends Error {
- constructor (hash, actionError) {
- super(actionError ?? `invoice canceled: ${hash}`)
- this.name = 'InvoiceCanceledError'
- this.hash = hash
- this.actionError = actionError
- }
-}
-
-export class NoAttachedWalletError extends Error {
- constructor () {
- super('no attached wallet found')
- this.name = 'NoAttachedWalletError'
- }
-}
-
-export class InvoiceExpiredError extends Error {
- constructor (hash) {
- super(`invoice expired: ${hash}`)
- this.name = 'InvoiceExpiredError'
- }
-}
+import { InvoiceCanceledError, NoAttachedWalletError, InvoiceExpiredError } from '@/wallets/errors'
export const useInvoice = () => {
const client = useApolloClient()
diff --git a/components/qr.js b/components/qr.js
index 12bf5a93..8b3f4563 100644
--- a/components/qr.js
+++ b/components/qr.js
@@ -2,7 +2,7 @@ import { QRCodeSVG } from 'qrcode.react'
import { CopyInput, InputSkeleton } from './form'
import InvoiceStatus from './invoice-status'
import { useEffect } from 'react'
-import { useWallet } from '@/wallets/common'
+import { useWallet } from '@/wallets/index'
import Bolt11Info from './bolt11-info'
export default function Qr ({ asIs, value, useWallet: automated, statusVariant, description, status }) {
diff --git a/components/use-indexeddb.js b/components/use-indexeddb.js
index 948440a4..5086ff69 100644
--- a/components/use-indexeddb.js
+++ b/components/use-indexeddb.js
@@ -1,7 +1,7 @@
import { useState, useEffect, useCallback, useRef } from 'react'
-export function getDbName (userId) {
- return `app:storage${userId ? `:${userId}` : ''}`
+export function getDbName (userId, name) {
+ return `app:storage:${userId ?? ''}${name ? `:${name}` : ''}`
}
function useIndexedDB ({ dbName, storeName, options = { keyPath: 'id', autoIncrement: true }, indices = [], version = 1 }) {
diff --git a/components/vault/use-vault-configurator.js b/components/vault/use-vault-configurator.js
index ec5d849c..5056208d 100644
--- a/components/vault/use-vault-configurator.js
+++ b/components/vault/use-vault-configurator.js
@@ -1,11 +1,10 @@
-import { UPDATE_VAULT_KEY } from '@/fragments/users'
import { useMutation, useQuery } from '@apollo/client'
import { useMe } from '../me'
import { useToast } from '../toast'
import useIndexedDB, { getDbName } from '../use-indexeddb'
import { useCallback, useEffect, useState } from 'react'
import { E_VAULT_KEY_EXISTS } from '@/lib/error'
-import { CLEAR_VAULT, GET_VAULT_ENTRIES } from '@/fragments/vault'
+import { CLEAR_VAULT, GET_VAULT_ENTRIES, UPDATE_VAULT_KEY } from '@/fragments/vault'
import { toHex } from '@/lib/hex'
import { decryptData, encryptData } from './use-vault'
@@ -22,7 +21,7 @@ const useImperativeQuery = (query) => {
export function useVaultConfigurator () {
const { me } = useMe()
const toaster = useToast()
- const { set, get, remove } = useIndexedDB({ dbName: getDbName(me?.id), storeName: 'vault' })
+ const { set, get, remove } = useIndexedDB({ dbName: getDbName(me?.id, 'vault'), storeName: 'vault' })
const [updateVaultKey] = useMutation(UPDATE_VAULT_KEY)
const getVaultEntries = useImperativeQuery(GET_VAULT_ENTRIES)
const [key, setKey] = useState(null)
@@ -44,10 +43,10 @@ export function useVaultConfigurator () {
}
setKey(localVaultKey)
} catch (e) {
- toaster.danger('error loading vault configuration ' + e.message)
+ // toaster?.danger('error loading vault configuration ' + e.message)
}
})()
- }, [me?.privates?.vaultKeyHash, keyHash, get, remove])
+ }, [me?.privates?.vaultKeyHash, keyHash, get, remove, toaster])
// clear vault: remove everything and reset the key
const [clearVault] = useMutation(CLEAR_VAULT, {
diff --git a/components/wallet-buttonbar.js b/components/wallet-buttonbar.js
index e07995f3..76b60e92 100644
--- a/components/wallet-buttonbar.js
+++ b/components/wallet-buttonbar.js
@@ -1,6 +1,7 @@
import { Button } from 'react-bootstrap'
import CancelButton from './cancel-button'
import { SubmitButton } from './form'
+import { isConfigured } from '@/wallets/common'
export default function WalletButtonBar ({
wallet, disable,
@@ -10,12 +11,12 @@ export default function WalletButtonBar ({
return (
- {wallet.hasConfig && wallet.isConfigured &&
+ {isConfigured(wallet) &&
}
{children}
{hasCancel && }
- {wallet.isConfigured ? editText : createText}
+ {isConfigured(wallet) ? editText : createText}
diff --git a/components/wallet-card.js b/components/wallet-card.js
index 7f2ae297..36328920 100644
--- a/components/wallet-card.js
+++ b/components/wallet-card.js
@@ -3,26 +3,18 @@ import styles from '@/styles/wallet.module.css'
import Plug from '@/svgs/plug.svg'
import Gear from '@/svgs/settings-5-fill.svg'
import Link from 'next/link'
-import { Status } from '@/wallets/common'
+import { Status, isConfigured } from '@/wallets/common'
import DraggableIcon from '@/svgs/draggable.svg'
export default function WalletCard ({ wallet, draggable, onDragStart, onDragEnter, onDragEnd, onTouchStart, sourceIndex, targetIndex, index }) {
- const { card: { title, badges } } = wallet
+ const { card: { title, badges } } = wallet.def
let indicator = styles.disabled
switch (wallet.status) {
case Status.Enabled:
- case true:
indicator = styles.success
break
- case Status.Locked:
- indicator = styles.warning
- break
- case Status.Error:
- indicator = styles.error
- break
- case Status.Initialized:
- case false:
+ default:
indicator = styles.disabled
break
}
@@ -57,9 +49,9 @@ export default function WalletCard ({ wallet, draggable, onDragStart, onDragEnte
)}
-
+
- {wallet.isConfigured
+ {isConfigured(wallet)
? <>configure>
: <>attach>}
diff --git a/components/wallet-logger.js b/components/wallet-logger.js
index f9814c80..19e23f57 100644
--- a/components/wallet-logger.js
+++ b/components/wallet-logger.js
@@ -86,10 +86,14 @@ const INDICES = [
{ name: 'wallet_ts', keyPath: ['wallet', 'ts'] }
]
+function getWalletLogDbName (userId) {
+ return getDbName(userId)
+}
+
function useWalletLogDB () {
const { me } = useMe()
const { add, getPage, clear, error, notSupported } = useIndexedDB({
- dbName: getDbName(me?.id),
+ dbName: getWalletLogDbName(me?.id),
storeName: 'wallet_logs',
indices: INDICES
})
@@ -127,7 +131,7 @@ export function useWalletLogger (wallet, setLogs) {
)
const deleteLogs = useCallback(async (wallet, options) => {
- if ((!wallet || wallet.walletType) && !options?.clientOnly) {
+ if ((!wallet || wallet.def.walletType) && !options?.clientOnly) {
await deleteServerWalletLogs({ variables: { wallet: wallet?.walletType } })
}
if (!wallet || wallet.sendPayment) {
@@ -190,7 +194,7 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
result = await getPage(page, pageSize, indexName, query, 'prev')
// no walletType means we're using the local IDB
- if (wallet && !wallet.walletType) {
+ if (wallet && !wallet.def.walletType) {
return result
}
}
diff --git a/pages/_app.js b/pages/_app.js
index 95f2a446..d138e412 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -22,7 +22,7 @@ import dynamic from 'next/dynamic'
import { HasNewNotesProvider } from '@/components/use-has-new-notes'
import { WebLnProvider } from '@/wallets/webln/client'
import { AccountProvider } from '@/components/account'
-import { WalletProvider } from '@/wallets/common'
+import { WalletsProvider } from '@/wallets/index'
const PWAPrompt = dynamic(() => import('react-ios-pwa-prompt'), { ssr: false })
@@ -105,7 +105,7 @@ export default function MyApp ({ Component, pageProps: { ...props } }) {
-
+
@@ -132,7 +132,7 @@ export default function MyApp ({ Component, pageProps: { ...props } }) {
-
+
diff --git a/pages/settings/wallets/[wallet].js b/pages/settings/wallets/[wallet].js
index 80f41465..196dffc2 100644
--- a/pages/settings/wallets/[wallet].js
+++ b/pages/settings/wallets/[wallet].js
@@ -5,14 +5,13 @@ import { WalletSecurityBanner } from '@/components/banners'
import { WalletLogs } from '@/components/wallet-logger'
import { useToast } from '@/components/toast'
import { useRouter } from 'next/router'
-import { useWallet } from '@/wallets/common'
+import { useWallet } from '@/wallets/index'
import Info from '@/components/info'
import Text from '@/components/text'
import { AutowithdrawSettings } from '@/components/autowithdraw-shared'
-import dynamic from 'next/dynamic'
-import { useIsClient } from '@/components/use-client'
-
-const WalletButtonBar = dynamic(() => import('@/components/wallet-buttonbar.js'), { ssr: false })
+import { isConfigured } from '@/wallets/common'
+import { SSR } from '@/lib/constants'
+import WalletButtonBar from '@/components/wallet-buttonbar'
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
@@ -22,7 +21,7 @@ export default function WalletSettings () {
const { wallet: name } = router.query
const wallet = useWallet(name)
- const initial = wallet?.fields.reduce((acc, field) => {
+ const initial = wallet?.def.fields.reduce((acc, field) => {
// We still need to run over all wallet fields via reduce
// even though we use wallet.config as the initial value
// since wallet.config is empty when wallet is not configured.
@@ -41,8 +40,8 @@ export default function WalletSettings () {
return (
- {wallet?.card?.title}
- {wallet?.card?.subtitle}
+ {wallet?.def.card.title}
+ {wallet?.def.card.subtitle}
{wallet?.canSend && wallet?.hasConfig > 0 && }