-
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.
fix(solidr-front): simplify wallet provider
- Loading branch information
t.chambard
committed
Jul 21, 2024
1 parent
773cc1e
commit 142e871
Showing
4 changed files
with
24 additions
and
56 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
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 |
---|---|---|
@@ -1,58 +1,21 @@ | ||
import { atom } from "recoil"; | ||
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"; | ||
import { | ||
Connection, | ||
LAMPORTS_PER_SOL, | ||
PublicKey, | ||
clusterApiUrl, | ||
} from "@solana/web3.js"; | ||
import { SolidrClient } from "@solidr"; | ||
|
||
type WalletState = { | ||
network: WalletAdapterNetwork; | ||
endpoint: string; | ||
connection: Connection; | ||
}; | ||
|
||
type TxState = { | ||
pending: boolean; | ||
error?: string; | ||
pending: boolean; | ||
error?: string; | ||
}; | ||
|
||
export const network = WalletAdapterNetwork.Devnet; | ||
export const endpoint = clusterApiUrl(network); | ||
// export const endpoint = 'http://localhost:8899/'; | ||
export const connection = new Connection(endpoint, "confirmed"); | ||
|
||
export const walletState = atom<WalletState>({ | ||
key: "walletState", | ||
default: { | ||
network, | ||
endpoint, | ||
connection, | ||
}, | ||
dangerouslyAllowMutability: true, | ||
}); | ||
|
||
export const txState = atom<TxState>({ | ||
key: "txState", | ||
default: { | ||
pending: false, | ||
}, | ||
dangerouslyAllowMutability: true, | ||
key: "txState", | ||
default: { | ||
pending: false, | ||
}, | ||
dangerouslyAllowMutability: true, | ||
}); | ||
|
||
export const solidrClientState = atom<SolidrClient | undefined>({ | ||
key: "solidrClientState", | ||
default: undefined, | ||
dangerouslyAllowMutability: true, | ||
key: "solidrClientState", | ||
default: undefined, | ||
dangerouslyAllowMutability: true, | ||
}); | ||
|
||
export async function getSolanaBalance(publicKey: string): Promise<number> { | ||
const balanceInLamports = await connection.getBalance( | ||
new PublicKey(publicKey), | ||
); | ||
const balanceInSol = balanceInLamports / LAMPORTS_PER_SOL; | ||
|
||
return balanceInSol; | ||
} |