Skip to content

Commit

Permalink
added context
Browse files Browse the repository at this point in the history
  • Loading branch information
ritvij14 committed Aug 16, 2022
1 parent 7068a64 commit 8e20de7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
9 changes: 6 additions & 3 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MintImageStack from "./routes/MintImageStack";
import AppLoading from "expo-app-loading";
import { useFonts } from "expo-font";
import Drawer from "./routes/Drawer";
import { NiftyAppProvider } from "./utils/context";

const NETWORK = clusterApiUrl("devnet");

Expand Down Expand Up @@ -371,9 +372,11 @@ export default function App() {
return <AppLoading />;
} else {
return (
<NativeBaseProvider>
<Drawer />
</NativeBaseProvider>
<NiftyAppProvider>
<NativeBaseProvider>
<Drawer />
</NativeBaseProvider>
</NiftyAppProvider>
);
}
}
Expand Down
27 changes: 27 additions & 0 deletions utils/context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PublicKey } from "@solana/web3.js";
import React, { useState } from "react";
import nacl from "tweetnacl";
import { NiftyContext, NiftyState } from "./types";

export const NiftyAppContext = React.createContext<NiftyContext>(null);

export const NiftyAppProvider: React.FC<React.ReactNode> = ({ children }) => {
const initialState: NiftyState = {
dappkeypair: nacl.box.keyPair(),
sharedsecret: new Uint8Array([]),
phantomWalletPublicKey: "",
session: PublicKey.default,
};
const [state, setState] = useState(initialState);

const updateState = (newState: NiftyState) => {
setState({
...newState,
...state,
});
};

return (
<NiftyAppContext.Provider value={{ state, updateState }}>{children}</NiftyAppContext.Provider>
);
};
14 changes: 14 additions & 0 deletions utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BoxKeyPair } from "tweetnacl";
import { PublicKey } from "@solana/web3.js";

export interface NiftyState {
dappkeypair: BoxKeyPair;
sharedsecret: Uint8Array;
phantomWalletPublicKey: string;
session: PublicKey;
}

export type NiftyContext = {
state: NiftyState;
updateState: (newState: NiftyState) => void;
};

0 comments on commit 8e20de7

Please sign in to comment.