Skip to content

Commit

Permalink
add entity app action preview for boosts
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed May 29, 2024
1 parent df6542a commit ef3e7b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/extensions/entity/register.ts
Original file line number Diff line number Diff line change
@@ -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 => ({
Expand All @@ -14,7 +15,7 @@ export const DaoExtension = (config: ExtensionConfig): ExtensionInfo => ({
Dark: LogoWhite,
},
Tags: [],
Contracts: {},
Contracts: EntityContracts(config),
AppRoot: App,
WidgetRoots: {},
Developer: {
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/entity/src/BoostSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/extensions/entity/src/contracts.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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) => <BoostActionPreview action={action} />,
},
})
28 changes: 28 additions & 0 deletions src/extensions/entity/src/previews/BoostActionPreview.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<ActionPreviewHighlight>
boost our {EntityConfig.ProductName} with <strong>{displayablePayments}</strong>.
</ActionPreviewHighlight>
)
}

0 comments on commit ef3e7b0

Please sign in to comment.