mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-21 16:52:01 -07:00
feat():Counter Offers Page: Set up test environment
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
This Card component displays a counter offer with token icon, name, and price.
|
||||
*/
|
||||
|
||||
// Global npm libraries
|
||||
import React, { useState } from 'react'
|
||||
import { Container, Row, Col, Card, Button } from 'react-bootstrap'
|
||||
import Jdenticon from '@chris.troutner/react-jdenticon'
|
||||
|
||||
function CounterOfferCard (props) {
|
||||
const { offer } = props
|
||||
const [icon, setIcon] = useState(offer.tokenIcon)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Col xs={12} sm={6} lg={4} style={{ padding: '25px' }}>
|
||||
<Card className='shadow-sm'>
|
||||
<Card.Body style={{ textAlign: 'center', padding: '10px' }}>
|
||||
{/** If the icon is loaded, display it */}
|
||||
{icon && (
|
||||
<Card.Img
|
||||
src={icon}
|
||||
style={{ height: '100px', width: 'auto', margin: '0 auto' }}
|
||||
onError={(e) => {
|
||||
setIcon(null) // Set the icon to null if it fails to load the image url.
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/** If the icon is not loaded, display the Jdenticon */}
|
||||
{!icon && (
|
||||
<div style={{ display: 'flex', justifyContent: 'center', marginBottom: '10px' }}>
|
||||
<Jdenticon size='100' value={offer.tokenId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card.Title style={{ textAlign: 'center', marginTop: '10px' }}>
|
||||
<h4>{offer.ticker}</h4>
|
||||
</Card.Title>
|
||||
|
||||
<Container>
|
||||
<Row>
|
||||
<Col>
|
||||
{/* <strong>{offer.tokenName}</strong> */}
|
||||
<strong>Counter Offer UTXO</strong>
|
||||
</Col>
|
||||
</Row>
|
||||
<br />
|
||||
|
||||
<Row>
|
||||
{/* <Col>Price:</Col> */}
|
||||
<Col><strong>{offer.price}</strong></Col>
|
||||
</Row>
|
||||
<br />
|
||||
|
||||
<Row className='text-center'>
|
||||
<Col>
|
||||
<Button disabled variant='danger' size='sm'>
|
||||
Cancel
|
||||
</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Col>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default CounterOfferCard
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Shows Counter Offers created by the user.
|
||||
*/
|
||||
|
||||
// Global npm libraries
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Container, Row, Col, Spinner } from 'react-bootstrap'
|
||||
|
||||
// Local libraries
|
||||
import CounterOfferCard from './counter-offer-card'
|
||||
import AsyncLoad from '../../../services/async-load'
|
||||
|
||||
function CounterOffers (props) {
|
||||
const appData = props.appData
|
||||
|
||||
const [counterOffers, setCounterOffers] = useState([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
|
||||
// Generate counter offer cards
|
||||
const generateCards = () => {
|
||||
return counterOffers.map((offer) => (
|
||||
<CounterOfferCard
|
||||
key={offer.id}
|
||||
offer={offer}
|
||||
appData={appData}
|
||||
/>
|
||||
))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const loadWallet = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const { bchWalletState, serverUrl } = appData
|
||||
const asyncLoad = new AsyncLoad()
|
||||
await asyncLoad.loadWalletLib()
|
||||
const counterOfferWallet = await asyncLoad.getDerivatedWallet(serverUrl, bchWalletState.mnemonic, "m/44'/245'/0'/0/1")
|
||||
|
||||
const utxoStore = counterOfferWallet.utxos.utxoStore
|
||||
const bchUtxos = utxoStore.bchUtxos
|
||||
setCounterOffers(bchUtxos)
|
||||
console.log('counterOffers', bchUtxos)
|
||||
setIsLoading(false)
|
||||
} catch (error) {
|
||||
setIsLoading(false)
|
||||
console.log('error', error)
|
||||
}
|
||||
}
|
||||
|
||||
loadWallet()
|
||||
}, [appData])
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Row>
|
||||
<Col>
|
||||
<h1>Counter Offers</h1>
|
||||
<p className='text-muted'>Your pending counter offers</p>
|
||||
</Col>
|
||||
</Row>
|
||||
{isLoading
|
||||
? (
|
||||
<Row className='text-center' style={{ padding: '50px' }}>
|
||||
<Col>
|
||||
<Spinner animation='border' role='status'>
|
||||
<span className='visually-hidden'>Loading...</span>
|
||||
</Spinner>
|
||||
<p className='mt-3 text-muted'>Loading counter offers...</p>
|
||||
</Col>
|
||||
</Row>
|
||||
)
|
||||
: (
|
||||
<>
|
||||
<Row>
|
||||
{generateCards()}
|
||||
</Row>
|
||||
{counterOffers.length === 0 && (
|
||||
<Row className='text-center'>
|
||||
<Col>
|
||||
<p>No counter offers found.</p>
|
||||
</Col>
|
||||
</Row>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default CounterOffers
|
||||
@@ -30,6 +30,7 @@ import ContentCreators from './nostr/content-creators/index.js'
|
||||
import UserDataReview from './user-data-review'
|
||||
import Offers from './offers'
|
||||
import NostrChat from './nostr-chat'
|
||||
import CounterOffers from './counter-offers'
|
||||
function AppBody (props) {
|
||||
// Dependency injection through props
|
||||
const appData = props.appData
|
||||
@@ -55,6 +56,7 @@ function AppBody (props) {
|
||||
<Route path='/content-creators' element={<ContentCreators appData={appData} />} />
|
||||
<Route path='/user-data/:tokenId' element={<UserDataReview appData={appData} />} />
|
||||
<Route path='/offers' element={<Offers appData={appData} />} />
|
||||
<Route path='/counter-offers' element={<CounterOffers appData={appData} />} />
|
||||
<Route path='/nostr-chat' element={<NostrChat appData={appData} />} />
|
||||
</Routes>
|
||||
{/** Show in all paths except the servers view */}
|
||||
|
||||
@@ -58,6 +58,14 @@ function NavMenu (props) {
|
||||
Fungible Tokens
|
||||
</NavLink>
|
||||
|
||||
<NavLink
|
||||
className={currentPath === '/counter-offers' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
to='/counter-offers'
|
||||
onClick={handleClickEvent}
|
||||
>
|
||||
Counter Offers
|
||||
</NavLink>
|
||||
|
||||
<hr />
|
||||
|
||||
<NavLink
|
||||
|
||||
@@ -333,6 +333,28 @@ class AsyncLoad {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async getDerivatedWallet (restURL, mnemonic, hdPath = "m/44'/245'/0'/0/0") {
|
||||
try {
|
||||
const options = {
|
||||
interface: 'consumer-api',
|
||||
restURL,
|
||||
noUpdate: true,
|
||||
hdPath
|
||||
}
|
||||
|
||||
const wallet = new this.BchWallet(mnemonic, options)
|
||||
|
||||
// Wait for wallet to initialize.
|
||||
await wallet.walletInfoPromise
|
||||
await wallet.initialize()
|
||||
|
||||
return wallet
|
||||
} catch (error) {
|
||||
console.error('Error initStarterWallet: ', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sleep (ms) {
|
||||
|
||||
Reference in New Issue
Block a user