-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'app/feature/69-transfer-progress-bar' into design
- Loading branch information
Showing
7 changed files
with
145 additions
and
8 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
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,65 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import LinearProgress from '@material-ui/core/LinearProgress'; | ||
import { setSyncTimeout } from '../../lib/utils'; | ||
|
||
import BodyLarge from '../text/body-large'; | ||
import BodyStandard from '../text/body-standard'; | ||
|
||
const useStyles = makeStyles({ | ||
wrapper: styles => ({ | ||
width: '100%', | ||
maxHeight: '2vh', | ||
flexGrow: 1, | ||
...styles, | ||
}), | ||
|
||
bar: { | ||
height: '0.5vh', | ||
width: '100%', | ||
}, | ||
}); | ||
|
||
function randSign() { | ||
return Math.random() > 0.5 ? 1 : -1; | ||
} | ||
|
||
// TODO add weights to stageList | ||
export default function ContinuousProgress({value, endValue, ...props}) { | ||
const defaults = { step: 1 }; | ||
const { step, styles, organic } = { ...defaults, ...props}; | ||
const [completed, setCompleted] = useState(0); | ||
const classes = useStyles(styles); | ||
|
||
//const increment = Math.ceil(endValue * (step / 100)); | ||
|
||
useEffect(() => { | ||
async function progress() { | ||
let diff = (value == endValue) ? 100 : (value / endValue) * 100; | ||
// @brokenwindow this does not take into acount the timing of the input | ||
// value | ||
if(organic) { | ||
const rand = 5 * Math.random(); | ||
diff += randSign() * rand; | ||
await setSyncTimeout(rand * 500); | ||
} | ||
setCompleted(prev => { | ||
if (prev === 100) { | ||
return 0; | ||
} | ||
return Math.min(diff, 100); | ||
}); | ||
} | ||
|
||
progress() | ||
|
||
}, [value]); | ||
|
||
return ( | ||
<> | ||
<div className={classes.wrapper}> | ||
<LinearProgress className={classes.bar} variant="determinate" value={completed} /> | ||
</div> | ||
</> | ||
); | ||
} |
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,35 @@ | ||
import React, { useState, useEffect } from 'react' | ||
|
||
const averageBlockTime = 15000; | ||
export default function useTxTimer(time = averageBlockTime, opts) { | ||
const defaults = { steps: 8 }; | ||
const { steps } = {...defaults, ...opts}; | ||
const [timer, setTimer] = React.useState(null); | ||
const [timerVal, setTimerVal] = React.useState(0); | ||
|
||
// TODO allow providing a callback on timer completion. e.g. indicating a tx | ||
// is taking too long. | ||
|
||
const start = () => { | ||
console.log('Start tx timer'); | ||
setTimerVal(0); | ||
const inc = time / steps; | ||
setTimer(() => setInterval( | ||
() => setTimerVal(t => { | ||
if(t >= time) { | ||
setTimer(timer => clearInterval(timer)); | ||
return time; | ||
} | ||
return t + inc; | ||
}), inc)); | ||
} | ||
|
||
const stop = () => setTimer(timer => clearInterval(timer)); | ||
|
||
return { | ||
start, | ||
stop, | ||
value: timerVal, | ||
transferTime: time, | ||
} | ||
} |
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