-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SQLite, account creation, and account fetching #16
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5287dc4
WIP
dguenther 6d77edc
Add support for mutation options to data facade
dguenther 0b6ba4f
Add creating and getting accounts from sqlite
dguenther a1c99e9
Set DEMO to true by default
dguenther 32168a7
Restructure folders
dguenther 8be21e8
Add README
dguenther File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
# facades | ||
|
||
Facades use the `data-facade` package to provide a `tanstack/react-query` interface between the wallet code in the `data` folder and the Expo frontend in the `app` folder. | ||
|
||
The facade routes are intended to be similar to the [Iron Fish RPC routes](https://github.com/iron-fish/ironfish/tree/master/ironfish/src/rpc/routes). Our goal is that in the future, we could implement a facade that connects directly to an Iron Fish node with minimal changes to the frontend code. |
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,38 @@ | ||
import { f } from "data-facade"; | ||
import { z } from "zod"; | ||
import { AccountsMethods } from "./types"; | ||
|
||
let ACCOUNTS = [ | ||
{ id: 0, name: "alice", viewOnlyAccount: "alice" }, | ||
{ id: 1, name: "bob", viewOnlyAccount: "bob"}, | ||
{ id: 2, name: "carol", viewOnlyAccount: "carol"} | ||
]; | ||
|
||
async function getAccounts(limit: number) { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return ACCOUNTS.slice(0, limit); | ||
} | ||
|
||
export const accountsHandlers = f.facade<AccountsMethods>({ | ||
getAccounts: f.handler.query(async () => { | ||
const accounts = await getAccounts(ACCOUNTS.length); | ||
console.log("getAccounts", accounts); | ||
return accounts; | ||
}), | ||
createAccount: f.handler | ||
.input( | ||
z.object({ | ||
name: z.string(), | ||
}), | ||
) | ||
.mutation(async ({ name }) => { | ||
const existingId = ACCOUNTS.at(-1)?.id | ||
if (existingId === undefined) { | ||
throw new Error("No accounts found"); | ||
} | ||
const account = { id: existingId + 1, name, viewOnlyAccount: name } | ||
console.log("createAccount", account); | ||
ACCOUNTS.push(account); | ||
return account; | ||
}), | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: IIRC, it's possible to set a default for this with React Query. I'd recommend busting the whole cache on mutation. IMO, being overly aggressive with cache busting after a mutation is usually the way to go; especially for stuff like accounts that will be on-device, so the request doesn't even need to go over the wire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the node app, we handle this at the
trpc-react
level: https://github.com/iron-fish/ironfish-node-app/blob/9712ebf2cd64507b42b8a055ab9efebc9a808f6d/renderer/providers/TRPCProvider.tsx#L14So I think we'd need to add something to
data-facade
to allow for this? We can pass defaultOptions to the QueryClient to setonSuccess
by default, but it would get clobbered if we wanted to setonSuccess
on mutations explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to kick this down the road and add a ticket in Linear for it: https://linear.app/if-labs/issue/IFL-2522/invalidate-react-query-query-cache-on-all-mutations