Merge pull request #1614 from stackernews/wallet-fixes

Wallet fixes
This commit is contained in:
Keyan 2024-11-19 15:49:12 -06:00 committed by GitHub
commit 9179688abc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 10 deletions

View File

@ -27,12 +27,17 @@ function useIndexedDB ({ dbName, storeName, options = DEFAULT_OPTIONS, indices =
db.transaction(storeName) db.transaction(storeName)
while (operationQueue.current.length > 0) { while (operationQueue.current.length > 0) {
const operation = operationQueue.current.shift() const operation = operationQueue.current.shift()
operation(db) // if the db is the same as the one we're processing, run the operation
// else, we'll just clear the operation queue
// XXX this is a consquence of using a ref to store the queue and should be fixed
if (dbName === db.name) {
operation(db)
}
} }
} catch (error) { } catch (error) {
handleError(error) handleError(error)
} }
}, [storeName, handleError, operationQueue]) }, [dbName, storeName, handleError, operationQueue])
useEffect(() => { useEffect(() => {
let isMounted = true let isMounted = true

View File

@ -13,11 +13,12 @@ import { canReceive, canSend, isConfigured } from '@/wallets/common'
import { SSR } from '@/lib/constants' import { SSR } from '@/lib/constants'
import WalletButtonBar from '@/components/wallet-buttonbar' import WalletButtonBar from '@/components/wallet-buttonbar'
import { useWalletConfigurator } from '@/wallets/config' import { useWalletConfigurator } from '@/wallets/config'
import { useCallback, useMemo } from 'react' import { useCallback, useEffect, useMemo, useState } from 'react'
import { useMe } from '@/components/me' import { useMe } from '@/components/me'
import validateWallet from '@/wallets/validate' import validateWallet from '@/wallets/validate'
import { ValidationError } from 'yup' import { ValidationError } from 'yup'
import { useFormikContext } from 'formik' import { useFormikContext } from 'formik'
import useDarkMode from '@/components/dark-mode'
export const getServerSideProps = getGetServerSideProps({ authRequired: true }) export const getServerSideProps = getGetServerSideProps({ authRequired: true })
@ -28,6 +29,8 @@ export default function WalletSettings () {
const wallet = useWallet(name) const wallet = useWallet(name)
const { me } = useMe() const { me } = useMe()
const { save, detach } = useWalletConfigurator(wallet) const { save, detach } = useWalletConfigurator(wallet)
const [dark] = useDarkMode()
const [imgSrc, setImgSrc] = useState(wallet?.def.card?.image?.src)
const initial = useMemo(() => { const initial = useMemo(() => {
const initial = wallet?.def.fields.reduce((acc, field) => { const initial = wallet?.def.fields.reduce((acc, field) => {
@ -69,12 +72,16 @@ export default function WalletSettings () {
const { card: { image, title, subtitle } } = wallet?.def || { card: {} } const { card: { image, title, subtitle } } = wallet?.def || { card: {} }
useEffect(() => {
if (!imgSrc) return
// wallet.png <-> wallet-dark.png
setImgSrc(dark ? image?.src.replace(/\.([a-z]{3})$/, '-dark.$1') : image?.src)
}, [dark])
return ( return (
<CenterLayout> <CenterLayout>
{image {image
? typeof image === 'object' ? <img alt={title} {...image} src={imgSrc} className='pb-3 px-2 mw-100' />
? <img {...image} alt={title} className='pb-2' />
: <img src={image} width='33%' alt={title} className='pb-2' />
: <h2 className='pb-2'>{title}</h2>} : <h2 className='pb-2'>{title}</h2>}
<h6 className='text-muted text-center pb-3'><Text>{subtitle}</Text></h6> <h6 className='text-muted text-center pb-3'><Text>{subtitle}</Text></h6>
<Form <Form

View File

@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "WalletBlink" ALTER COLUMN "apiKeyRecv" DROP NOT NULL;
-- AlterTable
ALTER TABLE "WalletLNbits" ALTER COLUMN "invoiceKey" DROP NOT NULL;
-- AlterTable
ALTER TABLE "WalletNWC" ALTER COLUMN "nwcUrlRecv" DROP NOT NULL;
-- AlterTable
ALTER TABLE "WalletPhoenixd" ALTER COLUMN "secondaryPassword" DROP NOT NULL;

View File

@ -289,7 +289,7 @@ model WalletLNbits {
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
url String url String
invoiceKey String invoiceKey String?
} }
model WalletNWC { model WalletNWC {
@ -298,7 +298,7 @@ model WalletNWC {
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade) wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
nwcUrlRecv String nwcUrlRecv String?
} }
model WalletBlink { model WalletBlink {
@ -307,7 +307,7 @@ model WalletBlink {
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade) wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
apiKeyRecv String apiKeyRecv String?
currencyRecv String? currencyRecv String?
} }
@ -318,7 +318,7 @@ model WalletPhoenixd {
createdAt DateTime @default(now()) @map("created_at") createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
url String url String
secondaryPassword String secondaryPassword String?
} }
model Mute { model Mute {