TokenScript icon indicating copy to clipboard operation
TokenScript copied to clipboard

Need an elegant way to get what action you are in

Open JamesANZ opened this issue 6 years ago • 2 comments

Problem: When creating a TokenScript that has multiple actions, sometimes you need to know what action you are in so that you can serve unique content. At the moment it is not possible to do this from this.props

Possible solution: Enable this.props.action.name to return it's name which can then be mapped back to the context of the action you are currently in.

Having to create separate SHTML files for each action just to fulfill this seems bad.

JamesANZ avatar Sep 16 '19 12:09 JamesANZ

Good suggestion. @hboon can you tell if Sangalli's suggested additional API is not brittle?

P.S. I didn't label this as Schema because it's about API.

SmartLayer avatar Sep 16 '19 13:09 SmartLayer

@colourful-land sounds useful. Should action be considered part of the context? Then we can have:

web3.tokens.context.currentAction.name

or:

web3.tokens.actions.currentAction.name

(The latter supports adding web3.tokens.actions.all in the future)

This:

web3.tokens.dataChanged = (oldTokens, updatedTokens) => {
    const currentTokenInstance = web3.tokens.data.currentInstance;
    document.getElementById('root').innerHTML = new Token(currentTokenInstance).render();
};

becomes:

web3.tokens.dataChanged = (oldTokens, updatedTokens) => {
    const currentTokenInstance = web3.tokens.data.currentInstance;
    const actionName = web3.tokens.context.currentAction.name;
    //or: const actionName = web3.tokens.actions.currentAction.name;
    document.getElementById('root').innerHTML = new Token(currentTokenInstance, actionName).render();
};

hboon avatar Feb 12 '20 05:02 hboon