mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex-taker-v2.git
synced 2026-09-21 16:52:01 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d31a7f5e73 | ||
|
|
b973f7101a | ||
|
|
313df177e9 | ||
|
|
2c34ea5c2e | ||
|
|
e9e9982de0 | ||
|
|
5a3010ffce |
Generated
+1652
-6439
File diff suppressed because it is too large
Load Diff
+12
-1
@@ -40,7 +40,8 @@
|
|||||||
"eject": "react-app-rewired eject",
|
"eject": "react-app-rewired eject",
|
||||||
"lint": "standard --env mocha --fix",
|
"lint": "standard --env mocha --fix",
|
||||||
"pub": "node deploy/publish-main.js",
|
"pub": "node deploy/publish-main.js",
|
||||||
"pub:ghp": "./deploy/publish-gh-pages.sh"
|
"pub:ghp": "./deploy/publish-gh-pages.sh",
|
||||||
|
"postinstall": "rm -rf node_modules/fork-ts-checker-webpack-plugin/node_modules 2>/dev/null || true && (cd node_modules/@eslint/eslintrc && npm install ajv@^6.12.6 --no-save 2>/dev/null || true) && (cd node_modules/eslint && npm install ajv@^6.12.6 --no-save 2>/dev/null || true)"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "react-app"
|
"extends": "react-app"
|
||||||
@@ -66,6 +67,16 @@
|
|||||||
"standard": "17.0.0",
|
"standard": "17.0.0",
|
||||||
"web3.storage": "4.3.0"
|
"web3.storage": "4.3.0"
|
||||||
},
|
},
|
||||||
|
"overrides": {
|
||||||
|
"ajv": "^8.17.1",
|
||||||
|
"ajv-keywords": "^5.1.0",
|
||||||
|
"ajv-formats": "^2.1.1",
|
||||||
|
"babel-loader": {
|
||||||
|
"schema-utils": "^2.7.1",
|
||||||
|
"ajv-keywords": "^3.5.2",
|
||||||
|
"ajv": "^6.12.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"publish": [
|
"publish": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
This component renders as a button. When clicked, it opens a modal that
|
||||||
|
cancels the counter offer.
|
||||||
|
|
||||||
|
This is a functional component with as little state as possible.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Global npm libraries
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import { Button, Modal, Container } from 'react-bootstrap'
|
||||||
|
|
||||||
|
function CancelCounterOfferBtn (props) {
|
||||||
|
const [show, setShow] = useState(false)
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setShow(false)
|
||||||
|
// props.instance.setState({ showModal: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpen = () => {
|
||||||
|
setShow(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button variant='danger' onClick={handleOpen} disabled>Cancel</Button>
|
||||||
|
<Modal show={show} onHide={handleClose}>
|
||||||
|
<Modal.Header closeButton>
|
||||||
|
<Modal.Title>Cancel </Modal.Title>
|
||||||
|
</Modal.Header>
|
||||||
|
<Modal.Body>
|
||||||
|
<Container>
|
||||||
|
{/** ... */}
|
||||||
|
</Container>
|
||||||
|
</Modal.Body>
|
||||||
|
<Modal.Footer />
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CancelCounterOfferBtn
|
||||||
@@ -1,64 +1,79 @@
|
|||||||
/*
|
/*
|
||||||
This Card component displays a counter offer with token icon, name, and price.
|
This Card component summarizes an SLP token.
|
||||||
|
if a token icon does not exist or cant be loaded , then display a default icon from Jdenticon library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Global npm libraries
|
// Global npm libraries
|
||||||
import React, { useState } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Container, Row, Col, Card, Button } from 'react-bootstrap'
|
import { Container, Row, Col, Card, Button } from 'react-bootstrap'
|
||||||
import Jdenticon from '@chris.troutner/react-jdenticon'
|
import Jdenticon from '@chris.troutner/react-jdenticon'
|
||||||
|
// Local libraries
|
||||||
|
import InfoButton from './info-button'
|
||||||
|
import CancelCounterOfferBtn from './cancel-counter-offer-btn'
|
||||||
|
|
||||||
function CounterOfferCard (props) {
|
function CounterOfferCard (props) {
|
||||||
const { offer } = props
|
const { token } = props
|
||||||
const [icon, setIcon] = useState(offer.tokenIcon)
|
const [icon, setIcon] = useState(token.icon)
|
||||||
|
|
||||||
|
// Update icon state every token.icon changes
|
||||||
|
useEffect(() => {
|
||||||
|
setIcon(token.icon)
|
||||||
|
}, [token.icon])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Col xs={12} sm={6} lg={4} style={{ padding: '25px' }}>
|
<Col xs={12} sm={6} lg={4} style={{ padding: '25px' }}>
|
||||||
<Card className='shadow-sm'>
|
<Card>
|
||||||
<Card.Body style={{ textAlign: 'center', padding: '10px' }}>
|
<Card.Body style={{ textAlign: 'center' }}>
|
||||||
{/** If the icon is loaded, display it */}
|
{/** If the icon is loaded, display it */
|
||||||
{icon && (
|
icon && (
|
||||||
<Card.Img
|
<Card.Img
|
||||||
src={icon}
|
src={icon}
|
||||||
style={{ height: '100px', width: 'auto', margin: '0 auto' }}
|
style={{ height: '100px', width: 'auto' }}
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
setIcon(null) // Set the icon to null if it fails to load the image url.
|
setIcon(null) // Set the icon to null if it fails to load the image url.
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/** If the icon is not loaded, display the Jdenticon */}
|
{/** If the icon is not loaded, display the Jdenticon */
|
||||||
{!icon && (
|
!icon && (
|
||||||
<div style={{ display: 'flex', justifyContent: 'center', marginBottom: '10px' }}>
|
<Jdenticon size='100' value={token.tokenId} />
|
||||||
<Jdenticon size='100' value={offer.tokenId} />
|
)
|
||||||
</div>
|
}
|
||||||
)}
|
<Card.Title style={{ textAlign: 'center' }}>
|
||||||
|
<h4>{props.token.ticker}</h4>
|
||||||
<Card.Title style={{ textAlign: 'center', marginTop: '10px' }}>
|
|
||||||
<h4>{offer.ticker}</h4>
|
|
||||||
</Card.Title>
|
</Card.Title>
|
||||||
|
|
||||||
<Container>
|
<Container>
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
{/* <strong>{offer.tokenName}</strong> */}
|
{props.token.name}
|
||||||
<strong>Counter Offer UTXO</strong>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<Row>
|
|
||||||
{/* <Col>Price:</Col> */}
|
|
||||||
<Col><strong>{offer.price}</strong></Col>
|
|
||||||
</Row>
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<Row className='text-center'>
|
<Row className='text-center'>
|
||||||
<Col>
|
<Col xs={4}>
|
||||||
<Button disabled variant='danger' size='sm'>
|
<InfoButton token={props.token} />
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col xs={4}>
|
||||||
|
<Button
|
||||||
|
href={`/profile/${props.token.makerNpub}#single-view`}
|
||||||
|
target='_blank'
|
||||||
|
rel='noopener noreferrer'
|
||||||
|
disabled={!props.token.makerNpub}
|
||||||
|
>
|
||||||
|
Seller
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</Col>
|
||||||
|
<Col xs={4}>
|
||||||
|
<CancelCounterOfferBtn token={props.token} />
|
||||||
|
</Col>
|
||||||
|
|
||||||
</Row>
|
</Row>
|
||||||
</Container>
|
</Container>
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
|
|||||||
@@ -1,89 +1,245 @@
|
|||||||
/*
|
/*
|
||||||
Shows Counter Offers created by the user.
|
This component displays the counter offers for the current wallet.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Global npm libraries
|
// Global npm libraries
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect, useCallback } from 'react'
|
||||||
import { Container, Row, Col, Spinner } from 'react-bootstrap'
|
import { Container, Row, Col, Spinner, Button } from 'react-bootstrap'
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
// Local libraries
|
|
||||||
import CounterOfferCard from './counter-offer-card'
|
import CounterOfferCard from './counter-offer-card'
|
||||||
import AsyncLoad from '../../../services/async-load'
|
import AsyncLoad from '../../../services/async-load'
|
||||||
|
import { faRedo } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
// Local libraries
|
||||||
|
|
||||||
function CounterOffers (props) {
|
const CounterOffers = (props) => {
|
||||||
const appData = props.appData
|
const { appData } = props
|
||||||
|
const [iconsAreLoaded, setIconsAreLoaded] = useState(false)
|
||||||
|
const [dataAreLoaded, setDataAreLoaded] = useState(false)
|
||||||
const [counterOffers, setCounterOffers] = useState([])
|
const [counterOffers, setCounterOffers] = useState([])
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
|
||||||
// Generate counter offer cards
|
// Get Cid from url
|
||||||
|
const parseCid = (url) => {
|
||||||
|
// get the cid from the url format 'ipfs://bafybeicem27xbzs65uvbcgykcmscsgln3lmhbfrcoec3gdttkdgtxv5acq
|
||||||
|
if (url && url.includes('ipfs://')) {
|
||||||
|
const cid = url.split('ipfs://')[1]
|
||||||
|
return cid
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function loads the token data .
|
||||||
|
const lazyLoadTokenData = useCallback(async (tokens) => {
|
||||||
|
try {
|
||||||
|
setDataAreLoaded(false)
|
||||||
|
// map each token and fetch the token data
|
||||||
|
for (let i = 0; i < tokens.length; i++) {
|
||||||
|
const thisToken = tokens[i]
|
||||||
|
|
||||||
|
// data does not need to be downloaded, so continue with the next one
|
||||||
|
if (thisToken.dataAlreadyDownloaded) continue
|
||||||
|
|
||||||
|
// Try to get token data.
|
||||||
|
const tokenData = await appData.wallet.getTokenData(thisToken.tokenId)
|
||||||
|
console.log('tokenData', tokenData)
|
||||||
|
if (tokenData) {
|
||||||
|
// Set data to the token object , this can be used to display the token name in the token card component.
|
||||||
|
thisToken.tokenData = tokenData
|
||||||
|
thisToken.tokenId = tokenData.genesisData.tokenId
|
||||||
|
thisToken.ticker = tokenData.genesisData.ticker
|
||||||
|
thisToken.name = tokenData.genesisData.name
|
||||||
|
thisToken.decimals = tokenData.genesisData.decimals
|
||||||
|
thisToken.tokenType = tokenData.genesisData.type
|
||||||
|
thisToken.url = tokenData.genesisData.documentUri
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark token to prevent fetch token data again.
|
||||||
|
thisToken.dataAlreadyDownloaded = true
|
||||||
|
}
|
||||||
|
|
||||||
|
setDataAreLoaded(true)
|
||||||
|
} catch (error) {
|
||||||
|
setDataAreLoaded(true)
|
||||||
|
}
|
||||||
|
}, [appData])
|
||||||
|
|
||||||
|
// Fetch mutable data if it exist and get the token icon url
|
||||||
|
const fetchTokenMutableData = useCallback(async (token) => {
|
||||||
|
try {
|
||||||
|
// Get the token data
|
||||||
|
const tokenData = token.tokenData
|
||||||
|
|
||||||
|
if (!tokenData.mutableData) return false // Return false if no mutable data
|
||||||
|
|
||||||
|
// Get the token icon from the mutable data
|
||||||
|
const cid = parseCid(tokenData.mutableData)
|
||||||
|
console.log('mutable data cid', cid)
|
||||||
|
|
||||||
|
const { json } = await appData.wallet.cid2json({ cid })
|
||||||
|
console.log('json: ', json)
|
||||||
|
if (!json) return false
|
||||||
|
|
||||||
|
let iconUrl = json.tokenIcon
|
||||||
|
|
||||||
|
if (json.fullSizedUrl && json.fullSizedUrl.includes('http')) {
|
||||||
|
iconUrl = json.fullSizedUrl
|
||||||
|
}
|
||||||
|
const userData = json.userData
|
||||||
|
// Return icon url
|
||||||
|
return { iconUrl, userData }
|
||||||
|
} catch (error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}, [appData])
|
||||||
|
|
||||||
|
// This function loads the token icons from the ipfs gateways.
|
||||||
|
const lazyLoadMutableData = useCallback(async (tokens) => {
|
||||||
|
try {
|
||||||
|
setIconsAreLoaded(false)
|
||||||
|
// map each token and fetch the icon url
|
||||||
|
for (let i = 0; i < tokens.length; i++) {
|
||||||
|
const thisToken = tokens[i]
|
||||||
|
|
||||||
|
// Incon does not need to be downloaded, so continue with the next one
|
||||||
|
if (thisToken.iconAlreadyDownloaded) continue
|
||||||
|
|
||||||
|
// Try to get token icon url from mutable data.
|
||||||
|
const { iconUrl, userData } = await fetchTokenMutableData(thisToken)
|
||||||
|
console.log('iconUrl', iconUrl)
|
||||||
|
if (iconUrl) {
|
||||||
|
// Set the icon url to the token , this can be used to display the icon in the token card component.
|
||||||
|
thisToken.icon = iconUrl
|
||||||
|
thisToken.userData = userData
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark token to prevent fetch token icon again.
|
||||||
|
thisToken.iconAlreadyDownloaded = true
|
||||||
|
}
|
||||||
|
|
||||||
|
setIconsAreLoaded(true)
|
||||||
|
} catch (error) {
|
||||||
|
setIconsAreLoaded(true)
|
||||||
|
}
|
||||||
|
}, [fetchTokenMutableData])
|
||||||
|
|
||||||
|
// Load the counter offers for the current wallet.
|
||||||
|
const loadData = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
setCounterOffers([])
|
||||||
|
// Get the wallet state and server url from the app data.
|
||||||
|
const { bchWalletState, serverUrl } = appData
|
||||||
|
// Create a new AsyncLoad instance.
|
||||||
|
const asyncLoad = new AsyncLoad()
|
||||||
|
// Load the wallet library.
|
||||||
|
await asyncLoad.loadWalletLib()
|
||||||
|
// Get the counter offer derivated wallet
|
||||||
|
const counterOfferWallet = await asyncLoad.getDerivatedWallet(serverUrl, bchWalletState.mnemonic, "m/44'/245'/0'/0/1")
|
||||||
|
// Get the utxos from the counter offer wallet.
|
||||||
|
const utxos = await counterOfferWallet.getUtxos()
|
||||||
|
const bchUtxos = utxos.bchUtxos
|
||||||
|
// Get the counter offers data for the current wallet address.
|
||||||
|
const { counterOffers } = await asyncLoad.getCounterOffersByAddress(bchWalletState.cashAddress)
|
||||||
|
// Filter the counter offers to only include the ones that are in the utxos.
|
||||||
|
const filteredCounterOffers = counterOffers.filter(val =>
|
||||||
|
bchUtxos.some(utxo => utxo.txid === val.counterOfferUtxo)
|
||||||
|
)
|
||||||
|
|
||||||
|
setCounterOffers(filteredCounterOffers)
|
||||||
|
setIsLoading(false)
|
||||||
|
// Load the token data for the counter offers in background.
|
||||||
|
await lazyLoadTokenData(filteredCounterOffers)
|
||||||
|
// Load the token icons for the counter offers in background.
|
||||||
|
await lazyLoadMutableData(filteredCounterOffers)
|
||||||
|
} catch (error) {
|
||||||
|
setIsLoading(false)
|
||||||
|
console.error('Error loading counter offers:', error)
|
||||||
|
}
|
||||||
|
}, [appData, lazyLoadTokenData, lazyLoadMutableData])
|
||||||
|
|
||||||
|
// Start to load the token icons when the component is mounted
|
||||||
|
useEffect(() => {
|
||||||
|
loadData()
|
||||||
|
}, [loadData])
|
||||||
|
|
||||||
|
// Handler for refresh button
|
||||||
|
const handleRefresh = useCallback(() => {
|
||||||
|
loadData()
|
||||||
|
}, [loadData])
|
||||||
|
// Generate the token cards for each token in the wallet.
|
||||||
const generateCards = () => {
|
const generateCards = () => {
|
||||||
return counterOffers.map((offer) => (
|
return counterOffers.map(thisCounterOffer => (
|
||||||
<CounterOfferCard
|
<CounterOfferCard
|
||||||
key={offer.id}
|
|
||||||
offer={offer}
|
|
||||||
appData={appData}
|
appData={appData}
|
||||||
|
token={thisCounterOffer}
|
||||||
|
key={`${thisCounterOffer.id}`}
|
||||||
|
refreshTokens={loadData}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<Container>
|
<>
|
||||||
<Row>
|
<Container>
|
||||||
<Col>
|
<Row>
|
||||||
<h1>Counter Offers</h1>
|
<Col xs={6} style={{ textAlign: 'start' }}>
|
||||||
<p className='text-muted'>Your pending counter offers</p>
|
{!isLoading && (
|
||||||
</Col>
|
<Row>
|
||||||
</Row>
|
<Col xs={6}>
|
||||||
{isLoading
|
<Button variant='success' onClick={handleRefresh}>
|
||||||
? (
|
<FontAwesomeIcon icon={faRedo} size='lg' /> Refresh
|
||||||
<Row className='text-center' style={{ padding: '50px' }}>
|
</Button>
|
||||||
<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>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
</>
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row>
|
||||||
|
{appData.asyncInitSucceeded && (
|
||||||
|
|
||||||
|
<Col xs={12} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
||||||
|
{/** Show spinner info if tokens are loaded but data is not loaded */
|
||||||
|
isLoading && (
|
||||||
|
<div style={{ borderRadius: '10px', backgroundColor: '#f0f0f0', padding: '10px', display: 'flex', justifyContent: 'center', alignItems: 'center', width: 'fit-content' }}>
|
||||||
|
<span style={{ marginRight: '10px' }}>Loading Counter Offers </span>
|
||||||
|
<Spinner animation='border' />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{/** Show spinner info if tokens are loaded but data is not loaded */
|
||||||
|
!isLoading && !dataAreLoaded && counterOffers.length > 0 && (
|
||||||
|
<div style={{ borderRadius: '10px', backgroundColor: '#f0f0f0', padding: '10px', display: 'flex', justifyContent: 'center', alignItems: 'center', width: 'fit-content' }}>
|
||||||
|
<span style={{ marginRight: '10px' }}>Loading Token Data </span>
|
||||||
|
<Spinner animation='border' />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{/** Show spinner info if tokens are loaded but icons are not loaded */
|
||||||
|
!isLoading && dataAreLoaded && !iconsAreLoaded && (
|
||||||
|
<div style={{ borderRadius: '10px', backgroundColor: '#f0f0f0', padding: '10px', display: 'flex', justifyContent: 'center', alignItems: 'center', width: 'fit-content' }}>
|
||||||
|
<span style={{ marginRight: '10px' }}>Loading Token Icons </span>
|
||||||
|
<Spinner animation='border' />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
</Col>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Row>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
{generateCards()}
|
||||||
|
</Row>
|
||||||
|
{/** Display a message if no tokens are found */}
|
||||||
|
{!isLoading && counterOffers.length === 0 && (
|
||||||
|
<Row className='text-center'>
|
||||||
|
<span> No tokens found in wallet </span>
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</Container>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
This component renders as a button. When clicked, it opens a modal that
|
||||||
|
displays information about the token.
|
||||||
|
|
||||||
|
This is a functional component with as little state as possible.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Global npm libraries
|
||||||
|
import React, { useState, useEffect } from 'react'
|
||||||
|
import { Button, Modal, Container, Row, Col, Spinner } from 'react-bootstrap'
|
||||||
|
|
||||||
|
// Takes a string as input. If it matches a pattern for a link, a JSX object is
|
||||||
|
// returned with a link. Otherwise the original string is returned.
|
||||||
|
function linkIfUrl (url) {
|
||||||
|
// Convert the URL into a link if it contains 'http'
|
||||||
|
if (url?.includes('http')) {
|
||||||
|
url = (<a href={url} target='_blank' rel='noreferrer'>{url}</a>)
|
||||||
|
|
||||||
|
//
|
||||||
|
} else if (url?.includes('ipfs://')) {
|
||||||
|
// Convert to a Filecoin link if its an IPFS reference.
|
||||||
|
|
||||||
|
const cid = url.substring(7)
|
||||||
|
url = (<a href={`https://${cid}.ipfs.dweb.link/data.json`} target='_blank' rel='noreferrer'>{url}</a>)
|
||||||
|
}
|
||||||
|
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
function InfoButton (props) {
|
||||||
|
const [show, setShow] = useState(false)
|
||||||
|
const [mutableDataCid, setMutableDataCid] = useState(null)
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setShow(false)
|
||||||
|
// props.instance.setState({ showModal: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpen = () => {
|
||||||
|
setShow(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the url property of the token to a link, if it matches common patterns.
|
||||||
|
let url = props.token.url
|
||||||
|
url = linkIfUrl(props.token.url)
|
||||||
|
|
||||||
|
// console.log('props.token: ', props.token)
|
||||||
|
|
||||||
|
// Get Cid from url
|
||||||
|
const parseCid = (url) => {
|
||||||
|
// get the cid from the url format 'ipfs://bafybeicem27xbzs65uvbcgykcmscsgln3lmhbfrcoec3gdttkdgtxv5acq
|
||||||
|
if (url && url.includes('ipfs://')) {
|
||||||
|
const cid = url.split('ipfs://')[1]
|
||||||
|
return cid
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
// Get token user data if it exists and verify if it contains media or markdown
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
console.log('props token', props.token)
|
||||||
|
const userDataStr = props.token.userData
|
||||||
|
if (userDataStr) {
|
||||||
|
const userData = JSON.parse(userDataStr)
|
||||||
|
|
||||||
|
// If user data contains media or markdown, set the mutable data cid
|
||||||
|
if (userData?.media || userData?.markdown) {
|
||||||
|
setMutableDataCid(parseCid(props.token.tokenData.mutableData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}, [props.token, show])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button variant='info' onClick={handleOpen}>Info</Button>
|
||||||
|
<Modal show={show} onHide={handleClose}>
|
||||||
|
<Modal.Header closeButton>
|
||||||
|
<Modal.Title>Token Information</Modal.Title>
|
||||||
|
</Modal.Header>
|
||||||
|
<Modal.Body>
|
||||||
|
<Container>
|
||||||
|
<Row>
|
||||||
|
<Col xs={4}><b>Ticker</b>:</Col>
|
||||||
|
<Col xs={8}>{props.token.ticker}</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row style={{ backgroundColor: '#eee' }}>
|
||||||
|
<Col xs={4}><b>Name</b>:</Col>
|
||||||
|
<Col xs={8}>{props.token.name}</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<Col xs={4}><b>Token ID</b>:</Col>
|
||||||
|
<Col xs={8} style={{ wordBreak: 'break-all' }}>
|
||||||
|
<a href={`https://token.fullstack.cash/?tokenid=${props.token.tokenId}`} target='_blank' rel='noreferrer'>
|
||||||
|
{props.token.tokenId}
|
||||||
|
</a>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row style={{ backgroundColor: '#eee' }}>
|
||||||
|
<Col xs={4}><b>Decimals</b>:</Col>
|
||||||
|
<Col xs={8}>{props.token.decimals}</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<Col xs={4}><b>Token Type</b>:</Col>
|
||||||
|
<Col xs={8}>{props.token.tokenType}</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row style={{ backgroundColor: '#eee', wordBreak: 'break-all' }}>
|
||||||
|
<Col xs={4}><b>URL</b>:</Col>
|
||||||
|
<Col xs={8}>{url}</Col>
|
||||||
|
</Row>
|
||||||
|
{!props.token.iconAlreadyDownloaded && (
|
||||||
|
<div className='text-center'>
|
||||||
|
<Spinner animation='border' size='sm' />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{mutableDataCid && (
|
||||||
|
<Row style={{ paddingTop: '10px' }}>
|
||||||
|
<Col xs={4}><b>User Data</b>:</Col>
|
||||||
|
<Col xs={8}>
|
||||||
|
<Button
|
||||||
|
href={`/user-data/${props.token.tokenId}#single-view`}
|
||||||
|
target='_blank'
|
||||||
|
rel='noopener noreferrer'
|
||||||
|
variant='success'
|
||||||
|
>
|
||||||
|
View User Data
|
||||||
|
</Button>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
</Modal.Body>
|
||||||
|
<Modal.Footer />
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InfoButton
|
||||||
@@ -15,6 +15,10 @@ import { bytesToHex } from '@noble/hashes/utils' // already an installed depende
|
|||||||
import { getPublicKey } from 'nostr-tools/pure'
|
import { getPublicKey } from 'nostr-tools/pure'
|
||||||
import * as nip19 from 'nostr-tools/nip19'
|
import * as nip19 from 'nostr-tools/nip19'
|
||||||
|
|
||||||
|
import config from '../config'
|
||||||
|
|
||||||
|
const SERVER = `${config.dexServer}/`
|
||||||
|
|
||||||
class AsyncLoad {
|
class AsyncLoad {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.BchWallet = false
|
this.BchWallet = false
|
||||||
@@ -386,6 +390,21 @@ class AsyncLoad {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the counter offers for a given address
|
||||||
|
async getCounterOffersByAddress (addr) {
|
||||||
|
try {
|
||||||
|
const options = {
|
||||||
|
method: 'GET',
|
||||||
|
url: `${SERVER}offer/list/counter-offer/${addr}`
|
||||||
|
}
|
||||||
|
const result = await axios.request(options)
|
||||||
|
return result.data
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting counter offers by address', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep (ms) {
|
function sleep (ms) {
|
||||||
|
|||||||
Reference in New Issue
Block a user