11import React , { useMemo } from 'react'
2- import style from './transaction.module.css'
32import Image from 'next/image'
43import XECIcon from 'assets/xec-logo.png'
54import BCHIcon from 'assets/bch-logo.png'
65import EyeIcon from 'assets/eye-icon.png'
76import CheckIcon from 'assets/check-icon.png'
87import XIcon from 'assets/x-icon.png'
9- import TableContainerGetter from '../../components/ TableContainer/TableContainerGetter'
8+ import TableContainerGetter from '../TableContainer/TableContainerGetter'
109import { compareNumericString } from 'utils/index'
1110import moment from 'moment-timezone'
1211import { XEC_TX_EXPLORER_URL , BCH_TX_EXPLORER_URL } from 'constants/index'
@@ -15,26 +14,29 @@ interface IProps {
1514 addressSyncing : {
1615 [ address : string ] : boolean
1716 }
17+ paybuttonId : string
1818 tableRefreshCount : number
1919 timezone : string
2020}
2121
22- function getGetterForAddress ( addressString : string ) : Function {
22+ function fetchTransactionsByPaybuttonId ( paybuttonId : string ) : Function {
2323 return async ( page : number , pageSize : number , orderBy : string , orderDesc : boolean ) => {
24- const ok = await fetch ( `/api/address /transactions/${ addressString } ?page=${ page } &pageSize=${ pageSize } &orderBy=${ orderBy } &orderDesc=${ String ( orderDesc ) } ` , {
24+ const response = await fetch ( `/api/paybutton /transactions/${ paybuttonId } ?page=${ page } &pageSize=${ pageSize } &orderBy=${ orderBy } &orderDesc=${ String ( orderDesc ) } ` , {
2525 headers : {
2626 Timezone : moment . tz . guess ( )
2727 }
2828 } )
29- const ok2 = await fetch ( `/api/address/transactions/count/${ addressString } ` )
29+ const responseCount = await fetch ( `/api/paybutton/transactions/count/${ paybuttonId } ` )
30+ const transactions = await response . json ( )
31+ const count = await responseCount . json ( )
3032 return {
31- data : await ok . json ( ) ,
32- totalCount : await ok2 . json ( )
33+ data : transactions . transactions ,
34+ totalCount : count
3335 }
3436 }
3537}
3638
37- export default ( { addressSyncing, tableRefreshCount, timezone = moment . tz . guess ( ) } : IProps ) : JSX . Element => {
39+ export default ( { paybuttonId , addressSyncing, tableRefreshCount, timezone = moment . tz . guess ( ) } : IProps ) : JSX . Element => {
3840 const columns = useMemo (
3941 ( ) => [
4042 {
@@ -80,17 +82,31 @@ export default ({ addressSyncing, tableRefreshCount, timezone = moment.tz.guess(
8082 }
8183 } ,
8284 {
83- Header : 'TX' ,
85+ Header : ( ) => ( < div style = { { textAlign : 'center' } } > TX </ div > ) ,
8486 accessor : 'hash' ,
8587 disableSortBy : true ,
8688 Cell : ( cellProps ) => {
8789 const url = cellProps . cell . row . values [ 'address.networkId' ] === 1 ? XEC_TX_EXPLORER_URL : BCH_TX_EXPLORER_URL
8890 return (
89- < a href = { url . concat ( cellProps . cell . value ) } target = "_blank" rel = "noopener noreferrer" className = "table-eye-ctn" >
90- < div className = "table-eye" >
91- < Image src = { EyeIcon } alt = 'View on explorer' />
92- </ div >
93- </ a >
91+ < div className = "table-eye-ctn" >
92+ < a href = { url . concat ( cellProps . cell . value ) } target = "_blank" rel = "noopener noreferrer" >
93+ < div className = "table-eye" >
94+ < Image src = { EyeIcon } alt = 'View on explorer' />
95+ </ div >
96+ </ a >
97+ </ div >
98+ )
99+ }
100+ } ,
101+ {
102+ Header : ( ) => ( < div style = { { marginRight : '1px' } } > Address</ div > ) ,
103+ accessor : 'address.address' ,
104+ shrinkable : true ,
105+ Cell : ( cellProps ) => {
106+ return (
107+ < div >
108+ { cellProps . cell . value }
109+ </ div >
94110 )
95111 }
96112 }
@@ -99,19 +115,7 @@ export default ({ addressSyncing, tableRefreshCount, timezone = moment.tz.guess(
99115 )
100116 return (
101117 < >
102- { Object . keys ( addressSyncing ) . map ( transactionAddress => (
103- < div key = { transactionAddress } className = 'address-transactions-ctn' >
104- < div className = { style . tablelabel } >
105- < div > { transactionAddress } </ div >
106- < a href = { transactionAddress . slice ( 0 , 5 ) === 'ecash' ? `https://explorer.e.cash/address/${ transactionAddress } ` : `https://blockchair.com/bitcoin-cash/address/${ transactionAddress } ` } target = "_blank" rel = "noopener noreferrer" className = "table-eye-ctn" >
107- < div className = "table-eye" >
108- < Image src = { EyeIcon } alt = 'View on explorer' />
109- </ div >
110- </ a >
111- </ div >
112- < TableContainerGetter columns = { columns } dataGetter = { getGetterForAddress ( transactionAddress ) } tableRefreshCount = { tableRefreshCount } emptyMessage = { 'No transactions.' } />
113- </ div >
114- ) ) }
118+ < TableContainerGetter columns = { columns } dataGetter = { fetchTransactionsByPaybuttonId ( paybuttonId ) } tableRefreshCount = { tableRefreshCount } emptyMessage = { 'No transactions.' } />
115119 </ >
116120 )
117121}
0 commit comments