This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f457e2
commit 786e8f8
Showing
5 changed files
with
114 additions
and
110 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
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,54 @@ | ||
import React, { useEffect } from 'react' | ||
import { Router, Route, useParams } from 'react-router-dom' | ||
import { bindActionCreators } from 'redux' | ||
import { connect, useSelector } from 'react-redux' | ||
import { restoreDepositState, restoreRedemptionState } from '../actions'; | ||
import { useWeb3React } from '@web3-react/core' | ||
|
||
export const RESTORER = { | ||
DEPOSIT: 'deposit', | ||
REDEMPTION: 'redemption' | ||
} | ||
|
||
function LoadableBase({ children, account, restoreDepositState, restoreRedemptionState, restorer }) { | ||
// Wait for web3 connected | ||
const { active: networkActive, error: networkError } = useWeb3React() | ||
const { address } = useParams() | ||
const depositStateRestored = useSelector((state) => state[restorer].stateRestored) | ||
|
||
useEffect(async () => { | ||
if(networkActive) { | ||
if (address && ! depositStateRestored) { | ||
if (restorer == RESTORER.DEPOSIT) { | ||
restoreDepositState(address) | ||
} else if (restorer == RESTORER.REDEMPTION) { | ||
restoreRedemptionState(address) | ||
} else { | ||
throw "Unknown restorer." | ||
} | ||
|
||
// return <div>Loading...</div> | ||
} else { | ||
// FIXME How do we not render these if we're getting ready to transition to | ||
// FIXME a new page? | ||
// return children | ||
} | ||
} | ||
}, [networkActive]) | ||
|
||
return children | ||
} | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return bindActionCreators( | ||
{ | ||
restoreDepositState, | ||
restoreRedemptionState | ||
}, | ||
dispatch | ||
); | ||
} | ||
|
||
const Loadable = connect(null, mapDispatchToProps)(LoadableBase) | ||
|
||
export default Loadable |
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