chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
56 lines • 1.92 kB
JavaScript
import React, { createContext, useContext, useState } from 'react';
import * as iw from '../InitializeWallet';
const WalletContextInternal = createContext(undefined);
export const WalletContext = ({ children }) => {
const [wallet, setWallet] = useState(null);
return (React.createElement(WalletContextInternal.Provider, { value: { wallet, setWallet } }, children));
};
export function useWallet() {
const ctx = useContext(WalletContextInternal);
if (!ctx) {
throw new Error('useWallet must be used within <WalletContext>');
}
const { wallet, setWallet } = ctx;
const initializeWallet = {
async create(args) {
const c = await iw.create(args);
setWallet(c.wallet);
return c;
},
async fromPrivateKey(args) {
const wallet = await iw.fromPrivateKey(args);
setWallet(wallet);
return wallet;
},
async fromSeed(args) {
const wallet = await iw.fromSeed(args);
setWallet(wallet);
return wallet;
},
async fromPhrase(args) {
const wallet = await iw.fromPhrase(args);
setWallet(wallet);
return wallet;
},
async fromKeystore(args) {
const wallet = await iw.fromKeystore(args);
setWallet(wallet);
return wallet;
},
async deserialize(args) {
const wallet = await iw.deserialize(args);
setWallet(wallet);
return wallet;
},
checkPhrase: iw.checkPhrase,
checkSeed: iw.checkSeed,
checkPrivateKey: iw.checkPrivateKey,
checkKeystore: iw.checkKeystore,
checkSerialized: iw.checkSerialized,
};
const closeWallet = () => {
setWallet(null);
};
return { wallet, initializeWallet, closeWallet };
}
//# sourceMappingURL=WalletContext.js.map