From a49f5f0dd17aef682959bb259cff309e20d02d25 Mon Sep 17 00:00:00 2001 From: Edd Date: Wed, 13 Mar 2024 11:28:04 +0000 Subject: [PATCH] feat(explorer): fees on transfer component (#5907) --- .../size-in-asset/size-in-asset.tsx | 4 +- .../txs/details/transfer/Transfer.graphql | 4 ++ .../transfer/__generated__/Transfer.ts | 6 ++- .../transfer/blocks/transfer-participants.tsx | 49 +++++++++++++++++-- .../txs/details/transfer/transfer-details.tsx | 9 +++- 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/apps/explorer/src/app/components/size-in-asset/size-in-asset.tsx b/apps/explorer/src/app/components/size-in-asset/size-in-asset.tsx index ba6b06146..840e4af86 100644 --- a/apps/explorer/src/app/components/size-in-asset/size-in-asset.tsx +++ b/apps/explorer/src/app/components/size-in-asset/size-in-asset.tsx @@ -33,10 +33,10 @@ const SizeInAsset = ({ } return ( -

+ {label}  -

+ ); }; diff --git a/apps/explorer/src/app/components/txs/details/transfer/Transfer.graphql b/apps/explorer/src/app/components/txs/details/transfer/Transfer.graphql index 0bab974b6..12461ea89 100644 --- a/apps/explorer/src/app/components/txs/details/transfer/Transfer.graphql +++ b/apps/explorer/src/app/components/txs/details/transfer/Transfer.graphql @@ -1,5 +1,9 @@ query ExplorerTransferStatus($id: ID!) { transfer(id: $id) { + fees { + amount + epoch + } transfer { reference timestamp diff --git a/apps/explorer/src/app/components/txs/details/transfer/__generated__/Transfer.ts b/apps/explorer/src/app/components/txs/details/transfer/__generated__/Transfer.ts index cd29ad55a..5d5994820 100644 --- a/apps/explorer/src/app/components/txs/details/transfer/__generated__/Transfer.ts +++ b/apps/explorer/src/app/components/txs/details/transfer/__generated__/Transfer.ts @@ -8,12 +8,16 @@ export type ExplorerTransferStatusQueryVariables = Types.Exact<{ }>; -export type ExplorerTransferStatusQuery = { __typename?: 'Query', transfer?: { __typename?: 'TransferNode', transfer: { __typename?: 'Transfer', reference?: string | null, timestamp: any, status: Types.TransferStatus, reason?: string | null, fromAccountType: Types.AccountType, from: string, to: string, toAccountType: Types.AccountType, amount: string, asset?: { __typename?: 'Asset', id: string } | null } } | null }; +export type ExplorerTransferStatusQuery = { __typename?: 'Query', transfer?: { __typename?: 'TransferNode', fees?: Array<{ __typename?: 'TransferFee', amount: string, epoch: number } | null> | null, transfer: { __typename?: 'Transfer', reference?: string | null, timestamp: any, status: Types.TransferStatus, reason?: string | null, fromAccountType: Types.AccountType, from: string, to: string, toAccountType: Types.AccountType, amount: string, asset?: { __typename?: 'Asset', id: string } | null } } | null }; export const ExplorerTransferStatusDocument = gql` query ExplorerTransferStatus($id: ID!) { transfer(id: $id) { + fees { + amount + epoch + } transfer { reference timestamp diff --git a/apps/explorer/src/app/components/txs/details/transfer/blocks/transfer-participants.tsx b/apps/explorer/src/app/components/txs/details/transfer/blocks/transfer-participants.tsx index 843e46a05..c48c74636 100644 --- a/apps/explorer/src/app/components/txs/details/transfer/blocks/transfer-participants.tsx +++ b/apps/explorer/src/app/components/txs/details/transfer/blocks/transfer-participants.tsx @@ -44,8 +44,14 @@ const AccountType: Record = { ACCOUNT_TYPE_ORDER_MARGIN: 'Order Margin', }; +export type TransferFee = { + amount?: string; + epoch?: number; +}; + interface TransferParticipantsProps { transfer: Transfer; + fees?: TransferFee[] | null; from: string; } @@ -60,6 +66,7 @@ interface TransferParticipantsProps { export function TransferParticipants({ transfer, from, + fees, }: TransferParticipantsProps) { // This mapping is required as the global account types require a type to be set, while // the underlying protobufs allow for every field to be undefined. @@ -104,6 +111,9 @@ export function TransferParticipants({ {transfer.asset ? ( ) : null} + {transfer.asset && fees && ( + + )} {/* Empty divs for the top arrow and the bottom arrow of the transfer inset */} @@ -125,10 +135,6 @@ export function TransferParticipants({ - {/* -
-
- */} @@ -169,3 +175,38 @@ export function TransferRecurringRecipient({ // Fallback should not happen return null; } + +export function TransferFees({ + assetId, + fees, +}: { + assetId: string; + fees: TransferFee[]; +}) { + // A recurring transfer that is rejected or cancelled will have an array of fees of 0 length + if (assetId && fees && fees.length > 0) { + if (fees.length === 1) { + return ( +

+ Fee: +

+ ); + } else { + return ( +
+ {t('Fees')} +
    + {fees.map((fee) => ( +
  • + {' '} + {t('in epoch')} {fee.epoch} +
  • + ))} +
+
+ ); + } + } + + return null; +} diff --git a/apps/explorer/src/app/components/txs/details/transfer/transfer-details.tsx b/apps/explorer/src/app/components/txs/details/transfer/transfer-details.tsx index 3755be0b6..e927f03e0 100644 --- a/apps/explorer/src/app/components/txs/details/transfer/transfer-details.tsx +++ b/apps/explorer/src/app/components/txs/details/transfer/transfer-details.tsx @@ -41,9 +41,16 @@ export function TransferDetails({ transfer, from, id }: TransferDetailsProps) { ? TransferStatus.STATUS_REJECTED : data?.transfer?.transfer.status; + const fees = data?.transfer?.fees?.map((fee) => { + return { + amount: fee?.amount ? fee.amount : '0', + epoch: fee?.epoch ? fee.epoch : 0, + }; + }); + return (
- + {recurring ? : null} {recurring && recurring.dispatchStrategy ? (