Skip to content

Commit

Permalink
feat: enhance GasBalanceSection with dynamic activity link based on s…
Browse files Browse the repository at this point in the history
…elected service
  • Loading branch information
mohandast52 committed Dec 9, 2024
1 parent 7ea4866 commit 616a8ab
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions frontend/components/MainPage/sections/GasBalanceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const TooltipContent = styled.div`
`;

export const GasBalanceSection = () => {
const { selectedAgentConfig } = useServices();
const { selectedAgentConfig, selectedService } = useServices();
const { evmHomeChainId: homeChainId } = selectedAgentConfig;
const { masterSafes } = useMasterWalletContext();
const { isLoaded: isBalancesLoaded } = useBalanceContext();
Expand All @@ -116,6 +116,23 @@ export const GasBalanceSection = () => {
return masterSafes.find((wallet) => wallet.evmChainId === homeChainId);
}, [homeChainId, masterSafes]);

const activityLink = useMemo(() => {
if (!masterSafe) return;
if (!selectedService?.home_chain) return;

const link =
EXPLORER_URL_BY_MIDDLEWARE_CHAIN[selectedService.home_chain] +
'/address/' +
masterSafe.address;

return (
<a href={link} target="_blank">
Track activity on blockchain explorer{' '}
<ArrowUpOutlined style={{ rotate: '45deg' }} />
</a>
);
}, [masterSafe, selectedService?.home_chain]);

return (
<CardSection
justify="space-between"
Expand All @@ -131,20 +148,7 @@ export const GasBalanceSection = () => {
<TooltipContent>
Your agent uses this balance to fund trading activity on-chain.
<br />
<a
href={
`${
EXPLORER_URL_BY_MIDDLEWARE_CHAIN[
// TODO: fix unknown
homeChainId as unknown as keyof typeof EXPLORER_URL_BY_MIDDLEWARE_CHAIN
]
}/address/` + masterSafe.address
}
target="_blank"
>
Track activity on blockchain explorer{' '}
<ArrowUpOutlined style={{ rotate: '45deg' }} />
</a>
{activityLink}
</TooltipContent>
}
>
Expand Down

0 comments on commit 616a8ab

Please sign in to comment.