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 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
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
10 changes: 10 additions & 0 deletions packages/yoroi-extension/app/api/common/lib/MultiToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export class MultiToken {
values: Array<TokenEntry>;
defaults: DefaultTokenEntry;

/**
* If both passed tokens are not null - they are added.
* If either is null - the one not null is returned.
* If both is null - null is returned.
*/
static sumOrEitherNotNull(token1: ?MultiToken, token2: ?MultiToken): ?MultiToken {
if (token1 == null || token2 == null) return token1 ?? token2;
return token1.joinAddCopy(token2);
}

static from(multiTokenData: {|
values: Array<{| identifier: string, networkId: number, amount: string |}>,
defaults: DefaultTokenEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Props = {|
+showFiat?: boolean,
+shouldHideBalance: boolean,
+getTokenInfo: ($ReadOnly<Inexact<TokenLookupKey>>) => $ReadOnly<TokenRow>,
+amount: null | MultiToken,
+amount: ?MultiToken,
+unitOfAccountSetting: UnitOfAccountSettingType,
+getCurrentPrice: (from: string, to: string) => ?string,
|};
Expand Down
28 changes: 4 additions & 24 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 All @@ -181,14 +167,8 @@ export default class NavWalletDetails extends Component<Props> {
);
}

getTotalAmount: void => (null | MultiToken) = () => {
if (this.props.rewards === undefined) {
return this.props.walletAmount;
}
if (this.props.rewards === null || this.props.walletAmount === null) {
return null;
}
return this.props.walletAmount.joinAddCopy(this.props.rewards);
getTotalAmount: void => ?MultiToken = () => {
return MultiToken.sumOrEitherNotNull(this.props.walletAmount, this.props.rewards);
}

renderAmountDisplay: {|
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 @@ -168,13 +163,7 @@ export default class NavWalletDetailsRevamp extends Component<Props> {
);
}

getTotalAmount: void => null | MultiToken = () => {
if (this.props.rewards === undefined) {
return this.props.walletAmount;
}
if (this.props.rewards === null || this.props.walletAmount === null) {
return null;
}
return this.props.rewards.joinAddCopy(this.props.walletAmount);
getTotalAmount: void => ?MultiToken = () => {
return MultiToken.sumOrEitherNotNull(this.props.walletAmount, this.props.rewards);
};
}
25 changes: 8 additions & 17 deletions packages/yoroi-extension/app/components/topbar/WalletCard.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// @flow
import { Component } from 'react';
import type { Node } from 'react';
import { Component } from 'react';
import { observer } from 'mobx-react';
import { intlShape, defineMessages } from 'react-intl';
import type { $npm$ReactIntl$IntlFormat, $npm$ReactIntl$MessageDescriptor } from 'react-intl';
import { defineMessages, intlShape } from 'react-intl';
import styles from './WalletCard.scss';
import WalletAccountIcon from './WalletAccountIcon';
import type { TokenLookupKey } from '../../api/common/lib/MultiToken';
import { MultiToken } from '../../api/common/lib/MultiToken';
import classnames from 'classnames';
import type { WalletChecksum } from '@emurgo/cip4-js';
import type { $npm$ReactIntl$IntlFormat, $npm$ReactIntl$MessageDescriptor } from 'react-intl';
import type { ConceptualWallet } from '../../api/ada/lib/storage/models/ConceptualWallet/index';
import { isLedgerNanoWallet, isTrezorTWallet, } from '../../api/ada/lib/storage/models/ConceptualWallet/index';
import globalMessages from '../../i18n/global-messages';
import {
isLedgerNanoWallet,
isTrezorTWallet,
} from '../../api/ada/lib/storage/models/ConceptualWallet/index';
import type { TokenLookupKey } from '../../api/common/lib/MultiToken';
import type { TokenRow } from '../../api/ada/lib/storage/database/primitives/tables';
import { ReactComponent as DragIcon } from '../../assets/images/add-wallet/wallet-list/drag.inline.svg';
import { ReactComponent as DragIcon } from '../../assets/images/add-wallet/wallet-list/drag.inline.svg';
import { Draggable } from 'react-beautiful-dnd';
import type { UnitOfAccountSettingType } from '../../types/unitOfAccountType';
import AmountDisplay from '../common/AmountDisplay';
Expand Down Expand Up @@ -192,14 +189,8 @@ export default class WalletCard extends Component<Props, State> {
);
}

getTotalAmount: void => null | MultiToken = () => {
if (this.props.rewards === undefined) {
return this.props.walletAmount;
}
if (this.props.rewards === null || this.props.walletAmount === null) {
return null;
}
return this.props.rewards.joinAddCopy(this.props.walletAmount);
getTotalAmount: void => ?MultiToken = () => {
return MultiToken.sumOrEitherNotNull(this.props.walletAmount, this.props.rewards);
};

countTokenTypes: void => {|tokenTypes: number, nfts: number|} = () => {
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
27 changes: 6 additions & 21 deletions packages/yoroi-extension/app/containers/NavBarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ROUTES } from '../routes-config';
import { asGetPublicKey } from '../api/ada/lib/storage/models/PublicDeriver/traits';
import { PublicDeriver } from '../api/ada/lib/storage/models/PublicDeriver';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import { MultiToken } from '../api/common/lib/MultiToken';
import { genLookupOrFail } from '../stores/stateless/tokenHelpers';
import BuySellDialog from '../components/buySell/BuySellDialog';
import globalMessages from '../i18n/global-messages';
Expand Down Expand Up @@ -57,7 +56,8 @@ export default class NavBarContainer extends Component<Props> {
const wallets = this.props.stores.wallets.publicDerivers;

const walletComponents = wallets.map(wallet => {
const balance = this.props.stores.transactions.balance;
const balance = this.props.stores.transactions.getBalance(wallet);
const rewards = this.props.stores.delegation.getRewardBalance(wallet);
const lastSyncInfo = this.props.stores.transactions.lastSyncInfo;

const parent = wallet.getParent();
Expand All @@ -81,9 +81,9 @@ export default class NavBarContainer extends Component<Props> {
detailComponent={
<NavWalletDetails
walletAmount={balance}
rewards={rewards}
onUpdateHideBalance={this.updateHideBalance}
shouldHideBalance={profile.shouldHideBalance}
rewards={this.getRewardBalance(wallet)}
getTokenInfo={genLookupOrFail(this.props.stores.tokenInfoStore.tokenInfo)}
defaultToken={this.props.stores.tokenInfoStore.getDefaultTokenInfo(
wallet.getParent().getNetworkInfo().NetworkId
Expand Down Expand Up @@ -114,13 +114,14 @@ export default class NavBarContainer extends Component<Props> {
return <NoWalletsDropdown />;
}

const balance = this.props.stores.transactions.balance;
const balance = this.props.stores.transactions.getBalance(publicDeriver);
const rewards = this.props.stores.delegation.getRewardBalance(publicDeriver);

return (
<NavWalletDetails
onUpdateHideBalance={this.updateHideBalance}
shouldHideBalance={profile.shouldHideBalance}
rewards={this.getRewardBalance(publicDeriver)}
rewards={rewards}
walletAmount={balance}
getTokenInfo={genLookupOrFail(this.props.stores.tokenInfoStore.tokenInfo)}
defaultToken={this.props.stores.tokenInfoStore.getDefaultTokenInfo(
Expand Down Expand Up @@ -168,20 +169,4 @@ export default class NavBarContainer extends Component<Props> {
<NavBar title={this.props.title} walletPlate={getPlate()} walletDetails={dropdownComponent} />
);
}

/**
* 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;
};
}
31 changes: 7 additions & 24 deletions packages/yoroi-extension/app/containers/NavBarContainerRevamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ROUTES } from '../routes-config';
import { ConceptualWallet } from '../api/ada/lib/storage/models/ConceptualWallet/index';
import { asGetPublicKey } from '../api/ada/lib/storage/models/PublicDeriver/traits';
import { PublicDeriver } from '../api/ada/lib/storage/models/PublicDeriver';
import { MultiToken } from '../api/common/lib/MultiToken';
import { genLookupOrFail, getTokenName } from '../stores/stateless/tokenHelpers';
import { networks } from '../api/ada/lib/storage/database/prepackaged/networks';
import { addressToDisplayString } from '../api/ada/lib/storage/bridge/utils';
Expand Down Expand Up @@ -76,14 +75,15 @@ export default class NavBarContainerRevamp extends Component<Props> {
: this.props.stores.wallets.getPublicKeyCache(withPubKey).plate;

const balance = this.props.stores.transactions.getBalance(publicDeriver);
const rewards = this.props.stores.delegation.getRewardBalance(publicDeriver);

return (
<NavWalletDetailsRevamp
plate={plate}
wallet={settingsCache}
onUpdateHideBalance={this.updateHideBalance}
shouldHideBalance={profile.shouldHideBalance}
rewards={this.getRewardBalance(publicDeriver)}
rewards={rewards}
walletAmount={balance}
getTokenInfo={genLookupOrFail(this.props.stores.tokenInfoStore.tokenInfo)}
defaultToken={this.props.stores.tokenInfoStore.getDefaultTokenInfo(
Expand Down Expand Up @@ -129,11 +129,10 @@ export default class NavBarContainerRevamp extends Component<Props> {
const cardanoWallets = [];

wallets.forEach(wallet => {
const walletBalance = this.props.stores.transactions.getBalance(wallet);
const walletAmount = this.props.stores.transactions.getBalance(wallet);
const rewards = this.props.stores.delegation.getRewardBalance(wallet);
const parent = wallet.getParent();
const settingsCache = this.props.stores.walletSettings.getConceptualWalletSettingsCache(
parent
);
const settingsCache = this.props.stores.walletSettings.getConceptualWalletSettingsCache(parent);

const withPubKey = asGetPublicKey(wallet);
const plate =
Expand All @@ -143,8 +142,8 @@ export default class NavBarContainerRevamp extends Component<Props> {

const walletMap = {
walletId: wallet.getPublicDeriverId(),
rewards: this.getRewardBalance(wallet),
walletAmount: walletBalance,
rewards,
walletAmount,
getTokenInfo: genLookupOrFail(this.props.stores.tokenInfoStore.tokenInfo),
plate,
wallet,
Expand Down Expand Up @@ -228,20 +227,4 @@ export default class NavBarContainerRevamp extends Component<Props> {
return acc;
}, []);
};

/**
* 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;
};
}
Loading
Loading