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

feat: Build item slots #1664

Merged
merged 23 commits into from
Nov 15, 2021
Merged

feat: Build item slots #1664

merged 23 commits into from
Nov 15, 2021

Conversation

LautaroPetaccio
Copy link
Contributor

@LautaroPetaccio LautaroPetaccio commented Nov 10, 2021

This PR adds the BuyItemSlotsModal with the required module to buy slots and attaches it to the ThirdPartyCollectionDetailPage.

Screen Shot 2021-11-12 at 14 54 00

Screen Shot 2021-11-12 at 17 42 59

Screen Shot 2021-11-10 at 14 41 29

Screen Shot 2021-11-12 at 14 52 45

Closes #1573

@vercel
Copy link

vercel bot commented Nov 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/decentraland/builder/DZGEUs6BSUgGwcgkjL45JHdYDq2j
✅ Preview: https://builder-git-feat-build-item-slots-decentraland1.vercel.app

@coveralls
Copy link

coveralls commented Nov 10, 2021

Pull Request Test Coverage Report for Build 1463278570

  • 96 of 132 (72.73%) changed or added relevant lines in 21 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.8%) to 13.56%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Modals/index.ts 0 1 0.0%
src/components/ThirdPartyCollectionDetailPage/ThirdPartyCollectionDetailPage.container.ts 0 1 0.0%
src/modules/collection/selectors.ts 0 1 0.0%
src/modules/common/reducer.ts 0 1 0.0%
src/modules/common/sagas.ts 0 1 0.0%
src/modules/tiers/sagas.ts 23 24 95.83%
src/components/Modals/BuyItemSlotsModal/index.ts 0 2 0.0%
src/lib/api/builder.ts 0 2 0.0%
src/modules/tiers/reducer.ts 11 13 84.62%
src/modules/wallet/selectors.ts 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/components/ThirdPartyCollectionDetailPage/ThirdPartyCollectionDetailPage.container.ts 1 0%
Totals Coverage Status
Change from base Build 1444327292: 0.8%
Covered Lines: 1479
Relevant Lines: 9814

💛 - Coveralls

const { wallet, collection } = this.props
return collection !== null && canSeeCollection(collection, wallet.address)
const { wallet, collection, thirdParty } = this.props
return collection && thirdParty && isUserManagerOfThirdParty(wallet.address, thirdParty)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is enough to verify that the user has access to the collection. What do you think about this @nicosantangelo ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup I think it's ok!

Copy link
Contributor

@nicosantangelo nicosantangelo left a comment

Choose a reason for hiding this comment

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

Things I've noticed using the UI:

  1. The loading indicator is too close to the text, which makes it a bit jarring when the data eventually appears

Screen Shot 2021-11-11 at 14 17 43

  1. The "you don't have enough MANA notice has more padding at the bottom that at the top which makes it a bit weird. Also, there seem to be two spaces between the MANA symbol and MANA

Screen Shot 2021-11-11 at 14 17 43

  1. The same described above happens with the error message. Furthermore, picking a new slot does not clean the error and there's no X to do it either which can be confusing.

Screen Shot 2021-11-11 at 14 17 43

Screen Shot 2021-11-11 at 14 17 43

  1. MINOR or NOT necessary: Maybe we can align the MANA symbols vertically?:

Screen Shot 2021-11-11 at 14 17 43

Comment on lines 4 to 11
import { Button, ModalDescription, ModalHeader, CheckboxProps, Radio, Mana, Loader, Message } from 'decentraland-ui'
import { T, t } from 'decentraland-dapps/dist/modules/translation/utils'
import { Modal, NetworkButton } from 'decentraland-dapps/dist/containers'
import { env } from 'decentraland-commons'
import { Props } from './BuyItemSlotsModal.types'
import { Network } from '@dcl/schemas'
import { ThirdPartyItemTier } from 'modules/tiers/types'
import styles from './BuyItemSlotsModal.module.css'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we order these? At lest to leave the remote imports at the top

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 13 to 20
const sortTiers = (a: ThirdPartyItemTier, b: ThirdPartyItemTier) => {
if (a.value < b.value) {
return -1
} else if (a.value > b.value) {
return 1
}
return 0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this live in modules/tiers/utils?
I see that we're doing the same with sortLandPoolLast so maybe it's not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved it to modules/tiers/utils. I left it there because it was the only place that it was going to be used.
I also added tests for it.

onFetchThirdPartyItemSlots: typeof fetchThirdPartyItemTiersRequest
manaBalance: number
tiers: ThirdPartyItemTier[]
metadata: { thirdParty: ThirdParty }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for consistency sake, could we extract this to it's own type? on the same file. Like this:

export type Props = ModalProps & {
  metadata: ShareModalMetadata
(...)
}

export type ShareModalMetadata = {
  type: ShareModalType
  id: string
}

And if you want to keep the callbacks (on(...)) at the end, that's peachy too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the callbacks at the end and created the Metadata type!

const collection = this.props.collection!
const slots = 0
const slots = thirdParty ? new BN(thirdParty.maxItems).sub(new BN(thirdParty.totalItems)) : new BN(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be a candidate for a utils method? like getCurrentSlots(thirdParty)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved it and tested it.

@@ -14,6 +15,7 @@ import CollectionPublishButton from './CollectionPublishButton'
import { Props } from './ThirdPartyCollectionDetailPage.types'

import './ThirdPartyCollectionDetailPage.css'
import { isUserManagerOfThirdParty } from 'modules/thirdParty/utils'
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't mind, Could we move this a few lines below the other module imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

error: null
}

type ThirdPartyReducerAction =
Copy link
Contributor

Choose a reason for hiding this comment

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

TiersReducerAction !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


const INITIAL_STATE: TiersState = {
data: {
thirdParty: []
Copy link
Contributor

Choose a reason for hiding this comment

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

Just making sure, this property is here so we can, in the future, add tiers to other parts of the state right?

I ask mostly because it's called thirdParty but not thirdPartyItems when the type is ThirdPartyItemTier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is set like that for the purpose you've mentioned.
You're right, it should be called thirdPartyItems as it defines the tiers of the items in a more proper way.

import { FETCH_THIRD_PARTY_ITEM_TIERS_REQUEST, BUY_THIRD_PARTY_ITEM_TIERS_SUCCESS, BUY_THIRD_PARTY_ITEM_TIERS_REQUEST } from './actions'
import { ThirdPartyItemTier, TiersState } from './types'

function getState(state: RootState): TiersState {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really mind this, but if you want, we could change this file to use constants

export const getState (...)

so it looks like all the other selectors in the codebase/other dapps.

Following that path, we can keep consistent and add the four selectors we have in all files:

export const getState = (state: RootState) => state.item
export const getData = (state: RootState) => getState(state).data
export const getLoading = (state: RootState) => getState(state).loading
export const getError = (state: RootState) => getState(state).error

which'd allow for not having to do .data below too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're using lambdas in all of our other selectors, so I don't mind at all! Changed.

Comment on lines 4 to 8
export function getManaBalance(state: RootState): number {
const wallet = getWallet(state)

return wallet ? wallet.networks.MATIC.mana : 0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful here, this method is misleading. There's no one mana balance, it always should depend on the network. Furthermore, decentraland dapps already has a getNetworks which can be accessed by network to get the mana balance (deprecating this selector)
I think we can just use getNetworks where this selector is used and pass Netowrk.MATIC if necessary

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 took this section of code from here.
Can't we have something like getManaBalanceForNetwork(state:RootState, network: Network)? Because as far as I'm aware (I might be mistaken), the contract will live in the MATIC network. This also opens the window for the the question "should we should this modal at all if we're on another network that's not MATIC?" because we could disable the "Buy slots" button in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created the getManaBalanceForNetwork(state:RootState, network: Network) method!

tsconfig.json Outdated
Comment on lines 14 to 20
"noUnusedLocals": false,
"isolatedModules": true,
"esModuleInterop": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"resolveJsonModule": true,
"noUnusedParameters": true,
"noUnusedParameters": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

but-why

After seeing this I've opened BuyItemSlotsModal.container.ts and saw that Dispatch is imported and not being used :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, I removed it to make the development a bit faster but I forgot about re-adding it again.

Copy link
Contributor

@nicosantangelo nicosantangelo left a comment

Choose a reason for hiding this comment

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

Minor comments, but great work

@@ -0,0 +1,8 @@
import { Network } from '@dcl/schemas'
import { RootState } from 'modules/common/types'
import { getNetworks } from 'decentraland-dapps/dist/modules/wallet/selectors'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this a line above 👉👈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

tsconfig.json Outdated
@@ -11,7 +11,7 @@
"skipLibCheck": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedLocals": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

👓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to the value it had before.

render() {
const { onClose, isFetchingTiers, name, isBuyingItemSlots, tiers, error } = this.props
const { selectedTierId } = this.state
console.log('Starting this shit')
Copy link
Contributor

Choose a reason for hiding this comment

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

👁️ . 👁️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ups, removed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buy Item slots
3 participants