2023-01-19 12:10:52 +00:00
|
|
|
import { useCallback, useContext } from 'react';
|
|
|
|
import { useVegaWalletDialogStore, VegaWalletContext } from '.';
|
2022-02-22 06:40:55 +00:00
|
|
|
|
|
|
|
export function useVegaWallet() {
|
|
|
|
const context = useContext(VegaWalletContext);
|
|
|
|
if (context === undefined) {
|
|
|
|
throw new Error('useVegaWallet must be used within VegaWalletProvider');
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
2023-01-19 12:10:52 +00:00
|
|
|
|
|
|
|
export function useReconnectVegaWallet() {
|
|
|
|
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
|
|
|
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
|
|
}));
|
|
|
|
const { disconnect } = useVegaWallet();
|
|
|
|
const reconnect = useCallback(async () => {
|
|
|
|
await disconnect();
|
|
|
|
openVegaWalletDialog();
|
|
|
|
}, [disconnect, openVegaWalletDialog]);
|
|
|
|
|
|
|
|
return reconnect;
|
|
|
|
}
|