SmartTokenLabs / tokenscript-engine

A JavaScript library for embedding tokenscript functionality in applications.
Other
2 stars 1 forks source link

Supporting negative numbers in RHS of selection expression #33

Open hboon opened 2 months ago

hboon commented 2 months ago

I was adding a dummy selection so it can be used to trigger early-loading that attribute (points). So I wrote this:

<ts:selection name="dummyForcePointsToLoadAlwaysFalse" filter="points>-1">

But the expression parsing code at https://github.com/SmartTokenLabs/tokenscript-engine/blob/0db404a54c692c2bafe7bdbc0beb97f2d376764f/javascript/engine-js/src/tokenScript/selection/SelectionFilter.ts#L19 doesn't handle negative numbers on the RHS.

const matches = filter.match(/([a-zA-Z0-9]*)([=<>]*)([a-zA-Z0-9]*)/);

It'll assign an empty string to conditionValue.

It's a uint though, so I'm not sure we'll ever have negative numbers, or will we?

micwallace commented 1 week ago

@hboon I've added full support for the conditionals using the implementation from AW iOS, so this is likely fixed.

What was the purpose of loading this attribute before a card is opened? Did you want to display this value somewhere else in the UI?

Maybe we could add a preload XML attribute onto ts:attribute that tells the engine to reload attributes where preload="true".

hboon commented 1 week ago

What was the purpose of loading this attribute before a card is opened? Did you want to display this value somewhere else in the UI?

@micwallace it's so that when we click on the "i"/Information button the attribute value is available. Without the selection hack, the value isn't available until a card using it is displayed.

hboon commented 1 week ago

Maybe we could add a preload XML attribute onto ts:attribute that tells the engine to reload attributes where preload="true".

Yeah, that would be useful.