mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-19 05:38:41 +01:00
* chore(suite-native): upgrade react-native-graph to v. 1.0.2 * feat(react-native-graph): graph events added `react-native-graph` can display graph events/interactions now. The AnimatedLineGraph component accepts two new props `events` and `EventComponent`. - `events` is an array of objects representing every individual interaction and it's metadata. Each of these objects contains a `date` property that is used to compute the event coordinates in the graph. - `EventComponent` accepts the coordinates and metadata of each event and represent it in the graph * refactor(suite-native): graph works with real date We used to covert graph points `Date` objects to unix epoch time. This commit makes the graph work with original dates as library intends. * feat(suite-native): graph implements transaction events Graph of Account detail displays transaction events.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { useState } from 'react';
|
|
|
|
import { EventTooltipComponentProps, GraphEventWithCords } from '../LineGraphProps';
|
|
|
|
/**
|
|
* Returns props for tooltip of active graph event.
|
|
*/
|
|
export const useEventTooltipProps = <TEventPayload extends object>(
|
|
eventsWithCords: GraphEventWithCords<TEventPayload>[] | null,
|
|
onEventHover?: () => void,
|
|
) => {
|
|
const [activeEventIndex, setActiveEventIndex] = useState<number | null>(null);
|
|
const handleDisplayEventTooltip = (eventIndex: number, isDisplayed: boolean) => {
|
|
if (activeEventIndex === eventIndex && !isDisplayed) setActiveEventIndex(null);
|
|
|
|
if (activeEventIndex === null && isDisplayed) {
|
|
onEventHover?.();
|
|
setActiveEventIndex(eventIndex);
|
|
}
|
|
};
|
|
const activeEvent =
|
|
eventsWithCords && typeof activeEventIndex === 'number'
|
|
? eventsWithCords[activeEventIndex]
|
|
: null;
|
|
const eventTooltipProps: EventTooltipComponentProps<TEventPayload> | null = activeEvent
|
|
? {
|
|
eventX: activeEvent.x,
|
|
eventY: activeEvent.y,
|
|
eventPayload: activeEvent.payload,
|
|
}
|
|
: null;
|
|
|
|
return { handleDisplayEventTooltip, eventTooltipProps };
|
|
};
|