11import { OutputTypes } from "@iota/iota.js" ;
22import React , { Component , ReactNode } from "react" ;
3- import { IAssociatedOutput } from "../../../models/tangle/IAssociatedOutputsResponse" ;
43import Pagination from "../layout/Pagination" ;
54import Spinner from "../layout/Spinner" ;
65import Output from "./Output" ;
@@ -18,27 +17,18 @@ class Outputs extends Component<OutputsProps, OutputsState> {
1817 constructor ( props : OutputsProps ) {
1918 super ( props ) ;
2019
21- let outputs : OutputTypes [ ] | IAssociatedOutput [ ] = [ ] ;
22-
23- if ( this . props . outputTypes ) {
24- outputs = this . props . outputTypes ;
25- }
26- if ( this . props . associatedOutputs ) {
27- outputs = this . props . associatedOutputs ;
28- }
2920 this . state = {
30- currentPage : this . props . currentPage ,
31- outputs
21+ currentPage : this . props . currentPage
3222 } ;
3323 }
3424
3525 /**
3626 * The outputs on current page.
3727 * @returns The outputs
3828 */
39- private get currentPageOutputs ( ) {
40- if ( this . state . outputs . length > 0 ) {
41- return this . state . outputs . slice ( ...this . getPageIndexes ( ) ) ;
29+ private get currentPageOutputs ( ) {
30+ if ( this . props . outputs . length > 0 ) {
31+ return this . props . outputs . slice ( ...this . getPageIndexes ( ) ) ;
4232 }
4333 return [ ] ;
4434 }
@@ -64,7 +54,7 @@ class Outputs extends Component<OutputsProps, OutputsState> {
6454 < div className = "card--header" >
6555 < h2 className = "card--header__title" > { this . props . title } </ h2 >
6656 < span className = "card--header-count" >
67- { this . state . outputs . length }
57+ { this . props . outputs . length }
6858 </ span >
6959 </ div >
7060 { this . props . statusBusy && (
@@ -77,27 +67,19 @@ class Outputs extends Component<OutputsProps, OutputsState> {
7767 ) }
7868 </ div >
7969
80- { this . props . outputTypes && ( this . currentPageOutputs as OutputTypes [ ] ) . map ( ( output , idx ) => (
81- < Output
82- key = { ( ( this . props . currentPage - 1 ) * this . props . pageSize ) + idx + 1 }
83- index = { ( ( this . props . currentPage - 1 ) * this . props . pageSize ) + idx + 1 }
84- output = { output }
85- />
86- ) ) }
87-
88- { this . props . associatedOutputs &&
89- ( this . currentPageOutputs as IAssociatedOutput [ ] ) . map ( ( output , idx ) => (
70+ { this . currentPageOutputs . map ( ( output , idx ) => (
9071 < Output
9172 key = { output . outputId }
9273 index = { ( ( this . state . currentPage - 1 ) * this . props . pageSize ) + idx + 1 }
93- output = { output . outputDetails ?. output ?? { } as OutputTypes }
74+ outputId = { output . outputId }
75+ output = { output . outputType ?? ( output . outputDetails ?. output ?? { } as OutputTypes ) }
9476 metadata = { output . outputDetails ?. metadata }
9577 />
9678 ) ) }
9779
9880 < Pagination
9981 currentPage = { this . state . currentPage }
100- totalCount = { this . state . outputs . length }
82+ totalCount = { this . props . outputs . length }
10183 pageSize = { this . props . pageSize }
10284 extraPageRangeLimit = { this . props . extraPageRangeLimit }
10385 siblingsCount = { this . props . siblingsCount }
@@ -111,10 +93,10 @@ class Outputs extends Component<OutputsProps, OutputsState> {
11193 ) }
11294 />
11395 </ div >
114- { this . state . outputs . length === 0 && (
96+ { this . props . outputs . length === 0 && (
11597 < div className = "card margin-t-m padding-l" >
11698 < h2 className = "margin-b-s" > { this . props . title } </ h2 >
117- { this . state . outputs && (
99+ { this . props . outputs && (
118100 < div className = "card--value" >
119101 There are no outputs for this address.
120102 </ div >
@@ -132,8 +114,8 @@ class Outputs extends Component<OutputsProps, OutputsState> {
132114 private getPageIndexes ( ) {
133115 const firstPageIndex = ( this . state . currentPage - 1 ) * this . props . pageSize ;
134116 const lastPageIndex =
135- ( this . state . currentPage === Math . ceil ( this . state . outputs . length / this . props . pageSize ) )
136- ? this . state . outputs . length
117+ ( this . state . currentPage === Math . ceil ( this . props . outputs . length / this . props . pageSize ) )
118+ ? this . props . outputs . length
137119 : firstPageIndex + this . props . pageSize ;
138120 return [ firstPageIndex , lastPageIndex ] as const ;
139121 }
0 commit comments