bch-consumer
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -266,4 +266,38 @@ /* | ||
} | ||
/** | ||
* @api bch.getTokenData2() getTokenData2() | ||
* @apiName getTokenData2 | ||
* @apiGroup BCH | ||
* @apiDescription Get PS007 token icon and other media | ||
* | ||
* Arguments: | ||
* - tokenId - (required) string containing token ID | ||
* | ||
* @apiExample {js} Example usage: | ||
* (async () => { | ||
* try { | ||
* const tokenId = 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d' | ||
* const tokenData = await bchConsumer.bch.getTokenData2(tokenId) | ||
* console.log(tokenData) | ||
* } catch(error) { | ||
* console.error(error) | ||
* } | ||
* })() | ||
* | ||
*/ | ||
async getTokenData2 (tokenId) { | ||
const body = { | ||
tokenId | ||
} | ||
const result = await this.axios.post(`${this.restURL}/bch/getTokenData2`, body) | ||
// console.log( | ||
// `result.data.txData: ${JSON.stringify(result.data.txData, null, 2)}` | ||
// ) | ||
return result.data | ||
} | ||
} | ||
module.exports = BCH |
{ | ||
"name": "bch-consumer", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A npm JS library for interacting with ipfs-bch-wallet-consumer REST API", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@psf/bch-js": "6.4.5", | ||
"@psf/bch-js": "6.5.1", | ||
"apidoc": "0.51.0", | ||
@@ -37,0 +37,0 @@ "axios": "0.25.0" |
@@ -217,2 +217,25 @@ /* | ||
}) | ||
describe('#getTokenData2', () => { | ||
it('should get PS002 data from a valid token', async () => { | ||
const tokenId = 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d' | ||
const result = await uut.getTokenData2(tokenId) | ||
// console.log(`result: ${JSON.stringify(result, null, 2)}`) | ||
assert.equal(result.success, true) | ||
assert.equal(result.status, 200) | ||
assert.equal(result.endpoint, 'getTokenData2') | ||
assert.property(result.tokenData, 'tokenStats') | ||
assert.property(result.tokenData, 'mutableData') | ||
assert.property(result.tokenData, 'immutableData') | ||
assert.property(result.tokenData, 'tokenIcon') | ||
assert.property(result.tokenData, 'fullSizedUrl') | ||
assert.property(result.tokenData, 'optimizedTokenIcon') | ||
assert.property(result.tokenData, 'optimizedFullSizedUrl') | ||
assert.property(result.tokenData, 'iconRepoCompatible') | ||
assert.property(result.tokenData, 'ps002Compatible') | ||
}) | ||
}) | ||
}) |
@@ -247,2 +247,33 @@ /* | ||
}) | ||
describe('#getTokenData2', () => { | ||
it('should pass data to REST API', async () => { | ||
const tokenId = 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d' | ||
// Mock dependency | ||
sandbox.stub(uut.axios, 'post').resolves({ data: { a: 'b' } }) | ||
const result = await uut.getTokenData2(tokenId) | ||
assert.equal(result.a, 'b') | ||
}) | ||
it('should throw an error if axios throws an error', async () => { | ||
// Force an error | ||
sandbox.stub(uut.axios, 'post').rejects(new Error('test error')) | ||
try { | ||
const tokenId = 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d' | ||
await uut.getTokenData2(tokenId) | ||
assert.fail('Unexpected code path') | ||
} catch (err) { | ||
assert.equal( | ||
err.message, | ||
'test error' | ||
) | ||
} | ||
}) | ||
}) | ||
}) |
39303
1011
+ Added@psf/bch-js@6.5.1(transitive)
- Removed@psf/bch-js@6.4.5(transitive)
Updated@psf/bch-js@6.5.1