-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add swr and introduce useTransactions hook
- Loading branch information
Showing
9 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import useSWR, { mutate } from 'swr'; | ||
|
||
import { Transaction } from '~/lib/types'; | ||
|
||
interface UseTransactionsResult { | ||
data: Transaction[] | undefined; | ||
error: Error | undefined; | ||
isLoading: boolean; | ||
refetch: () => Promise<void>; | ||
} | ||
|
||
export const useTransactions = (walletId: string): UseTransactionsResult => { | ||
const { data, error, isLoading } = useSWR<Transaction[], Error>( | ||
`/api/listTransactions/${walletId}`, | ||
); | ||
|
||
const refetch = () => mutate(`/api/listTransactions/${walletId}`); | ||
|
||
return { | ||
data, | ||
error, | ||
isLoading, | ||
refetch, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
packages/circle-demo-webapp/app/routes/api.getTransaction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { GetTransactionInput } from '@circle-fin/developer-controlled-wallets'; | ||
import { ActionFunction } from '@remix-run/node'; | ||
import { ActionFunctionArgs, LoaderFunctionArgs } from '@remix-run/node'; | ||
|
||
import { sdk } from '~/lib/sdk'; | ||
|
||
export const action: ActionFunction = async ({ request }) => { | ||
/** | ||
* @deprecated Use `loader` instead | ||
*/ | ||
export async function action({ request }: ActionFunctionArgs) { | ||
const res = await sdk.getTransaction((await request.json()) as GetTransactionInput); | ||
return Response.json(res.data); | ||
}; | ||
} | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
const res = await sdk.getTransaction((await request.json()) as GetTransactionInput); | ||
return Response.json(res.data); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/circle-demo-webapp/app/routes/api.listTransactions.$walletId.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LoaderFunctionArgs } from '@remix-run/node'; | ||
|
||
import { sdk } from '~/lib/sdk'; | ||
|
||
export async function loader({ params }: LoaderFunctionArgs) { | ||
if (!params.walletId) { | ||
throw new Error('Wallet ID is required'); | ||
} | ||
|
||
const res = await sdk.listTransactions({ | ||
walletIds: [params.walletId], | ||
includeAll: true, | ||
}); | ||
|
||
return Response.json(res.data?.transactions); | ||
} |
9 changes: 0 additions & 9 deletions
9
packages/circle-demo-webapp/app/routes/api.listTransactions.tsx
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
packages/circle-demo-webapp/app/routes/api.updateWalletSet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { UpdateWalletSetInput } from '@circle-fin/developer-controlled-wallets'; | ||
import { ActionFunction } from '@remix-run/node'; | ||
import { ActionFunctionArgs } from '@remix-run/node'; | ||
|
||
import { sdk } from '~/lib/sdk'; | ||
|
||
export const action: ActionFunction = async ({ request }) => { | ||
export async function action({ request }: ActionFunctionArgs) { | ||
const res = await sdk.updateWalletSet((await request.json()) as UpdateWalletSetInput); | ||
return Response.json(res.data); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters