From ef3e7b0218ecf6a2c95d2e8c580ff6c7effd64b5 Mon Sep 17 00:00:00 2001 From: Micha Vie Date: Wed, 29 May 2024 20:46:09 +0200 Subject: [PATCH] add entity app action preview for boosts --- src/extensions/entity/register.ts | 5 ++-- src/extensions/entity/src/BoostSection.tsx | 4 +-- src/extensions/entity/src/contracts.tsx | 6 +++- .../src/previews/BoostActionPreview.tsx | 28 +++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/extensions/entity/src/previews/BoostActionPreview.tsx diff --git a/src/extensions/entity/register.ts b/src/extensions/entity/register.ts index 3d43511..2ab25e2 100644 --- a/src/extensions/entity/register.ts +++ b/src/extensions/entity/register.ts @@ -1,7 +1,8 @@ import { App } from './src/EntityApp' -import { EntityConfig } from '@peerme/core-ts' import { LogoBlack } from './meta/LogoBlack' import { LogoWhite } from './meta/LogoWhite' +import { EntityConfig } from '@peerme/core-ts' +import { EntityContracts } from './src/contracts' import { ExtensionConfig, ExtensionInfo } from '../../shared/types' export const DaoExtension = (config: ExtensionConfig): ExtensionInfo => ({ @@ -14,7 +15,7 @@ export const DaoExtension = (config: ExtensionConfig): ExtensionInfo => ({ Dark: LogoWhite, }, Tags: [], - Contracts: {}, + Contracts: EntityContracts(config), AppRoot: App, WidgetRoots: {}, Developer: { diff --git a/src/extensions/entity/src/BoostSection.tsx b/src/extensions/entity/src/BoostSection.tsx index 5bd5f2a..aa39871 100644 --- a/src/extensions/entity/src/BoostSection.tsx +++ b/src/extensions/entity/src/BoostSection.tsx @@ -23,8 +23,8 @@ export function BoostSection(props: Props) { const tokenTransfers = payment.isEgld() ? [] : [payment] app.requestProposalAction( - EntityContracts(app.config).StreamCreate.Address, - EntityContracts(app.config).StreamCreate.Endpoint, + EntityContracts(app.config).Boost.Address, + EntityContracts(app.config).Boost.Endpoint, value, [app.config.entity.address], tokenTransfers diff --git a/src/extensions/entity/src/contracts.tsx b/src/extensions/entity/src/contracts.tsx index d7cb8fe..fc3b6c0 100644 --- a/src/extensions/entity/src/contracts.tsx +++ b/src/extensions/entity/src/contracts.tsx @@ -1,3 +1,6 @@ +import React from 'react' +import { ProposalAction } from '@peerme/core-ts' +import { BoostActionPreview } from './previews/BoostActionPreview' import { Network, ExtensionScInfo, ExtensionConfig } from '../../../shared/types' const getContractAddress = (network: Network) => { @@ -7,8 +10,9 @@ const getContractAddress = (network: Network) => { } export const EntityContracts = (config: ExtensionConfig): ExtensionScInfo => ({ - StreamCreate: { + Boost: { Address: getContractAddress(config.network), Endpoint: 'boost', + ActionPreview: (action: ProposalAction) => , }, }) diff --git a/src/extensions/entity/src/previews/BoostActionPreview.tsx b/src/extensions/entity/src/previews/BoostActionPreview.tsx new file mode 100644 index 0000000..898a57f --- /dev/null +++ b/src/extensions/entity/src/previews/BoostActionPreview.tsx @@ -0,0 +1,28 @@ +import React from 'react' +import { TokenTransfer } from '@multiversx/sdk-core' +import { ActionPreviewHighlight } from '../../../../shared/ui/elements' +import { + EntityConfig, + ProposalAction, + toFormattedTokenPayment, + toTokenPaymentFromProposalPayment, +} from '@peerme/core-ts' + +type Props = { + action: ProposalAction +} + +export function BoostActionPreview(props: Props) { + const displayablePayments = + props.action.payments.length > 0 + ? props.action.payments + .map((payment) => toFormattedTokenPayment(toTokenPaymentFromProposalPayment(payment))) + .join(', ') + : toFormattedTokenPayment(TokenTransfer.egldFromBigInteger(props.action.value)) + + return ( + + boost our {EntityConfig.ProductName} with {displayablePayments}. + + ) +}