Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: last transaction #481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ export const AgentRunningButton = () => {

const { selectedService, isFetched: isLoaded, setPaused } = useServices();

const { service, setDeploymentStatus } = useService({
serviceConfigId:
isLoaded && selectedService?.service_config_id
? selectedService.service_config_id
: '',
});
const serviceConfigId =
isLoaded && selectedService?.service_config_id
? selectedService.service_config_id
: '';
const { service, setDeploymentStatus } = useService({ serviceConfigId });

const handlePause = useCallback(async () => {
if (!service) return;
Expand Down Expand Up @@ -76,7 +75,8 @@ export const AgentRunningButton = () => {
Agent is working
</Paragraph>
)}
<LastTransaction />

<LastTransaction serviceConfigId={serviceConfigId} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this overkill and better to extract from hook? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with either approach for now, we can optimize at later point!

My preference atm is to use hooks to isolate children from parent changes where we can, though this may eventually lead to some performance issues. Yet to hit any so far however, but will memoize components/props once the time comes!

</Flex>
</Flex>
);
Expand Down
15 changes: 9 additions & 6 deletions frontend/components/MainPage/header/LastTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { useInterval } from 'usehooks-ts';
import { MiddlewareChain } from '@/client';
import { ONE_MINUTE_INTERVAL } from '@/constants/intervals';
import { EXPLORER_URL } from '@/constants/urls';
import { useAddress } from '@/hooks/useAddress';
import { usePageState } from '@/hooks/usePageState';
import { useService } from '@/hooks/useService';
import { useStakingProgram } from '@/hooks/useStakingProgram';
import { getLatestTransaction } from '@/service/Ethers';
import { TransactionInfo } from '@/types/TransactionInfo';
import { Optional } from '@/types/Util';
import { getTimeAgo } from '@/utils/time';

const { Text } = Typography;
Expand All @@ -24,21 +25,23 @@ const Loader = styled(Skeleton.Input)`
}
`;

type LastTransactionProps = { serviceConfigId: Optional<string> };

/**
* Displays the last transaction time and link to the transaction on explorer
* by agent safe.
*/
// TODO: loop over all supported chains
export const LastTransaction = () => {
export const LastTransaction = ({ serviceConfigId }: LastTransactionProps) => {
const { isPageLoadedAndOneMinutePassed } = usePageState();
const { multisigAddress } = useAddress();
const { activeStakingProgramMeta } = useStakingProgram();
const { service } = useService({ serviceConfigId });
const multisigAddress =
service?.chain_configs[service?.home_chain_id].chain_data.multisig;
const chainId = activeStakingProgramMeta?.chainId;

const [isFetching, setIsFetching] = useState(true);
const [transaction, setTransaction] = useState<TransactionInfo | null>(null);

const chainId = activeStakingProgramMeta?.chainId;

const fetchTransaction = useCallback(async () => {
if (!multisigAddress) return;
if (!chainId) return;
Expand Down
17 changes: 0 additions & 17 deletions frontend/hooks/backup/useAddress.ts

This file was deleted.

Loading