Skip to content

Commit cc67067

Browse files
authored
Fix: Use kanda IP endpoint for tracking (#56)
1 parent 6302269 commit cc67067

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ks-component-ts/src/field/components/FingerprintBooleanInput/FingerprintBooleanInputUncontrolled/helpers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ const handleResponse = async (
1515
return null;
1616
};
1717

18-
export const getIp = async () => fetch(IP_ENDPOINT_URL).then(handleResponse);
19-
2018
export const getCurrentTimeStamp = (): number => new Date().getTime();

ks-component-ts/src/field/components/FingerprintBooleanInput/FingerprintBooleanInputUncontrolled/useFingerprintBooleanInputUncontrolled.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import { useFormContext } from "react-hook-form";
33
import useFormTheme from "~/hooks/useFormTheme";
44
import clsx from "clsx";
55
import { DEFAULT_IP, CLASS_NAMES } from "./constants";
6-
import {
7-
getCurrentTimeStamp,
8-
getIp,
9-
} from "~/field/components/FingerprintBooleanInput/FingerprintBooleanInputUncontrolled/helpers";
6+
import { getCurrentTimeStamp } from "~/field/components/FingerprintBooleanInput/FingerprintBooleanInputUncontrolled/helpers";
107
import { HandleComponent, HandleType } from "~/components/Handle/types";
118
import { getHandle } from "~/field/components/BooleanInput/BooleanInputUncontrolled/helpers";
9+
import {
10+
InfoIP,
11+
Service,
12+
services,
13+
useSubmit,
14+
} from "@kanda-libs/ks-frontend-services";
15+
import { StringIndexedObject } from "~/types";
1216

1317
export interface Hook {
1418
Handle: HandleComponent;
@@ -24,6 +28,14 @@ export default function useFingerprintBooleanInputUncontrolled(
2428

2529
const { setValue } = useFormContext();
2630

31+
const { submit: getIp } = useSubmit(
32+
services.infoIP.infoIP as unknown as Service<
33+
InfoIP,
34+
StringIndexedObject,
35+
StringIndexedObject
36+
>
37+
);
38+
2739
const skeletonClassName = clsx(skeletonClasses, CLASS_NAMES.skeleton);
2840

2941
/**
@@ -44,8 +56,10 @@ export default function useFingerprintBooleanInputUncontrolled(
4456
* A useEffect hook for calling the API to get the IP address
4557
*/
4658
useEffect(() => {
47-
getIp()
48-
.then((data) => setIp(data?.ip || DEFAULT_IP))
59+
getIp({})
60+
.then(({ data }: StringIndexedObject) => {
61+
setIp(data?.ipv4 || DEFAULT_IP);
62+
})
4963
.catch((err) => console.log(err));
5064
7;
5165
}, []);

0 commit comments

Comments
 (0)