mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-22 01:02:06 -07:00
Merge pull request #1 from FullStack-cash/ct-unstable
fix(tokens): Adding new method for token icon lookup
This commit is contained in:
Generated
+108
-5948
File diff suppressed because it is too large
Load Diff
+1
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "fullstack-gatsby-theme-bch-wallet",
|
||||
"description": "A GatsbyJS Theme with AdminLTE integration and basic Bitcoin Cash wallet functionality.",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"main": "index.js",
|
||||
"author": "Chris Troutner <chris.troutner@gmail.com>",
|
||||
"contributors": [
|
||||
@@ -56,7 +56,6 @@
|
||||
"react-redux": "7.2.4",
|
||||
"semver": "7.3.5",
|
||||
"sharp": "0.29.3",
|
||||
"slp-mutable-data": "1.5.1",
|
||||
"stream-browserify": "3.0.0",
|
||||
"stream-http": "3.2.0"
|
||||
},
|
||||
@@ -67,7 +66,6 @@
|
||||
"eslint-plugin-prettier": "3.3.1",
|
||||
"eslint-plugin-standard": "5.0.0",
|
||||
"husky": "4.3.8",
|
||||
"mocha": "9.1.3",
|
||||
"prettier": "2.2.1",
|
||||
"semantic-release": "17.3.7",
|
||||
"standard": "16.0.3"
|
||||
|
||||
@@ -6,8 +6,11 @@ import TokenModal from './token-modal'
|
||||
import Spinner from '../../../images/loader.gif'
|
||||
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import SendTokens from './send-tokens'
|
||||
import { SlpMutableData } from 'slp-mutable-data'
|
||||
// import { SlpMutableData } from 'slp-mutable-data'
|
||||
import axios from 'axios'
|
||||
|
||||
let _this
|
||||
|
||||
class Tokens extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
@@ -270,15 +273,34 @@ 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()
|
||||
// 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)}`)
|
||||
// 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.
|
||||
const mutableData = await axios.get(`https://${mutableCid}.ipfs.dweb.link/data.json`)
|
||||
token.mutableData = mutableData.data
|
||||
// console.log('token.mutableData: ', token.mutableData)
|
||||
|
||||
// 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
|
||||
|
||||
@@ -7,7 +7,6 @@ import ImportWallet from './import'
|
||||
import NewWallet from './create'
|
||||
import InfoWallets from './info'
|
||||
import WalletInfo from './wallet-info'
|
||||
import { interfaces } from 'mocha'
|
||||
|
||||
let _this
|
||||
class Wallet extends React.Component {
|
||||
@@ -36,7 +35,6 @@ class Wallet extends React.Component {
|
||||
setWalletInfo={_this.props.setWalletInfo}
|
||||
setBchWallet={_this.props.setBchWallet}
|
||||
walletInfo={_this.props.walletInfo}
|
||||
interface={_this.props.interface}
|
||||
|
||||
/>
|
||||
|
||||
@@ -45,7 +43,6 @@ class Wallet extends React.Component {
|
||||
setWalletInfo={_this.props.setWalletInfo}
|
||||
setBchWallet={_this.props.setBchWallet}
|
||||
walletInfo={_this.props.walletInfo}
|
||||
interface={_this.props.interface}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
@@ -60,8 +57,7 @@ Wallet.propTypes = {
|
||||
setWalletInfo: PropTypes.func.isRequired,
|
||||
walletInfo: PropTypes.object.isRequired,
|
||||
updateBalance: PropTypes.func.isRequired,
|
||||
setBchWallet: PropTypes.func.isRequired,
|
||||
interface :PropTypes.string
|
||||
setBchWallet: PropTypes.func.isRequired
|
||||
}
|
||||
|
||||
export default Wallet
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Unit tests for the retry-queue library.
|
||||
*/
|
||||
|
||||
import chai from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// const BCHJS = require('@psf/bch-js')
|
||||
import RetryQueue from '../../src/lib/retry-queue.mjs'
|
||||
|
||||
const assert = chai.assert
|
||||
|
||||
// const bchjs = new BCHJS()
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
describe('#retry-queue.js', () => {
|
||||
beforeEach(() => {
|
||||
uut = new RetryQueue()
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#_retryWrapper', () => {
|
||||
it('should throw an error if function handler is not provided', async () => {
|
||||
try {
|
||||
await uut.retryWrapper()
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'function handler is required')
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw an error if input object is not provided', async () => {
|
||||
try {
|
||||
const funcHandler = () => {}
|
||||
await uut.retryWrapper(funcHandler)
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'input object is required')
|
||||
}
|
||||
})
|
||||
|
||||
it('should execute the given function.', async () => {
|
||||
const inputTest = 'test'
|
||||
// func mock to execute into the retry wrapper
|
||||
const funcHandle = sinon.spy()
|
||||
|
||||
await uut.retryWrapper(funcHandle, inputTest)
|
||||
|
||||
assert.equal(inputTest, funcHandle.getCall(0).args[0])
|
||||
assert.equal(funcHandle.callCount, 1)
|
||||
})
|
||||
|
||||
it('should call handleValidationError() when p-retry error is thrown', async () => {
|
||||
try {
|
||||
// Mock for ignore sleep time
|
||||
sandbox.stub(uut, 'sleep').resolves({})
|
||||
|
||||
const inputTest = 'test'
|
||||
const funcHandle = () => {
|
||||
throw new Error('test error')
|
||||
}
|
||||
uut.attempts = 1
|
||||
|
||||
await uut.retryWrapper(funcHandle, inputTest)
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
|
||||
it('should retry the specific number of times before giving up', async () => {
|
||||
// Mock for ignore sleep time
|
||||
sandbox.stub(uut, 'sleep').resolves({})
|
||||
|
||||
const inputTest = 'test'
|
||||
const funcHandle = () => {
|
||||
throw new Error('test error')
|
||||
}
|
||||
// func handler
|
||||
const spy = sinon.spy(funcHandle)
|
||||
|
||||
// p-retry attempts
|
||||
const attempts = 1
|
||||
|
||||
try {
|
||||
uut.attempts = attempts
|
||||
|
||||
await uut.retryWrapper(spy, inputTest)
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (error) {
|
||||
assert.equal(spy.callCount, attempts + 1)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#addToQueue', () => {
|
||||
it('should throw an error if function handler is not provided', async () => {
|
||||
try {
|
||||
await uut.addToQueue()
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'function handler is required')
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw an error if input object is not provided', async () => {
|
||||
try {
|
||||
const funcHandler = () => {}
|
||||
|
||||
await uut.addToQueue(funcHandler)
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'input object is required')
|
||||
}
|
||||
})
|
||||
|
||||
it('should add a function and input object to the queue and execute them', async () => {
|
||||
const inputTest = 'test'
|
||||
// func mock to execute into the retry wrapper
|
||||
const funcHandle = sinon.spy()
|
||||
|
||||
await uut.addToQueue(funcHandle, inputTest)
|
||||
|
||||
assert.equal(inputTest, funcHandle.getCall(0).args[0])
|
||||
assert.equal(funcHandle.callCount, 1)
|
||||
})
|
||||
|
||||
it('should catch and throw an error', async () => {
|
||||
try {
|
||||
// Mock for ignore sleep time
|
||||
sandbox.stub(uut, 'sleep').resolves({})
|
||||
|
||||
const inputTest = 'test'
|
||||
|
||||
const funcHandle = () => {
|
||||
throw new Error('test error')
|
||||
}
|
||||
|
||||
uut.attempts = 1
|
||||
await uut.retryWrapper(funcHandle, inputTest)
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'test error')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#handleValidationError', () => {
|
||||
it('should catch and throw an error', async () => {
|
||||
try {
|
||||
await uut.handleValidationError()
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
assert.include(err.message, 'Cannot read property')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user