23 lines
870 B
TypeScript
23 lines
870 B
TypeScript
import { useContext } from "react";
|
|
import { DeviceEntry, DeviceVerifyState } from "../ProtocolProvider/protocol/packets/packet.device.list";
|
|
import { DeviceProviderContext } from "./DeviceProvider";
|
|
|
|
/**
|
|
* Получает устройство ожидающее подтверждения, если оно есть
|
|
* @returns возвращает устройство которое сейчас ждет одобрения
|
|
* от других устройств
|
|
*/
|
|
export function useVerifyRequest() : DeviceEntry | null {
|
|
const context = useContext(DeviceProviderContext);
|
|
if(!context) {
|
|
throw new Error("useVerifyRequest must be used within a DeviceProvider");
|
|
}
|
|
|
|
const pending = context.devices.find(device => device.deviceVerify === DeviceVerifyState.NOT_VERIFIED);
|
|
|
|
if(!pending) {
|
|
return null;
|
|
}
|
|
|
|
return pending;
|
|
} |