Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug PM-706: OLYs are not refreshed #438

Merged
merged 1 commit into from
Jul 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,61 @@ const useUport = defaultProvider === WALLET_PROVIDER.UPORT

class Header extends Component {
componentDidMount() {
const { currentAccount } = this.props
const {
currentAccount, requestMainnetAddress, requestTokenBalance, fetchTournamentUserData,
} = this.props

if (requireRegistration && currentAccount) {
this.props.requestMainnetAddress()
requestMainnetAddress()
}

if (currentAccount) {
this.props.requestTokenBalance(currentAccount)
requestTokenBalance(currentAccount)

if (tournamentEnabled) {
this.props.fetchTournamentUserData(currentAccount)
fetchTournamentUserData(currentAccount)
}
}
}

componentDidUpdate(prevProps) {
const {
currentAccount, requestTokenBalance, requestMainnetAddress, fetchTournamentUserData,
} = this.props
// If user unlocks metamask, changes his account, we need to check if the account was registered
const shouldRequestMainnetAddress = requireRegistration && this.props.currentAccount !== prevProps.currentAccount
if (shouldRequestMainnetAddress) {
this.props.requestMainnetAddress()
const shouldRequestMainnetAddress = requireRegistration && currentAccount !== prevProps.currentAccount
if (shouldRequestMainnetAddress && currentAccount) {
requestTokenBalance(currentAccount)
requestMainnetAddress()
fetchTournamentUserData(currentAccount)
}
}

@autobind
async handleConnectWalletClick() {
const { isConnectedToCorrectNetwork, lockedMetamask, acceptedTOS } = this.props
const {
isConnectedToCorrectNetwork, lockedMetamask, acceptedTOS, openModal, initUport,
} = this.props

const shouldInstallProviders = !hasMetamask() && !useUport
const shouldAcceptTOS = !acceptedTOS || !legalComplianceEnabled

if (shouldInstallProviders) {
this.props.openModal('ModalInstallMetamask')
openModal('ModalInstallMetamask')
} else if (useMetamask) {
if (lockedMetamask) {
this.props.openModal('ModalUnlockMetamask')
openModal('ModalUnlockMetamask')
} else if (!isConnectedToCorrectNetwork) {
this.props.openModal('ModalSwitchNetwork')
openModal('ModalSwitchNetwork')
} else if (requireRegistration) {
this.props.openModal('ModalRegisterWallet')
openModal('ModalRegisterWallet')
} else if (shouldAcceptTOS) {
this.props.openModal('ModalAcceptTOS')
openModal('ModalAcceptTOS')
} else {
console.warn('should be connected')
}
} else if (useUport) {
this.props.initUport()
initUport()
}
}

Expand Down Expand Up @@ -141,7 +150,9 @@ class Header extends Component {
<div className={cx('headerLogo', 'beta')} style={logoVars} />
</NavLink>
</div>
<div className={cx('group', 'left', 'version')}>{version}</div>
<div className={cx('group', 'left', 'version')}>
{version}
</div>
<div className={cx('group', 'left', 'navLinks')}>
<NavLink to="/markets/list" activeClassName={cx('active')} className={cx('navLink')}>
Markets
Expand All @@ -162,12 +173,20 @@ class Header extends Component {
<div className={cx('group', 'right')}>
{canInteract ? (
<div className={cx('account')}>
{currentNetwork &&
currentNetwork !== 'MAIN' && (
<span className={cx('network', 'text')}>Network: {upperFirst(currentNetwork.toLowerCase())}</span>
{currentNetwork
&& currentNetwork !== 'MAIN' && (
<span className={cx('network', 'text')}>
Network:
{upperFirst(currentNetwork.toLowerCase())}
</span>
)}
<DecimalValue value={tokenBalance} className={cx('text')} />
&nbsp;
{tokenAddress ? <CurrencyName className={cx('text')} tokenAddress={tokenAddress} /> : (
<span>
ETH
</span>
)}
<DecimalValue value={tokenBalance} className={cx('text')} />&nbsp;
{tokenAddress ? <CurrencyName className={cx('text')} tokenAddress={tokenAddress} /> : <span>ETH</span>}
{badgesEnabled && <BadgeIcon userTournamentInfo={userTournamentInfo} />}
<ProviderIcon provider={currentProvider} />
<Identicon account={currentAccount} />
Expand Down