-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
51 additions
and
6 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
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,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> | ||
); | ||
}; |
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,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; | ||
}; |