-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKMERGE] /bug/fix profits and balance dashboard (#359)
* PM-618: Display WETH for Dashboard/Header (#334) * Bug: Fix problems with collateralToken, allowing to enter contractName to use as collateralToken (#340) * PM-618: Display WETH for Dashboard/Header * Refactor collateralToken * Implement ToS Acceptance localstorage load/save * Update config for staging * reset local config, update tests, fix collateralToken for all sources * update all configs * Fix failing imports & pass tests
- Loading branch information
Showing
21 changed files
with
418 additions
and
140 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
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 |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { requestTokenBalance } from 'store/actions/blockchain' | ||
import { requestTokenBalance, TOKEN_SOURCE_ETH } from 'store/actions/blockchain' | ||
import { openModal } from 'store/actions/modal' | ||
import { requestMainnetAddress } from 'store/actions/account' | ||
|
||
import { initProviders } from 'integrations/store/actions' | ||
import { WALLET_PROVIDER } from 'integrations/constants' | ||
|
||
import { getCollateralToken } from 'utils/features' | ||
import { getCollateralToken } from 'store/selectors/blockchain' | ||
|
||
/** | ||
* Requests the configured tournaments collateralToken balance. If none is set, does nothing | ||
* @param {function} dispatch | ||
* @param {function} getState | ||
*/ | ||
const requestTournamentTokenBalance = account => (dispatch) => { | ||
const tournamentToken = getCollateralToken() | ||
const requestCollateralTokenBalance = account => (dispatch, getState) => { | ||
const state = getState() | ||
const collateralToken = getCollateralToken(state) | ||
|
||
if (!tournamentToken) { | ||
return null | ||
// no collateral token defined yet - this information might be asynchronous, if the | ||
// defined collateral token is inside a contract. | ||
if (!collateralToken || !collateralToken.source) { | ||
return undefined | ||
} | ||
|
||
return dispatch(requestTokenBalance(tournamentToken.address, account)) | ||
// if the collateralToken source is the ETH balance from the users wallet, we don't need | ||
// to start a request to fetch the balance, as it is auto updating in the current provider | ||
if (collateralToken.source === TOKEN_SOURCE_ETH) { | ||
return undefined | ||
} | ||
|
||
return dispatch(requestTokenBalance(collateralToken.address, account)) | ||
} | ||
|
||
export default { | ||
requestMainnetAddress, | ||
requestTokenBalance: requestTournamentTokenBalance, | ||
requestTokenBalance: requestCollateralTokenBalance, | ||
openModal: modalName => dispatch => dispatch(openModal({ modalName })), | ||
initUport: () => dispatch => dispatch(initProviders({ providers: [WALLET_PROVIDER.UPORT] })), | ||
} |
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 |
---|---|---|
@@ -1,69 +1,55 @@ | ||
import Decimal from 'decimal.js' | ||
|
||
import { | ||
getCurrentAccount, | ||
getCurrentNetwork, | ||
getCurrentBalance, | ||
getActiveProvider, | ||
checkWalletConnection, | ||
hasAcceptedTermsAndConditions, | ||
isConnectedToCorrectNetwork, | ||
getTargetNetworkId, | ||
getRegisteredMainnetAddress, | ||
isMetamaskLocked, | ||
hasAcceptedTermsAndConditions, | ||
} from 'integrations/store/selectors' | ||
|
||
import { | ||
getLogoConfig, | ||
isFeatureEnabled, | ||
getFeatureConfig, | ||
getCollateralToken, | ||
} from 'utils/features' | ||
|
||
import { getTokenAmount } from 'store/selectors/blockchain' | ||
import { getCollateralToken } from 'store/selectors/blockchain' | ||
|
||
import { meSelector } from 'routes/Scoreboard/store/selectors' | ||
|
||
const collateralToken = getCollateralToken() | ||
const gameGuideConfig = getFeatureConfig('gameGuide') | ||
const logoConfig = getLogoConfig('logo') | ||
|
||
/** | ||
* Returns either the balance of the counfigured token of the current balance of ether | ||
* @param {*} state | ||
*/ | ||
const getCurrentTokenBalance = (state) => { | ||
if (!collateralToken) { | ||
return getCurrentBalance(state) | ||
} | ||
|
||
const amount = getTokenAmount(state, collateralToken.address) | ||
|
||
if (!amount) { | ||
return Decimal(0) | ||
export default (state) => { | ||
const collateralToken = getCollateralToken(state) | ||
|
||
return { | ||
hasWallet: checkWalletConnection(state), | ||
currentAccount: getCurrentAccount(state), | ||
currentNetwork: getCurrentNetwork(state), | ||
currentProvider: getActiveProvider(state), | ||
isConnectedToCorrectNetwork: isConnectedToCorrectNetwork(state), | ||
targetNetworkId: getTargetNetworkId(state), | ||
mainnetAddress: getRegisteredMainnetAddress(state), | ||
lockedMetamask: isMetamaskLocked(state), | ||
userTournamentInfo: meSelector(state), | ||
logoPath: logoConfig.regular, | ||
smallLogoPath: logoConfig.small, | ||
showScoreboard: isFeatureEnabled('scoreboard'), | ||
showGameGuide: isFeatureEnabled('gameGuide'), | ||
gameGuideType: gameGuideConfig.type, | ||
gameGuideURL: gameGuideConfig.url, | ||
tokenAddress: collateralToken.address, | ||
tokenBalance: collateralToken.balance, | ||
acceptedTOS: hasAcceptedTermsAndConditions(state), | ||
} | ||
|
||
return amount.toString() | ||
} | ||
|
||
export default state => ({ | ||
hasWallet: checkWalletConnection(state), | ||
currentAccount: getCurrentAccount(state), | ||
currentNetwork: getCurrentNetwork(state), | ||
currentProvider: getActiveProvider(state), | ||
isConnectedToCorrectNetwork: isConnectedToCorrectNetwork(state), | ||
targetNetworkId: getTargetNetworkId(state), | ||
mainnetAddress: getRegisteredMainnetAddress(state), | ||
lockedMetamask: isMetamaskLocked(state), | ||
userTournamentInfo: meSelector(state), | ||
logoPath: logoConfig.regular, | ||
smallLogoPath: logoConfig.small, | ||
showScoreboard: isFeatureEnabled('scoreboard'), | ||
showGameGuide: isFeatureEnabled('gameGuide'), | ||
gameGuideType: gameGuideConfig.type, | ||
gameGuideURL: gameGuideConfig.url, | ||
tokenAddress: collateralToken && collateralToken.address, | ||
tokenBalance: getCurrentTokenBalance(state), | ||
acceptedTOS: hasAcceptedTermsAndConditions(state), | ||
}) | ||
|
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
Oops, something went wrong.