mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
Merge pull request #18 from Permissionless-Software-Foundation/ct-unstable
fix(tokens): Adding support for mutable token data, including icons
This commit is contained in:
Binary file not shown.
Generated
+2380
-1264
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -42,6 +42,7 @@
|
||||
"gatsby-source-filesystem": "4.7.0",
|
||||
"gatsby-transformer-sharp": "4.7.0",
|
||||
"https-browserify": "1.0.0",
|
||||
"is-ipfs": "6.0.2",
|
||||
"jsonrpc-lite": "2.2.0",
|
||||
"p-queue": "7.2.0",
|
||||
"p-retry": "5.0.0",
|
||||
@@ -57,7 +58,7 @@
|
||||
"react-redux": "7.2.6",
|
||||
"semver": "7.3.5",
|
||||
"sharp": "0.30.1",
|
||||
"slp-mutable-data": "1.4.2",
|
||||
"slp-mutable-data": "1.8.1",
|
||||
"stream-browserify": "3.0.0",
|
||||
"stream-http": "3.2.0"
|
||||
},
|
||||
|
||||
@@ -7,7 +7,13 @@ import Spinner from '../../../images/loader.gif'
|
||||
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import SendTokens from './send-tokens'
|
||||
// import { SlpMutableData } from 'slp-mutable-data'
|
||||
import axios from 'axios'
|
||||
|
||||
const isIpfs = require('is-ipfs')
|
||||
|
||||
|
||||
let _this
|
||||
|
||||
class Tokens extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
@@ -270,22 +276,46 @@ class Tokens extends React.Component {
|
||||
// try to get mutable data from token id
|
||||
async handleMutableData (tokensArr) {
|
||||
try {
|
||||
const bchWalletLib = _this.props.bchWallet
|
||||
const bchjs = bchWalletLib.bchjs
|
||||
|
||||
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
|
||||
// console.log(
|
||||
// `Could not access mutable data for ${token.ticker} (${token.tokenId})`
|
||||
// )
|
||||
// }
|
||||
|
||||
try {
|
||||
// Get token data from bch-api.
|
||||
const tokenData = await bchjs.PsfSlpIndexer.getTokenData(token.tokenId)
|
||||
// console.log(`tokenData ${i}: ${JSON.stringify(tokenData, null, 2)}`)
|
||||
|
||||
// Extract the raw CID.
|
||||
const immutableCid = tokenData.immutableData.slice(7)
|
||||
const mutableCid = tokenData.mutableData.slice(7)
|
||||
// console.log(`immutableCid: ${immutableCid}`)
|
||||
// console.log(`mutableCid: ${mutableCid}`)
|
||||
|
||||
// Get mutable data from Filecoin.
|
||||
if (isIpfs.cid(mutableCid)) {
|
||||
const mutableData = await axios.get(`https://${mutableCid}.ipfs.dweb.link/data.json`)
|
||||
token.mutableData = mutableData.data
|
||||
// console.log('token.mutableData: ', token.mutableData)
|
||||
}
|
||||
|
||||
if (isIpfs.cid(immutableCid)) {
|
||||
// Get immutable data from Filecoin.
|
||||
const immutableData = await axios.get(`https://${immutableCid}.ipfs.dweb.link/data.json`)
|
||||
token.immutableData = immutableData.data
|
||||
// console.log('token.immutableData: ', token.immutableData)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
// Skip error
|
||||
console.log(
|
||||
`Could not access mutable data for ${token.ticker} (${token.tokenId})`
|
||||
)
|
||||
}
|
||||
|
||||
tokens.push(token)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user