system messages
This commit is contained in:
27
app/hooks/useDeviceMessage.ts
Normal file
27
app/hooks/useDeviceMessage.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { PacketDeviceNew } from "../providers/ProtocolProvider/protocol/packets/packet.device.new";
|
||||||
|
import { usePacket } from "../providers/ProtocolProvider/usePacket";
|
||||||
|
import { useSendSystemMessage } from "../providers/SystemAccountsProvider/useSendSystemMessage";
|
||||||
|
import { dotCenterIfNeeded } from "../utils/utils";
|
||||||
|
|
||||||
|
const messageTemplate = `
|
||||||
|
**Attempt to login from a new device**
|
||||||
|
|
||||||
|
We detected a login to your account from **{os}** a new device **by seed phrase**. If this was you, you can safely ignore this message.
|
||||||
|
|
||||||
|
**OS:** {os}
|
||||||
|
**IP:** {ip}
|
||||||
|
**Device:** {device}
|
||||||
|
**ID:** {deviceId}`
|
||||||
|
|
||||||
|
export function useDeviceMessage() {
|
||||||
|
const send = useSendSystemMessage("safe");
|
||||||
|
|
||||||
|
usePacket(0x09, (packet: PacketDeviceNew) => {
|
||||||
|
send(messageTemplate
|
||||||
|
.replace("{ip}", packet.getIpAddress())
|
||||||
|
.replace("{device}", packet.getDevice().deviceName)
|
||||||
|
.replace("{os}", packet.getDevice().deviceOs)
|
||||||
|
.replace("{deviceId}", dotCenterIfNeeded(packet.getDevice().deviceId, 12, 4))
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
20
app/hooks/useUpdateMessage.ts
Normal file
20
app/hooks/useUpdateMessage.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { usePublicKey } from "../providers/AccountProvider/usePublicKey";
|
||||||
|
import { APP_VERSION, RELEASE_NOTICE } from "../version";
|
||||||
|
import { useSendSystemMessage } from "../providers/SystemAccountsProvider/useSendSystemMessage";
|
||||||
|
|
||||||
|
export function useUpdateMessage() {
|
||||||
|
const publicKey = usePublicKey();
|
||||||
|
const lastNoticeVersion = localStorage.getItem("lastNoticeVersion") || "0.0.0";
|
||||||
|
const send = useSendSystemMessage("updates");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(publicKey == ""){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(lastNoticeVersion !== APP_VERSION){
|
||||||
|
send(RELEASE_NOTICE);
|
||||||
|
localStorage.setItem("lastNoticeVersion", APP_VERSION);
|
||||||
|
}
|
||||||
|
}, [lastNoticeVersion, publicKey]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user