Skip to content

Commit afcc412

Browse files
committed
Delete almost all wallet v1 code
and add some code for wallet protocol forms
1 parent f5d283d commit afcc412

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+677
-3126
lines changed

api/resolvers/vault.js

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
import { E_VAULT_KEY_EXISTS, GqlAuthenticationError, GqlInputError } from '@/lib/error'
2-
import { getWalletByType } from '@/wallets/common'
3-
import { deleteVault, hasVault, vaultNewSchematoTypedef, vaultPrismaFragments } from '@/wallets/vault'
42

53
export default {
64
Query: {
75
getVaultEntries: async (parent, args, { me, models }) => {
8-
if (!me) throw new GqlAuthenticationError()
9-
10-
const wallets = await models.wallet.findMany({
11-
where: { userId: me.id },
12-
include: vaultPrismaFragments.include()
13-
})
14-
15-
const vaultEntries = []
16-
for (const wallet of wallets) {
17-
vaultEntries.push(...vaultNewSchematoTypedef(wallet).vaultEntries)
18-
}
19-
20-
return vaultEntries
6+
// TODO(wallet-v2): this is probably not needed anymore
217
}
228
},
239
Mutation: {
@@ -36,19 +22,10 @@ export default {
3622

3723
return await models.$transaction(async tx => {
3824
// TODO(wallet-v2): use UserWallet instead of Wallet table
39-
const wallets = await tx.wallet.findMany({ where: { userId: me.id } })
40-
for (const wallet of wallets) {
41-
const def = getWalletByType(wallet.type)
42-
// TODO(wallet-v2): use UserWallet instead of Wallet table
43-
await tx.wallet.update({
44-
where: { id: wallet.id },
45-
data: {
46-
[def.walletField]: {
47-
update: vaultPrismaFragments.upsert({ ...wallet, vaultEntries: entries })
48-
}
49-
}
50-
})
51-
}
25+
// const wallets = await tx.wallet.findMany({ where: { userId: me.id } })
26+
// TODO(wallet-v2): implement this
27+
// for (const wallet of wallets) {
28+
// }
5229

5330
// optimistic concurrency control: make sure the user's vault key didn't change while we were updating the wallets
5431
await tx.user.update({
@@ -68,8 +45,8 @@ export default {
6845
}))
6946

7047
// TODO(wallet-v2): use UserWallet instead of Wallet table
71-
const wallets = await models.wallet.findMany({ where: { userId: me.id } })
72-
txs.push(...wallets.filter(hasVault).map(wallet => deleteVault(models, wallet)))
48+
// const wallets = await models.wallet.findMany({ where: { userId: me.id } })
49+
// txs.push(...wallets.filter(hasVault).map(wallet => deleteVault(models, wallet)))
7350

7451
await models.$transaction(txs)
7552
return true

api/resolvers/wallet.js

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import { finalizeHodlInvoice } from '@/worker/wallet'
2121
import { lnAddrOptions } from '@/lib/lnurl'
2222
import { GqlAuthenticationError, GqlAuthorizationError, GqlInputError } from '@/lib/error'
2323
import { getNodeSockets, getOurPubkey } from '../lnd'
24-
import { canReceive, getWalletByType } from '@/wallets/common'
2524
import performPaidAction from '../paidAction'
2625
import performPayingAction from '../payingAction'
27-
import { deleteVault, hasVault } from '@/wallets/vault'
26+
import { logContextFromBolt11 } from '@/wallets/server/logger'
2827

2928
export async function getInvoice (parent, { id }, { me, models, lnd }) {
3029
const inv = await models.invoice.findUnique({
@@ -165,6 +164,10 @@ const resolvers = {
165164

166165
return [...userWallets, ...walletTemplates]
167166
},
167+
wallet: async (parent, { name }, { me, models }) => {
168+
const template = await models.walletTemplate.findFirst({ where: { name } })
169+
return { ...template, __resolveType: 'WalletTemplate' }
170+
},
168171
withdrawl: getWithdrawl,
169172
direct: async (parent, { id }, { me, models }) => {
170173
if (!me) {
@@ -579,25 +582,7 @@ const resolvers = {
579582
throw new GqlAuthenticationError()
580583
}
581584

582-
// TODO(wallet-v2): use UserWallet instead of Wallet table
583-
const wallet = await models.wallet.findUnique({ where: { userId: me.id, id: Number(id) } })
584-
if (!wallet) {
585-
throw new GqlInputError('wallet not found')
586-
}
587-
588-
const logger = walletLogger({ wallet, models })
589-
590-
await models.$transaction([
591-
hasVault(wallet) ? deleteVault(models, wallet) : null,
592-
// TODO(wallet-v2): use UserWallet instead of Wallet table
593-
models.wallet.delete({ where: { userId: me.id, id: Number(id) } })
594-
].filter(Boolean))
595-
596-
if (canReceive({ def: getWalletByType(wallet.type), config: wallet.wallet })) {
597-
logger.info('details for receiving deleted')
598-
}
599-
600-
return true
585+
// TODO(wallet-v2): implement this
601586
},
602587
deleteWalletLogs: async (parent, { wallet }, { me, models }) => {
603588
if (!me) {
@@ -776,67 +761,6 @@ const resolvers = {
776761
// TODO(wallet-v2): implement wallet resolvers
777762
export default resolvers
778763

779-
const logContextFromBolt11 = async (bolt11) => {
780-
const decoded = await parsePaymentRequest({ request: bolt11 })
781-
return {
782-
bolt11,
783-
amount: formatMsats(decoded.mtokens),
784-
payment_hash: decoded.id,
785-
created_at: decoded.created_at,
786-
expires_at: decoded.expires_at,
787-
description: decoded.description
788-
}
789-
}
790-
791-
export const walletLogger = ({ wallet, models, me }) => {
792-
// no-op logger if no wallet or user provided
793-
if (!wallet && !me) {
794-
return {
795-
ok: () => {},
796-
info: () => {},
797-
error: () => {},
798-
warn: () => {}
799-
}
800-
}
801-
802-
// server implementation of wallet logger interface on client
803-
const log = (level) => async (message, ctx = {}) => {
804-
try {
805-
let { invoiceId, withdrawalId, ...context } = ctx
806-
807-
if (context.bolt11) {
808-
// automatically populate context from bolt11 to avoid duplicating this code
809-
context = {
810-
...context,
811-
...await logContextFromBolt11(context.bolt11)
812-
}
813-
}
814-
815-
await models.walletLog.create({
816-
data: {
817-
userId: wallet?.userId ?? me.id,
818-
// system logs have no wallet
819-
wallet: wallet?.type,
820-
level,
821-
message,
822-
context,
823-
invoiceId,
824-
withdrawalId
825-
}
826-
})
827-
} catch (err) {
828-
console.error('error creating wallet log:', err)
829-
}
830-
}
831-
832-
return {
833-
ok: (message, context) => log('SUCCESS')(message, context),
834-
info: (message, context) => log('INFO')(message, context),
835-
error: (message, context) => log('ERROR')(message, context),
836-
warn: (message, context) => log('WARN')(message, context)
837-
}
838-
}
839-
840764
export async function createWithdrawal (parent, { invoice, maxFee }, { me, models, lnd, headers, wallet, logger }) {
841765
assertApiKeyNotPermitted({ me })
842766
await validateSchema(withdrawlSchema, { invoice, maxFee })

api/typeDefs/wallet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const typeDefs = gql`
99
connectAddress: String!
1010
walletHistory(cursor: String, inc: String): History
1111
wallets: [WalletOrTemplate!]!
12+
wallet(name: String!): WalletOrTemplate
1213
walletLogs(type: String, from: String, to: String, cursor: String): WalletLog!
1314
failedInvoices: [Invoice!]!
1415
}

components/invoice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Bolt11Info from './bolt11-info'
88
import { useQuery } from '@apollo/client'
99
import { INVOICE } from '@/fragments/wallet'
1010
import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants'
11-
import { WalletConfigurationError, WalletPaymentAggregateError } from '@/wallets/errors'
11+
import { WalletConfigurationError, WalletPaymentAggregateError } from '@/wallets/client/errors'
1212
import ItemJob from './item-job'
1313
import Item from './item'
1414
import { CommentFlat } from './comment'

components/item-act.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { usePaidMutation } from './use-paid-mutation'
1313
import { ACT_MUTATION } from '@/fragments/paidAction'
1414
import { meAnonSats } from '@/lib/apollo'
1515
import { BoostItemInput } from './adv-post-form'
16-
import { useSendWallets } from '@/wallets/index'
16+
import { useSendWallets } from '@/wallets/client/hooks'
1717

1818
const defaultTips = [100, 1000, 10_000, 100_000]
1919

components/log-message.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

components/nav/common.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import SearchIcon from '../../svgs/search-line.svg'
2121
import classNames from 'classnames'
2222
import SnIcon from '@/svgs/sn.svg'
2323
import { useHasNewNotes } from '../use-has-new-notes'
24-
import { useWallets } from '@/wallets/index'
25-
import { useWalletIndicator } from '@/wallets/indicator'
24+
// import { useWallets } from '@/wallets/client/hooks'
25+
import { useWalletIndicator } from '@/wallets/client/hooks'
2626
import SwitchAccountList, { nextAccount, useAccounts } from '@/components/account'
2727
import { useShowModal } from '@/components/modal'
2828
import { numWithUnits } from '@/lib/format'
@@ -295,7 +295,7 @@ export default function LoginButton () {
295295

296296
function LogoutObstacle ({ onClose }) {
297297
const { registration: swRegistration, togglePushSubscription } = useServiceWorker()
298-
const { removeLocalWallets } = useWallets()
298+
// const { removeLocalWallets } = useWallets()
299299
const router = useRouter()
300300

301301
return (
@@ -326,7 +326,8 @@ function LogoutObstacle ({ onClose }) {
326326
await togglePushSubscription().catch(console.error)
327327
}
328328

329-
removeLocalWallets()
329+
// TODO(wallet-v2): implement this
330+
// removeLocalWallets()
330331

331332
await signOut({ callbackUrl: '/' })
332333
}}

components/nav/mobile/offcanvas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import AnonIcon from '@/svgs/spy-fill.svg'
77
import styles from './footer.module.css'
88
import canvasStyles from './offcanvas.module.css'
99
import classNames from 'classnames'
10-
import { useWalletIndicator } from '@/wallets/indicator'
10+
import { useWalletIndicator } from '@/wallets/client/hooks'
1111

1212
export default function OffCanvas ({ me, dropNavKey }) {
1313
const [show, setShow] = useState(false)

components/pay-bounty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useRoot } from './root'
88
import { ActCanceledError, useAct } from './item-act'
99
import { useLightning } from './lightning'
1010
import { useToast } from './toast'
11-
import { useSendWallets } from '@/wallets/index'
11+
import { useSendWallets } from '@/wallets/client/hooks'
1212
import { Form, SubmitButton } from './form'
1313

1414
export const payBountyCacheMods = {

components/use-invoice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useApolloClient, useMutation } from '@apollo/client'
22
import { useCallback, useMemo } from 'react'
3-
import { InvoiceCanceledError, InvoiceExpiredError, WalletReceiverError } from '@/wallets/errors'
3+
import { InvoiceCanceledError, InvoiceExpiredError, WalletReceiverError } from '@/wallets/client/errors'
44
import { RETRY_PAID_ACTION } from '@/fragments/paidAction'
55
import { INVOICE, CANCEL_INVOICE } from '@/fragments/wallet'
66

0 commit comments

Comments
 (0)