-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: UX improvements regarding agent activity (#349)
* feat: improvement on Agent head * Refactor rewards section labels for consistency (work period to epoch) * feat: add getTimeAgo util * feat: add useAddress hook * feat: update time util function * feat: add LastTransaction component * feat: Add pull request template * feat: add getLatestTransaction util * feat: update recursion * feat: update Idle agent head color * feat: Address Tanya & Josh comments
- Loading branch information
1 parent
6814d41
commit 412449a
Showing
13 changed files
with
272 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Proposed changes | ||
|
||
## Types of changes | ||
|
||
What types of changes does your code introduce? | ||
_Put an `x` in the boxes that apply_ | ||
|
||
- [ ] Bugfix (non-breaking change which fixes an issue) | ||
- [ ] New feature (non-breaking change which adds functionality) | ||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Skeleton, Typography } from 'antd'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { useInterval } from 'usehooks-ts'; | ||
|
||
import { useAddress } from '@/hooks/useAddress'; | ||
import { getLatestTransaction } from '@/service/Ethers'; | ||
import { TransactionInfo } from '@/types/TransactionInfo'; | ||
import { getTimeAgo } from '@/utils/time'; | ||
|
||
const { Text } = Typography; | ||
|
||
const Loader = styled(Skeleton.Input)` | ||
line-height: 1; | ||
span { | ||
width: 120px !important; | ||
height: 12px !important; | ||
margin-top: 6px !important; | ||
} | ||
`; | ||
|
||
const POLLING_INTERVAL = 60 * 1000; // 1 minute | ||
|
||
/** | ||
* Component to display the last transaction time and link to the transaction on GnosisScan | ||
* by agent safe. | ||
*/ | ||
export const LastTransaction = () => { | ||
const { multisigAddress } = useAddress(); | ||
|
||
const [isFetching, setIsFetching] = useState(true); | ||
const [transaction, setTransaction] = useState<TransactionInfo | null>(null); | ||
|
||
const fetchTransaction = useCallback(async () => { | ||
if (!multisigAddress) return; | ||
|
||
getLatestTransaction(multisigAddress) | ||
.then((tx) => setTransaction(tx)) | ||
.catch((error) => | ||
console.error('Failed to get latest transaction', error), | ||
) | ||
.finally(() => setIsFetching(false)); | ||
}, [multisigAddress]); | ||
|
||
// Fetch the latest transaction on mount | ||
useEffect(() => { | ||
fetchTransaction(); | ||
}, [fetchTransaction]); | ||
|
||
// Poll for the latest transaction | ||
useInterval(() => fetchTransaction(), POLLING_INTERVAL); | ||
|
||
if (isFetching) { | ||
return <Loader active size="small" />; | ||
} | ||
|
||
if (!transaction) { | ||
return ( | ||
<Text type="secondary" className="text-xs"> | ||
No transactions recently! | ||
</Text> | ||
); | ||
} | ||
|
||
return ( | ||
<Text type="secondary" className="text-xs"> | ||
Last txn: | ||
<Text | ||
type="secondary" | ||
className="text-xs pointer hover-underline" | ||
onClick={() => | ||
window.open(`https://gnosisscan.io/tx/${transaction.hash}`) | ||
} | ||
> | ||
{getTimeAgo(transaction.timestamp)} ↗ | ||
</Text> | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CHAINS } from '@/constants/chains'; | ||
|
||
import { useServices } from './useServices'; | ||
|
||
export const useAddress = () => { | ||
const { service } = useServices(); | ||
|
||
/** agent safe multisig address */ | ||
const multisigAddress = | ||
service?.chain_configs?.[CHAINS.GNOSIS.chainId]?.chain_data?.multisig; | ||
|
||
/** agent instance EOA address */ | ||
const instanceAddress = | ||
service?.chain_configs?.[CHAINS.GNOSIS.chainId]?.chain_data?.instances?.[0]; | ||
|
||
return { instanceAddress, multisigAddress }; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.