Skip to content

Commit

Permalink
Select recommended pool and saturationErrorBanner
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Nov 23, 2020
1 parent 9464d2e commit d54d9bb
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,8 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
validateDelegationAndCalculateFee()
}

const selectAdaliteStakepool = () => {
updateStakePoolIdentifier(getState(), null, ADALITE_CONFIG.ADALITE_STAKE_POOL_ID)
const selectAdaliteStakepool = (state: State) => {
updateStakePoolIdentifier(getState(), null, state.poolRecommendation.recommendedPoolHash)
}

/* SUBMIT TX */
Expand Down Expand Up @@ -1060,7 +1060,7 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
resetAmountFields(state)
wallet.generateNewSeeds()
await reloadWalletInfo(state)
selectAdaliteStakepool()
selectAdaliteStakepool(state)
setState({
waitingForHwWallet: false,
txSuccessTab: sendResponse && sendResponse.success ? txTab : '',
Expand Down
4 changes: 4 additions & 0 deletions app/frontend/components/pages/dashboard/dashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import InfoModal from '../../common/infoModal'
import NotShelleyCompatibleDialog from '../login/nonShelleyCompatibleDialog'
import DashboardErrorBanner from './dashboardErrorBanner'
import PremiumBanner from './premiumBanner'
import SaturationErrorBanner from './saturationErrorBanner'

interface Props {
displayStakingPage: any
Expand Down Expand Up @@ -77,6 +78,7 @@ class DashboardPage extends Component<Props> {
shouldShowNonShelleyCompatibleDialog,
displayInfoModal,
shouldShowPremiumBanner,
shouldShowSaturatedBanner,
},
{selectedMainTab}
) {
Expand All @@ -87,6 +89,7 @@ class DashboardPage extends Component<Props> {
{shouldShowNonShelleyCompatibleDialog && <NotShelleyCompatibleDialog />}
{!isShelleyCompatible && <DashboardErrorBanner />}
{shouldShowPremiumBanner && <PremiumBanner />}
{shouldShowSaturatedBanner && <SaturationErrorBanner />}
{ADALITE_CONFIG.ADALITE_CARDANO_VERSION === 'shelley' && (
<ul className="tabinator">
{mainTabs.map((name, i) => (
Expand Down Expand Up @@ -172,6 +175,7 @@ export default connect(
isShelleyCompatible: state.isShelleyCompatible,
shouldShowNonShelleyCompatibleDialog: state.shouldShowNonShelleyCompatibleDialog,
shouldShowPremiumBanner: state.shouldShowPremiumBanner,
shouldShowSaturatedBanner: state.poolRecommendation.shouldShowSaturatedBanner,
}),
actions
)(DashboardPage)
13 changes: 13 additions & 0 deletions app/frontend/components/pages/dashboard/saturationErrorBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {h} from 'preact'
import ErrorBanner from '../login/errorBanner'

const SaturationErrorBanner = () => {
const message = 'One of the pool you are delegating to is saturated.'
return (
<a style={'width: 100%;margin-bottom: 20px;'}>
<ErrorBanner message={message} />
</a>
)
}

export default SaturationErrorBanner
11 changes: 8 additions & 3 deletions app/frontend/components/pages/delegations/delegatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TransactionErrorModal from '../../pages/sendAda/transactionErrorModal'
import {getTranslation} from '../../../translations'
import {errorHasHelp} from '../../../helpers/errorsWithHelp'
import ConfirmTransactionDialog from '../../pages/sendAda/confirmTransactionDialog'
import {Lovelace} from '../../../state'
import {Lovelace, State} from '../../../state'
import {ADALITE_CONFIG} from '../../../config'
import Accordion from '../../common/accordion'

Expand Down Expand Up @@ -85,6 +85,7 @@ interface Props {
shouldShowConfirmTransactionDialog: any
txSuccessTab: any
gettingPoolInfo: boolean
poolRecommendation: any
pool: any
}

Expand Down Expand Up @@ -112,6 +113,7 @@ class Delegate extends Component<Props> {
shouldShowConfirmTransactionDialog,
txSuccessTab,
gettingPoolInfo,
poolRecommendation,
pool,
}) {
const delegationHandler = async () => {
Expand All @@ -123,7 +125,9 @@ class Delegate extends Component<Props> {
return (
<div className="delegate card">
<Accordion
initialVisibility={!Object.keys(pool).length}
initialVisibility={
poolRecommendation.shouldShowSaturatedBanner || !Object.keys(pool).length
}
header={<h2 className="card-title no-margin">Delegate Stake</h2>}
body={
<Fragment>
Expand Down Expand Up @@ -200,7 +204,7 @@ class Delegate extends Component<Props> {
}

export default connect(
(state) => ({
(state: State) => ({
stakePool: state.shelleyDelegation.selectedPool,
calculatingDelegationFee: state.calculatingDelegationFee,
delegationFee: state.shelleyDelegation.delegationFee,
Expand All @@ -211,6 +215,7 @@ export default connect(
txSuccessTab: state.txSuccessTab,
gettingPoolInfo: state.gettingPoolInfo,
isShelleyCompatible: state.isShelleyCompatible,
poolRecommendation: state.poolRecommendation,
pool: state.shelleyAccountInfo.delegation,
}),
actions
Expand Down
12 changes: 12 additions & 0 deletions app/frontend/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export interface State {
}
txConfirmType: string
txSuccessTab: string
poolRecommendation: {
isInRecommendedPoolSet: boolean
recommendedPoolHash: string
status: string
shouldShowSaturatedBanner: boolean
}
}

const initialState: State = {
Expand Down Expand Up @@ -234,6 +240,12 @@ const initialState: State = {
txConfirmType: '',
txSuccessTab: '',
keepConfirmationDialogOpen: false,
poolRecommendation: {
isInRecommendedPoolSet: true,
recommendedPoolHash: '',
status: '',
shouldShowSaturatedBanner: false,
},
}

export {initialState}
12 changes: 12 additions & 0 deletions app/frontend/wallet/blockchain-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
}
}

function getPoolRecommendation(poolHash: string, stake: number): Promise<any> {
const url = `${
ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
}/api/account/poolRecommendation/poolHash/${poolHash}/stake/${stake}`
return request(url).catch(() => ({
recommendedPoolHash: ADALITE_CONFIG.ADALITE_STAKE_POOL_ID,
isInRecommendedPoolSet: true,
status: 'GivedPoolOk',
}))
}

return {
getTxHistory,
fetchTxRaw,
Expand All @@ -369,6 +380,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
getPoolInfo,
getStakingHistory,
getRewardDetails,
getPoolRecommendation,
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/frontend/wallet/cardano-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {computeRequiredTxFee, selectMinimalTxPlan, isUtxoProfitable} from './byr
import {MaxAmountCalculator} from './max-amount-calculator'
// eslint-disable-next-line no-unused-vars
import {TxPlan} from './shelley/build-transaction'
import {ADALITE_CONFIG} from '../config'

const {
getMaxDonationAmount: _getMaxDonationAmount,
Expand Down Expand Up @@ -259,6 +260,10 @@ const CardanoWallet = (options) => {
return {code: 'UnsupportedOperation', message: ''}
}

function getPoolRecommendation() {
return ADALITE_CONFIG.ADALITE_STAKE_POOL_ID
}

return {
isHwWallet,
getWalletName,
Expand All @@ -281,6 +286,7 @@ const CardanoWallet = (options) => {
getMaxNonStakingAmount,
getPoolInfo,
checkCryptoProviderVersion,
getPoolRecommendation,
}
}

Expand Down
18 changes: 18 additions & 0 deletions app/frontend/wallet/shelley-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const ShelleyBlockchainExplorer = (config) => {
getStakingHistory: be.getStakingHistory,
getBestSlot,
getRewardDetails: be.getRewardDetails,
getPoolRecommendation: be.getPoolRecommendation,
}
}
const ShelleyWallet = ({
Expand Down Expand Up @@ -343,6 +344,10 @@ const ShelleyWallet = ({
const visibleAddresses = await getVisibleAddresses()
const transactionHistory = await getHistory()
const stakingHistory = await getStakingHistory(shelleyAccountInfo, validStakepools)
const poolRecommendation = await getPoolRecommendation(
shelleyAccountInfo.delegation,
stakingBalance
)
return {
validStakepools,
balance,
Expand All @@ -355,6 +360,7 @@ const ShelleyWallet = ({
transactionHistory,
stakingHistory,
visibleAddresses,
poolRecommendation,
}
}

Expand Down Expand Up @@ -474,6 +480,17 @@ const ShelleyWallet = ({
return null
}

async function getPoolRecommendation(pool: any, stake: number): Promise<any> {
const poolHash = pool ? pool.poolHash : null
const poolRecommendation = await blockchainExplorer.getPoolRecommendation(poolHash, stake)
const delegatesToRecommended = poolRecommendation.recommendedPoolHash === pool.poolHash
return {
...poolRecommendation,
shouldShowSaturatedBanner:
!delegatesToRecommended && poolRecommendation.status === 'GivenPoolSaturated',
}
}

return {
isHwWallet,
getWalletName,
Expand All @@ -497,6 +514,7 @@ const ShelleyWallet = ({
getWalletInfo,
getPoolInfo,
checkCryptoProviderVersion,
getPoolRecommendation,
}
}

Expand Down

0 comments on commit d54d9bb

Please sign in to comment.