Skip to content

Commit 2a6b24d

Browse files
committed
refactor(db): move wallet related code to separate directory (#529)
1 parent f5c4050 commit 2a6b24d

Some content is hidden

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

43 files changed

+211
-212
lines changed

packages/background/src/services/db.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { Account } from '@workspace/db/account/account'
55
import { accountCreate } from '@workspace/db/account/account-create'
66
import { accountFindUnique } from '@workspace/db/account/account-find-unique'
77
import { db } from '@workspace/db/db'
8-
import { dbWalletCreate } from '@workspace/db/db-wallet-create'
9-
import type { WalletInputCreate } from '@workspace/db/dto/wallet-input-create'
108
import { settingGetValue } from '@workspace/db/setting/setting-get-value'
9+
import { walletCreate } from '@workspace/db/wallet/wallet-create'
10+
import type { WalletCreateInput } from '@workspace/db/wallet/wallet-create-input'
1111
import { deriveFromMnemonicAtIndex } from '@workspace/keypair/derive-from-mnemonic-at-index'
1212
import { ellipsify } from '@workspace/ui/lib/ellipsify'
1313

@@ -45,11 +45,11 @@ export const [registerDbService, getDbService] = defineProxyService('DbService',
4545
},
4646
},
4747
wallet: {
48-
createWithAccount: async (input: WalletInputCreate) => {
48+
createWithAccount: async (input: WalletCreateInput) => {
4949
// First, we see if we can derive the first account from this mnemonic
5050
const derivedAccount = await deriveFromMnemonicAtIndex({ mnemonic: input.mnemonic })
5151
// If so, we create the wallet
52-
const walletId = await dbWalletCreate(db, input)
52+
const walletId = await walletCreate(db, input)
5353
// After creating the wallet we can create the account
5454
await accountCreate(db, {
5555
...derivedAccount,
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { type MutateOptions, mutationOptions, queryOptions } from '@tanstack/react-query'
22
import { db } from '@workspace/db/db'
3-
import { dbWalletCreate } from '@workspace/db/db-wallet-create'
4-
import { dbWalletDelete } from '@workspace/db/db-wallet-delete'
5-
import { dbWalletFindMany } from '@workspace/db/db-wallet-find-many'
6-
import { dbWalletFindUnique } from '@workspace/db/db-wallet-find-unique'
7-
import { dbWalletSetActive } from '@workspace/db/db-wallet-set-active'
8-
import { dbWalletUpdate } from '@workspace/db/db-wallet-update'
9-
import type { WalletInputCreate } from '@workspace/db/dto/wallet-input-create'
10-
import type { WalletInputFindMany } from '@workspace/db/dto/wallet-input-find-many'
11-
import type { WalletInputUpdate } from '@workspace/db/dto/wallet-input-update'
3+
import { walletCreate } from '@workspace/db/wallet/wallet-create'
4+
import type { WalletCreateInput } from '@workspace/db/wallet/wallet-create-input'
5+
import { walletDelete } from '@workspace/db/wallet/wallet-delete'
6+
import { walletFindMany } from '@workspace/db/wallet/wallet-find-many'
7+
import type { WalletFindManyInput } from '@workspace/db/wallet/wallet-find-many-input'
8+
import { walletFindUnique } from '@workspace/db/wallet/wallet-find-unique'
9+
import { walletSetActive } from '@workspace/db/wallet/wallet-set-active'
10+
import { walletUpdate } from '@workspace/db/wallet/wallet-update'
11+
import type { WalletUpdateInput } from '@workspace/db/wallet/wallet-update-input'
1212
import { queryClient } from './db-query-client.tsx'
1313
import { dbSettingOptions } from './db-setting-options.tsx'
1414

15-
export type DbWalletCreateMutateOptions = MutateOptions<string, Error, { input: WalletInputCreate }>
15+
export type DbWalletCreateMutateOptions = MutateOptions<string, Error, { input: WalletCreateInput }>
1616
export type DbWalletDeleteMutateOptions = MutateOptions<void, Error, { id: string }>
1717
export type DbWalletSetActiveMutateOptions = MutateOptions<void, Error, { id: string }>
18-
export type DbWalletUpdateMutateOptions = MutateOptions<number, Error, { input: WalletInputUpdate }>
18+
export type DbWalletUpdateMutateOptions = MutateOptions<number, Error, { input: WalletUpdateInput }>
1919

2020
export const dbWalletOptions = {
2121
create: (props: DbWalletCreateMutateOptions = {}) =>
2222
mutationOptions({
23-
mutationFn: ({ input }: { input: WalletInputCreate }) => dbWalletCreate(db, input),
23+
mutationFn: ({ input }: { input: WalletCreateInput }) => walletCreate(db, input),
2424
onSuccess: () => {
2525
queryClient.invalidateQueries(dbSettingOptions.getAll())
2626
queryClient.invalidateQueries(dbSettingOptions.getValue('activeWalletId'))
@@ -29,22 +29,22 @@ export const dbWalletOptions = {
2929
}),
3030
delete: (props: DbWalletDeleteMutateOptions = {}) =>
3131
mutationOptions({
32-
mutationFn: ({ id }: { id: string }) => dbWalletDelete(db, id),
32+
mutationFn: ({ id }: { id: string }) => walletDelete(db, id),
3333
...props,
3434
}),
35-
findMany: (input: WalletInputFindMany) =>
35+
findMany: (input: WalletFindManyInput) =>
3636
queryOptions({
37-
queryFn: () => dbWalletFindMany(db, input),
38-
queryKey: ['dbWalletFindMany', input],
37+
queryFn: () => walletFindMany(db, input),
38+
queryKey: ['walletFindMany', input],
3939
}),
4040
findUnique: (id: string) =>
4141
queryOptions({
42-
queryFn: () => dbWalletFindUnique(db, id),
43-
queryKey: ['dbWalletFindUnique', id],
42+
queryFn: () => walletFindUnique(db, id),
43+
queryKey: ['walletFindUnique', id],
4444
}),
4545
setActive: (props: DbWalletSetActiveMutateOptions = {}) =>
4646
mutationOptions({
47-
mutationFn: ({ id }: { id: string }) => dbWalletSetActive(db, id),
47+
mutationFn: ({ id }: { id: string }) => walletSetActive(db, id),
4848
onSuccess: () => {
4949
queryClient.invalidateQueries(dbSettingOptions.getAll())
5050
queryClient.invalidateQueries(dbSettingOptions.getValue('activeWalletId'))
@@ -54,7 +54,7 @@ export const dbWalletOptions = {
5454
}),
5555
update: (props: DbWalletUpdateMutateOptions = {}) =>
5656
mutationOptions({
57-
mutationFn: ({ id, input }: { id: string; input: WalletInputUpdate }) => dbWalletUpdate(db, id, input),
57+
mutationFn: ({ id, input }: { id: string; input: WalletUpdateInput }) => walletUpdate(db, id, input),
5858
...props,
5959
}),
6060
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useQuery } from '@tanstack/react-query'
2-
import type { WalletInputFindMany } from '@workspace/db/dto/wallet-input-find-many'
2+
import type { WalletFindManyInput } from '@workspace/db/wallet/wallet-find-many-input'
33

44
import { dbWalletOptions } from './db-wallet-options.tsx'
55

6-
export function useDbWalletFindMany({ input }: { input: WalletInputFindMany }) {
6+
export function useDbWalletFindMany({ input }: { input: WalletFindManyInput }) {
77
return useQuery(dbWalletOptions.findMany(input))
88
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { db } from '@workspace/db/db'
2-
import { dbWalletFindMany } from '@workspace/db/db-wallet-find-many'
3-
import type { Wallet } from '@workspace/db/entity/wallet'
2+
import type { Wallet } from '@workspace/db/wallet/wallet'
3+
import { walletFindMany } from '@workspace/db/wallet/wallet-find-many'
44
import { useLiveQuery } from 'dexie-react-hooks'
55

66
export function useDbWalletLive() {
7-
return useLiveQuery<Wallet[], Wallet[]>(() => dbWalletFindMany(db), [], [])
7+
return useLiveQuery<Wallet[], Wallet[]>(() => walletFindMany(db), [], [])
88
}

packages/db/src/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Dexie, type Table } from 'dexie'
22
import type { Account } from './account/account.ts'
33
import { dbPopulate } from './db-populate.ts'
4-
import type { Wallet } from './entity/wallet.ts'
54
import type { Network } from './network/network.ts'
65
import type { Setting } from './setting/setting.ts'
6+
import type { Wallet } from './wallet/wallet.ts'
77

88
export interface DatabaseConfig {
99
name: string

packages/db/src/db-wallet-update.ts

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

packages/db/src/dto/wallet-input-create.ts

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

packages/db/src/dto/wallet-input-find-many.ts

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

packages/db/src/dto/wallet-input-update.ts

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

packages/db/src/db-wallet-create-determine-order.ts renamed to packages/db/src/wallet/wallet-create-determine-order.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { tryCatch } from '@workspace/core/try-catch'
22

3-
import type { Database } from './database.ts'
3+
import type { Database } from '../database.ts'
44

5-
export async function dbWalletCreateDetermineOrder(db: Database): Promise<number> {
5+
export async function walletCreateDetermineOrder(db: Database): Promise<number> {
66
const { data, error } = await tryCatch(db.wallets.orderBy('order').last())
77

88
if (error) {

0 commit comments

Comments
 (0)