fix(trading): fix reward card asssets (#5888)

Co-authored-by: bwallacee <ben@vega.xyz>
This commit is contained in:
m.ray 2024-02-29 11:21:35 +02:00 committed by GitHub
parent bc413ed314
commit 375f4da541
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 13 deletions

View File

@ -24,6 +24,7 @@ import {
type DispatchStrategy, type DispatchStrategy,
IndividualScopeMapping, IndividualScopeMapping,
IndividualScopeDescriptionMapping, IndividualScopeDescriptionMapping,
type Asset,
} from '@vegaprotocol/types'; } from '@vegaprotocol/types';
import { Card } from '../card/card'; import { Card } from '../card/card';
import { type ReactNode, useState } from 'react'; import { type ReactNode, useState } from 'react';
@ -200,7 +201,8 @@ export const ActiveRewardCard = ({
transferNode.transfer.asset?.decimals || 0, transferNode.transfer.asset?.decimals || 0,
6 6
)} )}
rewardAsset={transferNode.asset} rewardAsset={transferNode.dispatchAsset}
transferAsset={transferNode.transfer.asset || undefined}
endsIn={ endsIn={
transferNode.transfer.kind.endEpoch != null transferNode.transfer.kind.endEpoch != null
? transferNode.transfer.kind.endEpoch - currentEpoch ? transferNode.transfer.kind.endEpoch - currentEpoch
@ -216,6 +218,8 @@ const RewardCard = ({
colour, colour,
rewardAmount, rewardAmount,
rewardAsset, rewardAsset,
transferAsset,
vegaAsset,
dispatchStrategy, dispatchStrategy,
endsIn, endsIn,
dispatchMetricInfo, dispatchMetricInfo,
@ -224,12 +228,14 @@ const RewardCard = ({
rewardAmount: string; rewardAmount: string;
/** The asset linked to the dispatch strategy via `dispatchMetricAssetId` property. */ /** The asset linked to the dispatch strategy via `dispatchMetricAssetId` property. */
rewardAsset?: BasicAssetDetails; rewardAsset?: BasicAssetDetails;
/** The VEGA asset details, required to format the min staking amount. */
transferAsset?: Asset | undefined;
/** The VEGA asset details, required to format the min staking amount. */
vegaAsset?: BasicAssetDetails;
/** The transfer's dispatch strategy. */ /** The transfer's dispatch strategy. */
dispatchStrategy: DispatchStrategy; dispatchStrategy: DispatchStrategy;
/** The number of epochs until the transfer stops. */ /** The number of epochs until the transfer stops. */
endsIn?: number; endsIn?: number;
/** The VEGA asset details, required to format the min staking amount. */
vegaAsset?: BasicAssetDetails;
dispatchMetricInfo?: ReactNode; dispatchMetricInfo?: ReactNode;
}) => { }) => {
const t = useT(); const t = useT();
@ -269,7 +275,9 @@ const RewardCard = ({
{rewardAmount} {rewardAmount}
</span> </span>
<span className="font-alpha">{rewardAsset?.symbol || ''}</span> <span className="font-alpha" data-testid="reward-asset">
{transferAsset?.symbol || ''}
</span>
</h3> </h3>
{/** DISTRIBUTION STRATEGY */} {/** DISTRIBUTION STRATEGY */}
@ -357,6 +365,7 @@ const RewardCard = ({
<RewardRequirements <RewardRequirements
dispatchStrategy={dispatchStrategy} dispatchStrategy={dispatchStrategy}
rewardAsset={rewardAsset} rewardAsset={rewardAsset}
vegaAsset={vegaAsset}
/> />
)} )}
</div> </div>
@ -379,8 +388,8 @@ export const DispatchMetricInfo = ({
let additionalDispatchMetricInfo = null; let additionalDispatchMetricInfo = null;
// if asset found then display asset symbol // if asset found then display asset symbol
if (reward.asset) { if (reward.dispatchAsset) {
additionalDispatchMetricInfo = <span>{reward.asset.symbol}</span>; additionalDispatchMetricInfo = <span>{reward.dispatchAsset.symbol}</span>;
} }
// but if scoped to only one market then display market name // but if scoped to only one market then display market name
if (marketNames.length === 1) { if (marketNames.length === 1) {

View File

@ -53,7 +53,24 @@ def setup_teams_and_games(vega: VegaServiceNull):
MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id MM_WALLET.name, parameter="reward.asset", new_value=tDAI_asset_id
) )
next_epoch(vega=vega) next_epoch(vega=vega)
vega.create_asset(
MM_WALLET.name,
name="VEGA",
symbol="VEGA",
decimals=5,
max_faucet_amount=1e10,
quantum=100000,
)
vega.wait_fn(1)
vega.wait_for_total_catchup()
VEGA_asset_id = vega.find_asset_id(symbol="VEGA")
vega.mint(PARTY_A.name, VEGA_asset_id, 1e5)
vega.mint(PARTY_B.name, VEGA_asset_id, 1e5)
vega.wait_fn(1)
vega.wait_for_total_catchup()
team_name = create_team(vega) team_name = create_team(vega)
next_epoch(vega) next_epoch(vega)
@ -101,7 +118,7 @@ def setup_teams_and_games(vega: VegaServiceNull):
from_key_name=PARTY_A.name, from_key_name=PARTY_A.name,
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL, from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES, to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
asset=tDAI_asset_id, asset=VEGA_asset_id,
reference="reward", reference="reward",
asset_for_metric=tDAI_asset_id, asset_for_metric=tDAI_asset_id,
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID, metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
@ -119,7 +136,7 @@ def setup_teams_and_games(vega: VegaServiceNull):
from_key_name=PARTY_B.name, from_key_name=PARTY_B.name,
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL, from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES, to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
asset=tDAI_asset_id, asset=VEGA_asset_id,
reference="reward", reference="reward",
asset_for_metric=tDAI_asset_id, asset_for_metric=tDAI_asset_id,
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID, metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
@ -288,6 +305,7 @@ def test_game_card(competitions_page: Page):
expect(game_1.get_by_test_id("entity-scope")).to_have_text("Individual") expect(game_1.get_by_test_id("entity-scope")).to_have_text("Individual")
expect(game_1.get_by_test_id("locked-for")).to_have_text("1 epoch") expect(game_1.get_by_test_id("locked-for")).to_have_text("1 epoch")
expect(game_1.get_by_test_id("reward-value")).to_have_text("100.00") expect(game_1.get_by_test_id("reward-value")).to_have_text("100.00")
expect(game_1.get_by_test_id("reward-asset")).to_have_text("VEGA")
expect(game_1.get_by_test_id("distribution-strategy")).to_have_text("Pro rata") expect(game_1.get_by_test_id("distribution-strategy")).to_have_text("Pro rata")
expect(game_1.get_by_test_id("dispatch-metric-info")).to_have_text( expect(game_1.get_by_test_id("dispatch-metric-info")).to_have_text(
"Price maker fees paid • tDAI" "Price maker fees paid • tDAI"

View File

@ -31,7 +31,7 @@ export type RewardTransfer = TransferNode & {
export type EnrichedRewardTransfer = RewardTransfer & { export type EnrichedRewardTransfer = RewardTransfer & {
/** Dispatch metric asset (reward asset) */ /** Dispatch metric asset (reward asset) */
asset?: AssetFieldsFragment; dispatchAsset?: AssetFieldsFragment;
/** A flag determining whether a reward asset is being traded on any of the active markets */ /** A flag determining whether a reward asset is being traded on any of the active markets */
isAssetTraded?: boolean; isAssetTraded?: boolean;
/** A list of markets in scope */ /** A list of markets in scope */
@ -142,9 +142,10 @@ export const useRewards = ({
.filter((node) => (scopeToTeams ? isScopedToTeams(node) : true)) .filter((node) => (scopeToTeams ? isScopedToTeams(node) : true))
// enrich with dispatch asset and markets in scope details // enrich with dispatch asset and markets in scope details
.map((node) => { .map((node) => {
const asset = const dispatchAsset =
assets && (assets &&
assets[node.transfer.kind.dispatchStrategy.dispatchMetricAssetId]; assets[node.transfer.kind.dispatchStrategy.dispatchMetricAssetId]) ||
undefined;
const marketsInScope = compact( const marketsInScope = compact(
node.transfer.kind.dispatchStrategy.marketIdsInScope?.map( node.transfer.kind.dispatchStrategy.marketIdsInScope?.map(
(id) => markets && markets[id] (id) => markets && markets[id]
@ -167,7 +168,7 @@ export const useRewards = ({
}); });
return { return {
...node, ...node,
asset: asset ? asset : undefined, dispatchAsset,
isAssetTraded: isAssetTraded != null ? isAssetTraded : undefined, isAssetTraded: isAssetTraded != null ? isAssetTraded : undefined,
markets: marketsInScope.length > 0 ? marketsInScope : undefined, markets: marketsInScope.length > 0 ? marketsInScope : undefined,
}; };