Skip to content

Commit

Permalink
A-1207235404867093 (#171)
Browse files Browse the repository at this point in the history
* feat: add icons

* feat: add update button component

* feat: update network provider

* feat: add new button to header

* feat: remove loader fetching data

* fix: timeout
  • Loading branch information
owlsua authored Jun 24, 2024
1 parent cf9340d commit 1eb8dda
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/assets/images/icon-loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/assets/images/icon-success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/basic/Tooltip/Tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
color: rgb(var(--color-white));
font-size: 0.8rem;
transition: opacity 0.7s ease;
z-index: 100000;
}

.top {
Expand Down
2 changes: 2 additions & 0 deletions src/components/composed/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ReactComponent as ExpandImg } from '@Assets/images/icon-expand.svg'
import { ReactComponent as SettingsImg } from '@Assets/images/settings.svg'

import { Button, Logo, Tooltip } from '@BasicComponents'
import { UpdateButton } from '@ComposedComponents'
import { AccountContext } from '@Contexts'

import './Header.css'
Expand Down Expand Up @@ -154,6 +155,7 @@ const Header = ({ customBackAction }) => {
</>
)}
<Logo unlocked={unlocked} />
{unlocked && <UpdateButton />}
</header>
)
}
Expand Down
33 changes: 33 additions & 0 deletions src/components/composed/UpdateButton/UpdateButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.update-button {
position: absolute;
top: 17px;
right: 216px;
display: flex;
width: 30px;
height: 30px;
padding: 0;
}

.update-button svg {
width: 100%;
height: 100%;
fill: rgb(var(--color-green));
}

.update-button svg path {
fill: rgb(var(--color-green));
}


@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.loading-animated {
animation: spin 2s linear infinite;
}
53 changes: 53 additions & 0 deletions src/components/composed/UpdateButton/UpdateButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useState, useContext, useEffect } from 'react'

import { Button } from '@BasicComponents'
import { ReactComponent as SuccessImg } from '@Assets/images/icon-success.svg'
import { ReactComponent as LoadingImg } from '@Assets/images/icon-loading.svg'

import { NetworkContext } from '@Contexts'

import './UpdateButton.css'


const UpdateButton = () => {
const { fetchAllData, fetchDelegations } =
useContext(NetworkContext)
const [loading, setLoading] = useState(false)
const [showSuccess, setShowSuccess] = useState(false)

const handleClick = async () => {
try {
setLoading(true)
await fetchAllData()
await fetchDelegations()
setLoading(false)
setShowSuccess(true)
}
catch (error) {
console.error(error)
setLoading(false)
}
}

useEffect(() => {
const timeout = setTimeout(() => {
setShowSuccess(false)
}, 3000)
return () => clearTimeout(timeout)
}, [showSuccess])

return (
<Button
onClickHandle={handleClick}
className="update-button"
alternate
extraStyleClasses={['update-button']}
>
{loading && <LoadingImg className="loading-animated" />}
{!loading && showSuccess && <SuccessImg />}
{!loading && !showSuccess && <LoadingImg />}
</Button>
)
}

export default UpdateButton
2 changes: 2 additions & 0 deletions src/components/composed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import AddWallet from './AddWallet/AddWallet'
import CurrentStaking from './CurrentStaking/CurrentStaking'
import HelpTooltip from './HelpTooltip/HelpTooltip'
import RestoreSeedField from './RestoreSeedField/RestoreSeedField'
import UpdateButton from './UpdateButton/UpdateButton'

export {
Balance,
Expand All @@ -42,4 +43,5 @@ export {
CurrentStaking,
HelpTooltip,
RestoreSeedField,
UpdateButton,
}

0 comments on commit 1eb8dda

Please sign in to comment.