new devices system prototype
This commit is contained in:
23
app/providers/DeviceProvider/useVerifyRequest.ts
Normal file
23
app/providers/DeviceProvider/useVerifyRequest.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user