-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
5,478 additions
and
8,809 deletions.
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.
Large diffs are not rendered by default.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ | |
"package": "com.ironfish.mobileapp" | ||
}, | ||
"plugins": [ | ||
"expo-router" | ||
"expo-router", | ||
"expo-secure-store" | ||
] | ||
} | ||
} |
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,34 +1,48 @@ | ||
import { View, Text } from "react-native"; | ||
import { useFacade } from "../../data"; | ||
import { View, Text, ScrollView, TextInput } from "react-native"; | ||
import { useFacade } from "../../data/facades"; | ||
import { Button } from "@ironfish/ui"; | ||
import { useState } from "react"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
|
||
export default function Transact() { | ||
const [facadeResult, setFacadeResult] = useState([""]); | ||
const facade = useFacade(); | ||
const qc = useQueryClient(); | ||
|
||
const getAccountsResult = facade.getAccounts.useQuery(123); | ||
const getAccountsWithZodResult = facade.getAccountsWithZod.useQuery({ | ||
limit: 2, | ||
const getAccountsResult = facade.getAccounts.useQuery(); | ||
const createAccount = facade.createAccount.useMutation({ | ||
onSuccess: () => { | ||
qc.invalidateQueries({ | ||
queryKey: ["getAccounts"], | ||
}); | ||
}, | ||
}); | ||
const getAllAccountsResult = facade.getAllAccounts.useQuery(); | ||
const createAccount = facade.createAccount.useMutation(); | ||
const exportAccount = facade.exportAccount.useMutation(); | ||
|
||
return ( | ||
<View> | ||
<ScrollView> | ||
<Text>Accounts</Text> | ||
<Text>{JSON.stringify(getAccountsResult.data)}</Text> | ||
<Text>{JSON.stringify(getAccountsWithZodResult.data)}</Text> | ||
<Text>{JSON.stringify(getAllAccountsResult.data)}</Text> | ||
<Text>Mutation: {facadeResult}</Text> | ||
{(getAccountsResult.data ?? []).map((account) => ( | ||
<View key={account.id}> | ||
<Text>{account.name}</Text> | ||
<Button | ||
onPress={async () => { | ||
const otherResult = await exportAccount.mutateAsync({ | ||
name: account.name, | ||
}); | ||
console.log("Exported Account:", otherResult); | ||
}} | ||
> | ||
Export Account | ||
</Button> | ||
</View> | ||
))} | ||
<Button | ||
onPress={async () => { | ||
const otherResult = await createAccount.mutateAsync("dave"); | ||
setFacadeResult(otherResult); | ||
const otherResult = await createAccount.mutateAsync({ name: "dave" }); | ||
console.log("Created Account:", otherResult); | ||
}} | ||
> | ||
Click me | ||
Create Account | ||
</Button> | ||
</View> | ||
</ScrollView> | ||
); | ||
} |
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,51 @@ | ||
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; | ||
}), | ||
exportAccount: f.handler | ||
.input( | ||
z.object({ | ||
name: z.string(), | ||
}), | ||
) | ||
.mutation(async ({ name }) => { | ||
const account = ACCOUNTS.find((a) => a.name === name) | ||
if (account === undefined) { | ||
throw new Error("No accounts found"); | ||
} | ||
return JSON.stringify(account); | ||
}), | ||
}); |
Oops, something went wrong.