Merge pull request #5099 from finned-palmer/show-wallet-scan-progress

btc-wallet: Show wallet scan progress
This commit is contained in:
~timluc-miptev 2021-07-23 13:18:03 +03:00 committed by GitHub
commit 3992fc1ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 19 deletions

View File

@ -16,10 +16,12 @@ const Balance = () => {
setPsbt, setPsbt,
setFee, setFee,
setError, setError,
scanProgress,
} = useSettings(); } = useSettings();
const [sending, setSending] = useState(false); const [sending, setSending] = useState(false);
const [copiedButton, setCopiedButton] = useState(false); const [copiedButton, setCopiedButton] = useState(false);
const [copiedString, setCopiedString] = useState(false); const [copiedString, setCopiedString] = useState(false);
const scanning = scanProgress?.main !== null || scanProgress?.change !== null;
const copyAddress = (arg) => { const copyAddress = (arg) => {
navigator.clipboard.writeText(address); navigator.clipboard.writeText(address);
@ -93,10 +95,26 @@ const Balance = () => {
> >
{value} {value}
</Text> </Text>
<Text {scanning ? (
fontSize={1} <Col alignItems="center">
color="orange" <Row>
>{`${sats}${unconfirmedString} sats`}</Text> <Text fontSize={1} color="orange">
Balance will be updated shortly:
</Text>
</Row>
<Row>
<Text fontSize={1} color="orange">
{scanProgress.main} main wallet addresses scanned
{scanProgress.change} change wallet addresses scanned
</Text>
</Row>
</Col>
) : (
<Text
fontSize={1}
color="orange"
>{`${sats}${unconfirmedString} sats`}</Text>
)}
</Col> </Col>
<Row flexDirection="row-reverse"> <Row flexDirection="row-reverse">
<Button <Button

View File

@ -201,16 +201,20 @@ const WalletModal = () => {
Extended Public Key (XPub) Extended Public Key (XPub)
</Text> </Text>
</Box> </Box>
<StatelessTextInput <Row alignItems="center">
value={xpub} <StatelessTextInput
disabled={inputDisabled} value={xpub}
fontSize="14px" disabled={inputDisabled}
type="password" fontSize="14px"
name="xpub" type="password"
autoCapitalize="none" name="xpub"
autoCorrect="off" autoCapitalize="none"
onChange={(e) => checkXPub(e)} autoCorrect="off"
/> onChange={(e) => checkXPub(e)}
mr={1}
/>
{!inputDisabled ? null : <LoadingSpinner />}
</Row>
<Box mt={3} mb={3}> <Box mt={3} mb={3}>
<Text <Text
fontSize="14px" fontSize="14px"

View File

@ -8,14 +8,15 @@ import Body from './lib/body.js';
import { useSettings } from '../hooks/useSettings.js'; import { useSettings } from '../hooks/useSettings.js';
const Root = () => { const Root = () => {
const { loaded, wallet, provider } = useSettings(); const { loaded, wallet, provider, scanProgress } = useSettings();
const blur = !loaded ? false : !(wallet && provider); const scanning = scanProgress?.main !== null || scanProgress?.change !== null;
const blur = !loaded || scanning ? false : !(wallet && provider);
return ( return (
<BrowserRouter> <BrowserRouter>
<ThemeProvider theme={light}> <ThemeProvider theme={light}>
<Reset /> <Reset />
{loaded ? <StartupModal /> : null} {loaded && !scanning ? <StartupModal /> : null}
<Box <Box
display="flex" display="flex"
flexDirection="column" flexDirection="column"
@ -23,8 +24,8 @@ const Root = () => {
alignItems="center" alignItems="center"
backgroundColor="lightOrange" backgroundColor="lightOrange"
width="100%" width="100%"
minHeight={loaded ? '100%' : 'none'} minHeight={loaded && !scanning ? '100%' : 'none'}
height={loaded ? 'none' : '100%'} height={loaded && !scanning ? 'none' : '100%'}
style={{ filter: blur ? 'blur(8px)' : 'none' }} style={{ filter: blur ? 'blur(8px)' : 'none' }}
px={[0, 4]} px={[0, 4]}
pb={[0, 4]} pb={[0, 4]}

View File

@ -43,6 +43,8 @@ export const SettingsContext = createContext({
setError: () => {}, setError: () => {},
broadcastSuccess: false, broadcastSuccess: false,
setBroadcastSuccess: () => {}, setBroadcastSuccess: () => {},
scanProgress: { main: null, change: null },
setScanProgress: () => {},
}); });
export const SettingsProvider = ({ channel, children }) => { export const SettingsProvider = ({ channel, children }) => {
@ -69,6 +71,10 @@ export const SettingsProvider = ({ channel, children }) => {
const [showWarning, setShowWarning] = useState(false); const [showWarning, setShowWarning] = useState(false);
const [error, setError] = useState(''); const [error, setError] = useState('');
const [broadcastSuccess, setBroadcastSuccess] = useState(false); const [broadcastSuccess, setBroadcastSuccess] = useState(false);
const [scanProgress, setScanProgress] = useState({
main: null,
change: null,
});
const { Provider } = SettingsContext; const { Provider } = SettingsContext;
@ -185,6 +191,7 @@ export const SettingsProvider = ({ channel, children }) => {
const errorData = channelData?.data?.error; const errorData = channelData?.data?.error;
const broadcastSuccessData = channelData?.data?.['broadcast-success']; const broadcastSuccessData = channelData?.data?.['broadcast-success'];
const broadcastFailData = channelData?.data?.['broadcast-fail']; const broadcastFailData = channelData?.data?.['broadcast-fail'];
const scanProgressData = channelData?.data?.['scan-progress'];
if (initialData) { if (initialData) {
setProvider(initialData.provider); setProvider(initialData.provider);
setWallet(initialData.wallet); setWallet(initialData.wallet);
@ -254,6 +261,9 @@ export const SettingsProvider = ({ channel, children }) => {
if (broadcastFailData) { if (broadcastFailData) {
setBroadcastSuccess(false); setBroadcastSuccess(false);
} }
if (scanProgressData) {
setScanProgress(scanProgressData);
}
}, [channelData]); }, [channelData]);
useEffect(() => { useEffect(() => {
@ -306,6 +316,8 @@ export const SettingsProvider = ({ channel, children }) => {
setError, setError,
broadcastSuccess, broadcastSuccess,
setBroadcastSuccess, setBroadcastSuccess,
scanProgress,
setScanProgress,
}} }}
> >
{children} {children}