Skip to content

Commit

Permalink
fix: getColors should accept two optional params (#145)
Browse files Browse the repository at this point in the history
* fix: getColors should accept two optional params

* rework to support 'type' params, return all if no params given
  • Loading branch information
troggy authored Sep 6, 2019
1 parent 36d6959 commit 2d11adb
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export function extendWeb3(web3Instance) {
outputFormatter: Number,
}),
new extend.Method({
name: 'getColors',
name: '_getColors',
call: 'plasma_getColors',
params: 0,
inputFormatters: [],
params: 2,
inputFormatters: [a => a, a => a],
outputFormatter: String,
}),
new extend.Method({
Expand Down Expand Up @@ -133,6 +133,28 @@ export function extendWeb3(web3Instance) {
web3Instance.getUnspent = (...params) =>
web3Instance._getUnspent(...paddedParams(params)); // eslint-disable-line no-underscore-dangle

/* eslint-disable no-underscore-dangle */
web3Instance.getColors = (type) => {
const typeStr = (type || '').toLowerCase();
if (typeStr === 'erc721' || typeStr === 'nft') {
return web3Instance._getColors(true, null);
}
if (typeStr === 'erc1948' || type === 'nst') {
return web3Instance._getColors(false, true);
}

if (typeStr === 'erc20') {
return web3Instance._getColors(false, false);
}

return Promise.all([
web3Instance._getColors(false, false),
web3Instance._getColors(true, false),
web3Instance._getColors(false, true),
]).then(([erc20, erc721, erc1948]) => ({ erc20, erc721, erc1948 }));
}
/* eslint-enable no-underscore-dangle */

return web3Instance;
}

Expand Down

0 comments on commit 2d11adb

Please sign in to comment.