2021-10-22 18:50:31 +00:00
|
|
|
import {
|
|
|
|
Dispatch,
|
|
|
|
SetStateAction,
|
|
|
|
createContext,
|
|
|
|
useState,
|
|
|
|
useContext,
|
|
|
|
} from "react";
|
2021-07-14 06:52:31 +00:00
|
|
|
|
2021-10-28 05:54:36 +00:00
|
|
|
export type SelectionType = "address" | "value" | "functionSig";
|
|
|
|
|
2021-07-14 06:52:31 +00:00
|
|
|
export type Selection = {
|
2021-10-28 05:54:36 +00:00
|
|
|
type: SelectionType;
|
2021-07-14 06:52:31 +00:00
|
|
|
content: string;
|
|
|
|
};
|
|
|
|
|
2021-10-28 05:54:36 +00:00
|
|
|
export type OptionalSelection = Selection | null;
|
2021-10-22 18:50:31 +00:00
|
|
|
|
2021-07-14 06:52:31 +00:00
|
|
|
export const useSelection = (): [
|
2021-10-22 18:50:31 +00:00
|
|
|
OptionalSelection,
|
|
|
|
Dispatch<SetStateAction<OptionalSelection>>
|
2021-07-14 06:52:31 +00:00
|
|
|
] => {
|
2021-10-22 18:50:31 +00:00
|
|
|
return useState<OptionalSelection>(null);
|
2021-07-14 06:52:31 +00:00
|
|
|
};
|
|
|
|
|
2021-10-22 18:50:31 +00:00
|
|
|
export const SelectionContext = createContext<ReturnType<typeof useSelection>>(
|
|
|
|
null!
|
|
|
|
);
|
2021-07-14 06:52:31 +00:00
|
|
|
|
|
|
|
export const useSelectionContext = () => {
|
2021-10-22 18:50:31 +00:00
|
|
|
return useContext(SelectionContext);
|
2021-07-14 06:52:31 +00:00
|
|
|
};
|