mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
feat(slp): Added slp-mutable-data to gatsby-web-wallet
This commit is contained in:
Generated
+5977
-5978
File diff suppressed because it is too large
Load Diff
@@ -51,6 +51,8 @@
|
|||||||
"react-qr-reader": "^2.2.1",
|
"react-qr-reader": "^2.2.1",
|
||||||
"react-redux": "^7.2.4",
|
"react-redux": "^7.2.4",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
|
"sharp": "^0.29.3",
|
||||||
|
"slp-mutable-data": "^1.2.2",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"stream-http": "^3.2.0"
|
"stream-http": "^3.2.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import TokenModal from './token-modal'
|
|||||||
import Spinner from '../../../images/loader.gif'
|
import Spinner from '../../../images/loader.gif'
|
||||||
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import SendTokens from './send-tokens'
|
import SendTokens from './send-tokens'
|
||||||
|
import { SlpMutableData } from 'slp-mutable-data'
|
||||||
let _this
|
let _this
|
||||||
class Tokens extends React.Component {
|
class Tokens extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -161,9 +161,10 @@ class Tokens extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
tokens = await bchWallet.listTokens()
|
tokens = await bchWallet.listTokens()
|
||||||
}
|
}
|
||||||
|
const mutableTokens = await _this.handleMutableData(tokens)
|
||||||
|
|
||||||
_this.setState({
|
_this.setState({
|
||||||
tokens,
|
tokens: mutableTokens,
|
||||||
inFetch: false
|
inFetch: false
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -171,7 +172,7 @@ class Tokens extends React.Component {
|
|||||||
throw new Error('No tokens found on this wallet.')
|
throw new Error('No tokens found on this wallet.')
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.props.setTokensInfo(tokens)
|
_this.props.setTokensInfo(mutableTokens)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
_this.handleError(error)
|
_this.handleError(error)
|
||||||
}
|
}
|
||||||
@@ -264,6 +265,30 @@ class Tokens extends React.Component {
|
|||||||
explorerURL
|
explorerURL
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try to get mutable data from token id
|
||||||
|
async handleMutableData (tokensArr) {
|
||||||
|
try {
|
||||||
|
const tokens = []
|
||||||
|
const slpMutableLib = new SlpMutableData()
|
||||||
|
for (let i = 0; i < tokensArr.length; i++) {
|
||||||
|
const token = tokensArr[i]
|
||||||
|
try {
|
||||||
|
const data = await slpMutableLib.get.mutableData(token.tokenId)
|
||||||
|
token.mutableData = data
|
||||||
|
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(error)
|
||||||
|
// Skip error
|
||||||
|
}
|
||||||
|
tokens.push(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Tokens.propTypes = {
|
Tokens.propTypes = {
|
||||||
walletInfo: PropTypes.object.isRequired, // wallet info
|
walletInfo: PropTypes.object.isRequired, // wallet info
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class TokenCard extends React.Component {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
const token = _this.props.token
|
const token = _this.props.token
|
||||||
|
const mutableData = token.mutableData
|
||||||
// console.log(`token: ${JSON.stringify(token, null, 2)}`)
|
// console.log(`token: ${JSON.stringify(token, null, 2)}`)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -20,7 +21,7 @@ class TokenCard extends React.Component {
|
|||||||
<Box className='hover-shadow border-none mt-2' id='token-card'>
|
<Box className='hover-shadow border-none mt-2' id='token-card'>
|
||||||
<Row className='text-center'>
|
<Row className='text-center'>
|
||||||
<Col sm={12} className='text-center mt-2 '>
|
<Col sm={12} className='text-center mt-2 '>
|
||||||
<Jdenticon size='100' value={token.tokenId} />
|
{mutableData && mutableData.tokenIcon ? <img className='mutable-img' src={mutableData.tokenIcon} width={100} /> : <Jdenticon size='100' value={token.tokenId} />}
|
||||||
<hr />
|
<hr />
|
||||||
</Col>
|
</Col>
|
||||||
<Col sm={12} className='flex justify-content-center '>
|
<Col sm={12} className='flex justify-content-center '>
|
||||||
|
|||||||
@@ -105,3 +105,6 @@
|
|||||||
.nopadding{
|
.nopadding{
|
||||||
padding: 0!important;
|
padding: 0!important;
|
||||||
}
|
}
|
||||||
|
.mutable-img{
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user