This repository was archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the OrdersTableWidget structure
- Loading branch information
1 parent
66c18b3
commit 2da3f7c
Showing
5 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/apps/explorer/components/OrdersTableWidget/OrdersTableWithData.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useEffect, useState, useCallback } from 'react' | ||
import { useParams } from 'react-router' | ||
import { getOrders } from 'api/operator' | ||
// import { getOrders } from 'api/operator/operatorMock' | ||
// import { useNetworkId } from 'state/network' | ||
import { Network } from 'types' | ||
|
||
import OrdersTable from 'components/orders/OrdersUserDetailsTable' | ||
import { Order } from 'api/operator' | ||
import { transformOrder } from 'utils' | ||
|
||
function useAddressParam(): string { | ||
const { address } = useParams<{ address: string }>() | ||
|
||
return address | ||
} | ||
|
||
type Result = { | ||
orders: Order[] | ||
error: string | ||
isLoading: boolean | ||
} | ||
|
||
function useGetOrders(owner: string): Result { | ||
const [isLoading, setIsLoading] = useState(false) | ||
const [error, setError] = useState('') | ||
const [orders, setOrders] = useState<Order[]>([]) | ||
const networkId = Network.Rinkeby // useNetworkId() | ||
|
||
const fetchOrders = useCallback(async (networkId: Network, owner?: string): Promise<void> => { | ||
setIsLoading(true) | ||
setError('') | ||
|
||
try { | ||
const ordersFetched = await getOrders({ networkId, owner }) | ||
|
||
// TODO: fetch buy/sellToken objects | ||
setOrders(ordersFetched.map((order) => transformOrder(order))) | ||
} catch (e) { | ||
const msg = `Failed to fetch trades` | ||
console.error(msg, e) | ||
setError(msg) | ||
} finally { | ||
setIsLoading(false) | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (!networkId) { | ||
return | ||
} | ||
|
||
fetchOrders(networkId, owner) | ||
}, [fetchOrders, networkId, owner]) | ||
|
||
return { orders, error, isLoading } | ||
} | ||
|
||
export const OrdersTableWithData: React.FC = () => { | ||
const ownerAddress = useAddressParam() | ||
|
||
const { orders, isLoading } = useGetOrders(ownerAddress) | ||
// console.log('orders', orders, isLoading, error) | ||
|
||
return isLoading ? <h2>Loading...</h2> : <OrdersTable orders={orders} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { media } from 'theme/styles/media' | ||
|
||
import ExplorerTabs from 'apps/explorer/components/common/ExplorerTabs/ExplorerTab' | ||
import { OrdersTableWithData } from './OrdersTableWithData' | ||
|
||
const Wrapper = styled.div` | ||
padding: 1.6rem; | ||
margin: 0 auto; | ||
width: 100%; | ||
max-width: 140rem; | ||
${media.mediumDown} { | ||
max-width: 94rem; | ||
} | ||
${media.mobile} { | ||
max-width: 100%; | ||
} | ||
> h1 { | ||
display: flex; | ||
padding: 2.4rem 0 0.75rem; | ||
align-items: center; | ||
font-weight: ${({ theme }): string => theme.fontBold}; | ||
} | ||
` | ||
const tabItems = [ | ||
{ | ||
id: 1, | ||
tab: 'Orders', | ||
content: <OrdersTableWithData />, | ||
}, | ||
{ | ||
id: 2, | ||
tab: 'Trades', | ||
content: ( | ||
<> | ||
<h2>Trades Content</h2> | ||
</> | ||
), | ||
}, | ||
] | ||
|
||
const OrdersTableWidget: React.FC = () => { | ||
return ( | ||
<Wrapper> | ||
<ExplorerTabs tabItems={tabItems} /> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export default OrdersTableWidget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import React from 'react' | ||
|
||
const UserDetails: React.FC = () => <h3>Placeholder Page</h3> | ||
import OrdersTableWidget from '../components/OrdersTableWidget' | ||
|
||
const UserDetails: React.FC = () => <OrdersTableWidget /> | ||
|
||
export default UserDetails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters