Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total sold vs available widget #2898

Merged
merged 14 commits into from
Nov 27, 2021

Conversation

chinins
Copy link
Contributor

@chinins chinins commented Nov 16, 2021

Description

This PR adds total sold vs. available widget and adds some updates to tokens display in the remaining widget.

New stuff

  • add new widget & corresponding queries
  • add react-textfit package
  • add updated numbers formatting

TODO

  • the numbers in sold vs. available widgets should go into 2 lines when they hit 10px - this is now done! :)

Screenshot 2021-11-23 at 14 12 18

Resolves #2868

@chinins chinins self-assigned this Nov 16, 2021
@chinins chinins marked this pull request as draft November 16, 2021 20:29
@chinins chinins changed the base branch from master to feature/coin-machine-redux November 16, 2021 20:29
@rdig rdig force-pushed the feature/coin-machine-redux branch from 9e79a65 to 9cc7853 Compare November 17, 2021 18:46
@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from 6d1c360 to b5d4612 Compare November 18, 2021 11:38
Base automatically changed from feature/coin-machine-redux to master November 18, 2021 12:52
@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from 444e848 to c1a32c3 Compare November 22, 2021 12:11
@chinins chinins requested a review from a team November 23, 2021 13:14
@chinins chinins marked this pull request as ready for review November 23, 2021 13:14
@chinins chinins marked this pull request as draft November 23, 2021 13:21
@chinins chinins marked this pull request as ready for review November 23, 2021 15:29
@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from 85fa442 to dec86a0 Compare November 23, 2021 15:33
Copy link
Contributor

@ArmandoGraterol ArmandoGraterol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like how it looks and the new info is quite useful when testing the coin machine. Surely it's also gonna be useful for normal users.

When I enter the coin machine I'm seeing some warnings on the console:
Screenshot from 2021-11-23 20-06-53

Can you check them out?

@arrenv
Copy link
Member

arrenv commented Nov 24, 2021

Looks like the perfectFit property was dropped - See reference: https://github.com/malte-wessel/react-textfit/blob/fc7aa18e61a2397fcef838dc8b16c8dc027dce26/CHANGELOG.md#v100

Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be working well.

tokens-available

tokens-available-big-size

@chinins
Copy link
Contributor Author

chinins commented Nov 25, 2021

@ArmandoGraterol, it's a leftover prop I forgot to remove - thank you for spotting it! It should be all good now - without any warning.

Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working well, without the error now for me!

@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from 7f453ac to ec2406e Compare November 25, 2021 15:09
Copy link
Contributor

@ArmandoGraterol ArmandoGraterol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, from what I've tested it's working as expected and without warnings! Good job

@chinins
Copy link
Contributor Author

chinins commented Nov 25, 2021

@ArmandoGraterol , @arrenv , can you please review my latest commit and test again?

I have added the dynamic switching to 2 lines when the font-size reaches 10px.

@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from f089125 to 9ba1bbf Compare November 25, 2021 18:29
Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, the split line looks to be working well.

number-newline-1

number-newline-3

number-newline-4

number-newline-2

Copy link
Contributor

@ArmandoGraterol ArmandoGraterol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiline seems to be working as expected!

FireShot Capture 499 - Colony - localhost

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on putting this PR together. Very nice work! 💯

There still is a issue in here. (but which was inherited from the previous iteration)

If the coin machine has less tokens that the batch available, it will still show the batch as having available the "max" allowed, even though the coin machine doesn't have them anymore.

I'll show you some pictures since it's easier to explain.

Screenshot from 2021-11-26 01-18-49

In here, there are only 10 tokens available in the coin machine (which the "Total sold v. available correctly shows -- 70/80), the buy widget correctly only allows you to buy 10 (notice the error), but the "Batch sold v. available" widget still shows 0 / 40 which is incorrect in this case as there are only 10 tokens left. It should show 0 / 10.

Notice, that if I pass the period, the previous batches table shows the period, correctly, as having just 0 / 10

Screenshot from 2021-11-26 01-19-03

Comment on lines 284 to 305
tokenClient.filters.Transfer(null, coinMachineClient.address, null),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very expensive, but I guess it's what we have to do in order to fetch the token transfers into the coin machine.

However, you can filter it even more, by only fetching blocks from the time the current instance of the coin machine was installed.

See this for an example:

const subgraphData = await apolloClient.query<
SubgraphCoinMachinePeriodsQuery,
SubgraphCoinMachinePeriodsQueryVariables
>({
query: SubgraphCoinMachinePeriodsDocument,
variables: {
colonyAddress: colonyAddress.toLowerCase(),
extensionAddress: coinMachineClient.address.toLowerCase(),
limit,
},
fetchPolicy: 'network-only',
});
const [extensionInitialised] = (
subgraphData?.data?.extensionInitialisedEvents || []
).map(parseSubgraphEvent);
/*
* We use the `FromChain` suffix to make these events more easily
* recognizable when reading the code
*/
const transferLogsFromChain = await getLogs(
tokenClient,
tokenClient.filters.Transfer(null, coinMachineClient.address, null),
{
fromBlock: extensionInitialised?.blockNumber,
},
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough - done now.

@@ -201,7 +201,7 @@ const BuyTokens = ({
const getFormattedCost = useCallback(
(amount) => {
const decimalCost = new Decimal(amount)
.times(salePriceData.coinMachineCurrentPeriodPrice)
.times(salePriceData?.coinMachineCurrentPeriodPrice || '0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this actually be OR 1, because if you multiply by 0, you'll always get 0, but if you multiply by 1 you'll just get the amount.

Depends on what you want the fallback to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default value should be 0. If it's 0 it will give an indication that something is off more that if it defaults to 1.... But I am happy to hear a counter-argument

@@ -311,6 +346,7 @@ const CoinMachine = ({
}}
sellableToken={sellableToken}
purchaseToken={purchaseToken}
periodTokens={periodTokens}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really that you put the period tokens back in here, as I worked really hard to refactor this so that it expressly doesn't use this specific value as it's not quite optimized.

However, I do understand why it's here, because you had to move the "Price next batch" display into the table.

I really don't like this, but this is a side-effect of just refactoring design willy nilly, you end up with content you need to move around, and you just slap it somewhere....

(sorry for the rant :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why it's so bad as I just moved the Price next batch logic from one component to another and added one prop to TokenSalesTable...
I am happy to discuss this & refactor once I understand the ideal state you would like to see.

Copy link
Contributor Author

@chinins chinins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdig updated the PR. Not sure about your comment regarding the periodTokens prop passing, other than that it's ready for re-review.

@@ -311,6 +346,7 @@ const CoinMachine = ({
}}
sellableToken={sellableToken}
purchaseToken={purchaseToken}
periodTokens={periodTokens}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why it's so bad as I just moved the Price next batch logic from one component to another and added one prop to TokenSalesTable...
I am happy to discuss this & refactor once I understand the ideal state you would like to see.

Comment on lines 284 to 305
tokenClient.filters.Transfer(null, coinMachineClient.address, null),
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough - done now.

@@ -201,7 +201,7 @@ const BuyTokens = ({
const getFormattedCost = useCallback(
(amount) => {
const decimalCost = new Decimal(amount)
.times(salePriceData.coinMachineCurrentPeriodPrice)
.times(salePriceData?.coinMachineCurrentPeriodPrice || '0')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default value should be 0. If it's 0 it will give an indication that something is off more that if it defaults to 1.... But I am happy to hear a counter-argument

@chinins chinins force-pushed the feature/2868-add-total-sold-vs-available-widget branch from b807101 to 272a49e Compare November 26, 2021 17:55
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as expected now. Very nice turnaround. 🥇

Screenshot from 2021-11-26 22-11-56

On Monday I'll put it up on QA

@chinins chinins merged commit 4c8c017 into master Nov 27, 2021
@chinins chinins deleted the feature/2868-add-total-sold-vs-available-widget branch November 27, 2021 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Total sold / available" section to Coin Machine.
4 participants