mango-ui-v3/components/ManualRefresh.tsx

33 lines
922 B
TypeScript
Raw Normal View History

import { useState } from 'react'
import { RefreshClockwiseIcon } from './icons'
import useMangoStore from '../stores/useMangoStore'
import Tooltip from './Tooltip'
2021-07-29 06:19:32 -07:00
import { IconButton } from './Button'
const ManualRefresh = ({ className = '' }) => {
const [spin, setSpin] = useState(false)
const actions = useMangoStore((s) => s.actions)
const handleRefreshData = async () => {
setSpin(true)
2021-06-23 08:32:33 -07:00
await actions.fetchMangoAccounts()
2021-06-17 11:03:47 -07:00
await actions.fetchWalletTokens()
await actions.fetchTradeHistory()
setSpin(false)
}
return (
<div className={`inline-flex relative ${className}`}>
<Tooltip content="Refresh Data" className="text-xs py-1">
2021-07-29 06:19:32 -07:00
<IconButton onClick={handleRefreshData}>
<RefreshClockwiseIcon
className={`w-4 h-4 ${spin ? 'animate-spin' : null}`}
/>
2021-07-29 06:19:32 -07:00
</IconButton>
</Tooltip>
</div>
)
}
export default ManualRefresh