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

fixed not displaying rewards balance when a withdrawal has been just processed #3403

Merged
merged 16 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ then RELEASE_TYPE="nightly"
elif [ $1 = "nightly-mv2" ];
then RELEASE_TYPE="nightly-mv2"
else
echo "First parameter is expected 'stable', 'stable-mv2', or 'nightly'"
echo "First parameter is expected 'stable', 'stable-mv2', 'nightly', or 'nightly-mv2'"
return 1
fi

Expand Down
3 changes: 3 additions & 0 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,9 @@ export default class AdaApi {
for (const input of signRequest.inputs()) {
amount.joinSubtractMutable(input.value);
}
for (const withdrawal of signRequest.withdrawals()) {
amount.joinSubtractMutable(withdrawal.amount);
}
let isIntraWallet = true;
for (const output of signRequest.outputs()) {
if (ownAddresses.has(output.address)) {
Expand Down
18 changes: 2 additions & 16 deletions packages/yoroi-extension/app/components/topbar/NavWalletDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ type Props = {|
+shouldHideBalance: boolean,
+highlightTitle?: boolean,
+showEyeIcon?: boolean,
/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
+rewards: null | void | MultiToken,
+rewards: ?MultiToken,
+walletAmount: null | MultiToken,
+infoText?: string,
+showDetails?: boolean,
Expand Down Expand Up @@ -82,11 +77,7 @@ export default class NavWalletDetails extends Component<Props> {

const totalAmount = this.getTotalAmount();

const showsRewards = (
this.props.rewards !== undefined &&
showDetails !== null &&
showDetails === true
);
const showsRewards = showDetails === true;
const showEyeIconSafe = showEyeIcon != null && showEyeIcon;
const { unitOfAccountSetting } = this.props;
return (
Expand Down Expand Up @@ -152,11 +143,6 @@ export default class NavWalletDetails extends Component<Props> {
</div>
</div>
}
{this.props.rewards === undefined && (
<div className={styles.info}>
{intl.formatMessage(globalMessages.walletSendConfirmationTotalLabel)}
</div>
)}
</>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ type Props = {|
+shouldHideBalance: boolean,
+highlightTitle?: boolean,
+showEyeIcon?: boolean,
/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
+rewards: null | void | MultiToken,
+rewards: ?MultiToken,
+walletAmount: null | MultiToken,
+infoText?: string,
+showDetails?: boolean,
Expand Down Expand Up @@ -169,11 +164,11 @@ export default class NavWalletDetailsRevamp extends Component<Props> {
}

getTotalAmount: void => null | MultiToken = () => {
if (this.props.rewards === undefined) {
if (this.props.rewards == null) {
return this.props.walletAmount;
}
if (this.props.rewards === null || this.props.walletAmount === null) {
return null;
if (this.props.walletAmount == null) {
return this.props.rewards;
}
return this.props.rewards.joinAddCopy(this.props.walletAmount);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import type { TokenRow } from '../../../api/ada/lib/storage/database/primitives/
type Props = {|
+onUpdateHideBalance: void => Promise<void>,
+shouldHideBalance: boolean,
/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
+rewards?: null | void | MultiToken,
+rewards: ?MultiToken,
+walletAmount: null | MultiToken,
+infoText?: string,
+getTokenInfo: ($ReadOnly<Inexact<TokenLookupKey>>) => $ReadOnly<TokenRow>,
Expand All @@ -32,9 +27,8 @@ type Props = {|

@observer
export default class WalletDetails extends Component<Props> {
static defaultProps: {| infoText: void, rewards: null |} = {
static defaultProps: {| infoText: void |} = {
infoText: undefined,
rewards: null,
};

static contextTypes: {| intl: $npm$ReactIntl$IntlFormat |} = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ export default class TransactionRevamp extends Component<Props, State> {
);
}

const amount = this.renderAmountDisplay({ entry: request.entry, getRawNumber: true });
const isPositiveNumber = typeof amount === 'string' ? amount.charAt(0) === '+' : false; // eslint-disable-line

return (
<Typography variant="body1" fontWeight={500} color="grayscale.900">
{this.renderAmountDisplay({ entry: request.entry })} {this.getTicker(request.entry)}
Expand Down Expand Up @@ -957,6 +954,7 @@ export default class TransactionRevamp extends Component<Props, State> {
data,
address,
addressIndex,
transform: amount => amount.abs().negated(),
});
})}
</div>
Expand Down
16 changes: 2 additions & 14 deletions packages/yoroi-extension/app/containers/NavBarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,7 @@ export default class NavBarContainer extends Component<Props> {
);
}

/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
getRewardBalance: (PublicDeriver<>) => null | void | MultiToken = publicDeriver => {
const delegationRequest = this.props.stores.delegation.getDelegationRequests(publicDeriver);
if (delegationRequest == null) return undefined;

const balanceResult = delegationRequest.getDelegatedBalance.result;
if (balanceResult == null) {
return null;
}
return balanceResult.accountPart;
getRewardBalance: (PublicDeriver<>) => ?MultiToken = publicDeriver => {
return this.props.stores.delegation.getRewardBalance(publicDeriver);
};
}
14 changes: 1 addition & 13 deletions packages/yoroi-extension/app/containers/NavBarContainerRevamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,7 @@ export default class NavBarContainerRevamp extends Component<Props> {
}, []);
};

/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
getRewardBalance: (PublicDeriver<>) => null | void | MultiToken = publicDeriver => {
const delegationRequest = this.props.stores.delegation.getDelegationRequests(publicDeriver);
if (delegationRequest == null) return undefined;

const balanceResult = delegationRequest.getDelegatedBalance.result;
if (balanceResult == null) {
return null;
}
return balanceResult.accountPart;
return this.props.stores.delegation.getRewardBalance(publicDeriver);
};
}
16 changes: 2 additions & 14 deletions packages/yoroi-extension/app/containers/wallet/MyWalletsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,8 @@ class MyWalletsPage extends Component<AllProps> {
return walletSubRow;
};

/**
* undefined => wallet is not a reward wallet
* null => still calculating
* value => done calculating
*/
getRewardBalance: (PublicDeriver<>) => null | void | MultiToken = publicDeriver => {
const delegationRequest = this.props.stores.delegation.getDelegationRequests(publicDeriver);
if (delegationRequest == null) return undefined;

const balanceResult = delegationRequest.getDelegatedBalance.result;
if (balanceResult == null) {
return null;
}
return balanceResult.accountPart;
getRewardBalance: (PublicDeriver<>) => ?MultiToken = publicDeriver => {
return this.props.stores.delegation.getRewardBalance(publicDeriver);
};
}
export default (withLayout(MyWalletsPage): ComponentType<Props>);
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,8 @@ export default class WalletRestoreDialogContainer extends Component<Props> {
await this.props.actions.profile.updateHideBalance.trigger();
};

getRewardBalance: (PublicDeriver<>) => null | void | MultiToken = publicDeriver => {
const delegationRequest = this.props.stores.delegation.getDelegationRequests(publicDeriver);
if (delegationRequest == null) return undefined;

const balanceResult = delegationRequest.getDelegatedBalance.result;
if (balanceResult == null) {
return null;
}
return balanceResult.accountPart;
getRewardBalance: (PublicDeriver<>) => ?MultiToken = publicDeriver => {
return this.props.stores.delegation.getRewardBalance(publicDeriver);
};

openToTransactions: (PublicDeriver<>) => void = publicDeriver => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import { withLayout } from '../../../styles/context/layout';
import type { LayoutComponentMap } from '../../../styles/context/layout';
import { Box } from '@mui/system';
import type { PoolData } from './SeizaFetcher';
import {
isCardanoHaskell,
isTestnet,
} from '../../../api/ada/lib/storage/database/prepackaged/networks';
import { isTestnet } from '../../../api/ada/lib/storage/database/prepackaged/networks';

type Props = {|
...StoresAndActionsProps,
Expand Down Expand Up @@ -78,13 +75,7 @@ class CardanoStakingPage extends Component<AllProps, State> {
const selectedPlate = this.props.stores.wallets.activeWalletPlate;
const stakingListBias = selectedPlate?.TextPart || 'bias';

const delegationRequests = this.props.stores.delegation.getDelegationRequests(
selectedWallet
);
if (delegationRequests == null) {
throw new Error(`${nameof(SeizaFetcher)} opened for non-reward wallet`);
}

const delegatedPoolId = this.props.stores.delegation.getDelegatedPoolId(selectedWallet);
if (urlTemplate != null) {
const totalAda = this._getTotalAda();
const locale = this.props.stores.profile.currentLocale;
Expand All @@ -95,10 +86,7 @@ class CardanoStakingPage extends Component<AllProps, State> {
}
const balance = this.props.stores.transactions.getBalance(publicDeriver);
const isWalletWithNoFunds = balance != null && balance.getDefaultEntry().amount.isZero();
const poolList = (
delegationRequests.getDelegatedBalance.result?.delegation != null &&
this._isRegistered(publicDeriver)
) ? [delegationRequests.getDelegatedBalance.result?.delegation] : [];
const poolList = (delegatedPoolId != null && this._isRegistered(publicDeriver)) ? [delegatedPoolId] : [];

const classicCardanoStakingPage = (
<div id="classicCardanoStakingPage">
Expand Down Expand Up @@ -191,19 +179,12 @@ class CardanoStakingPage extends Component<AllProps, State> {
}

const delegationStore = this.props.stores.delegation;
const delegationRequests = delegationStore.getDelegationRequests(publicDeriver);
if (delegationRequests == null) {
throw new Error(`${nameof(CardanoStakingPage)} opened for non-reward wallet`);
}

const balance = this.props.stores.transactions.getBalance(publicDeriver);
if (balance == null) {
return null;
}
const rewardBalance =
delegationRequests.getDelegatedBalance.result == null
? new MultiToken([], publicDeriver.getParent().getDefaultToken())
: delegationRequests.getDelegatedBalance.result.accountPart;
const rewardBalance = delegationStore.getRewardBalance(publicDeriver)
?? new MultiToken([], publicDeriver.getParent().getDefaultToken());
const tokenInfo = genLookupOrFail(this.props.stores.tokenInfoStore.tokenInfo)(
rewardBalance.getDefaultEntry()
);
Expand Down Expand Up @@ -466,21 +447,7 @@ class CardanoStakingPage extends Component<AllProps, State> {
};

_isRegistered: (PublicDeriver<>) => ?boolean = publicDeriver => {
if (!isCardanoHaskell(publicDeriver.getParent().getNetworkInfo())) {
return undefined;
}
const delegationRequests = this.props.stores.delegation.getDelegationRequests(
publicDeriver
);
if (delegationRequests == null) return undefined;
if (
!delegationRequests.getDelegatedBalance.wasExecuted ||
delegationRequests.getDelegatedBalance.isExecuting ||
delegationRequests.getDelegatedBalance.result == null
) {
return undefined;
}
return delegationRequests.getDelegatedBalance.result.stakeRegistered;
return this.props.stores.delegation.isStakeRegistered(publicDeriver);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ export default class BaseCardanoTimeStore extends Store<StoresMap, ActionsMap> {
const currentRelativeTime = toRelativeSlotNumber(currentAbsoluteSlot.slot);

runInAction(() => {
currTimeRequests.currentEpoch = currentRelativeTime.epoch;
if (currTimeRequests.currentEpoch !== currentRelativeTime.epoch) {
// Clearing processed withdrawals in case epoch changes
this.stores.transactions.clearProcessedWithdrawals(selected);
currTimeRequests.currentEpoch = currentRelativeTime.epoch;
}
currTimeRequests.currentSlot = currentRelativeTime.slot;
currTimeRequests.msIntoSlot = currentAbsoluteSlot.msIntoSlot;
});
Expand Down
37 changes: 29 additions & 8 deletions packages/yoroi-extension/app/stores/toplevel/DelegationStore.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// @flow

import { observable, action, } from 'mobx';
import { action, observable, } from 'mobx';
import { find } from 'lodash';
import type { NetworkRow } from '../../api/ada/lib/storage/database/primitives/tables';
import {
PublicDeriver,
} from '../../api/ada/lib/storage/models/PublicDeriver/index';
import { PublicDeriver, } from '../../api/ada/lib/storage/models/PublicDeriver/index';
import LocalizedRequest from '../lib/LocalizedRequest';
import Store from '../base/Store';
import type {
GetCurrentDelegationFunc,
GetDelegatedBalanceFunc,
RewardHistoryFunc,
GetCurrentDelegationFunc,
GetDelegatedBalanceResponse,
} from '../../api/common/lib/storage/bridge/delegationUtils';
import CachedRequest from '../lib/LocalizedCachedRequest';
import LocalizableError from '../../i18n/LocalizableError';
import {
PoolMissingApiError,
} from '../../api/common/errors';
import { PoolMissingApiError, } from '../../api/common/errors';
import type { MangledAmountFunc } from '../stateless/mangledAddresses';
import type { ActionsMap } from '../../actions/index';
import type { StoresMap } from '../index';
import type { PoolInfo } from '@emurgo/yoroi-lib';
import { MultiToken } from '../../api/common/lib/MultiToken';

export type DelegationRequests = {|
publicDeriver: PublicDeriver<>,
Expand Down Expand Up @@ -120,6 +118,29 @@ export default class DelegationStore extends Store<StoresMap, ActionsMap> {
return undefined; // can happen if the wallet is not a Shelley wallet
}

_getDelegatedBalanceResult: PublicDeriver<> => ?GetDelegatedBalanceResponse = (publicDeriver) => {
const delegationRequest = this.stores.delegation.getDelegationRequests(publicDeriver);
if (delegationRequest == null) return null;
return delegationRequest.getDelegatedBalance.result;
}

getRewardBalance: PublicDeriver<> => ?MultiToken = (publicDeriver) => {
if (this.stores.transactions.hasProcessedWithdrawals(publicDeriver)) {
// In case we have a processed withdrawal for the wallet
// We cancel out any still present reward, in case it has not synced yet
return null;
}
return this._getDelegatedBalanceResult(publicDeriver)?.accountPart ?? null;
}

getDelegatedPoolId: PublicDeriver<> => ?string = (publicDeriver) => {
return this._getDelegatedBalanceResult(publicDeriver)?.delegation ?? null;
}

isStakeRegistered: PublicDeriver<> => ?boolean = (publicDeriver) => {
return this._getDelegatedBalanceResult(publicDeriver)?.stakeRegistered ?? null;
}

getLocalPoolInfo: (
$ReadOnly<NetworkRow>,
string,
Expand Down
Loading
Loading