Skip to content

Commit

Permalink
🪄 [QA] Update stage environments (#631)
Browse files Browse the repository at this point in the history
This is a pull request that upon merging will update stage environments
with recent `main` changes.
The environments that will be updated:
* Stage live: https://stage-live--taho-development.netlify.app/
* Stage fork: https://stage-fork--taho-development.netlify.app/

Read more: [Deployment to Production
Flow](https://github.com/tahowallet/dapp/blob/main/docs/testing-env.md)
  • Loading branch information
andreachapman authored Nov 6, 2023
2 parents 44e93e4 + acd399e commit 6de8a48
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 329 deletions.
9 changes: 8 additions & 1 deletion src/redux-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ export * from "./slices/wallet"
export * from "./slices/island"

export * from "./selectors/claim"
export * from "./selectors/wallet"
export * from "./selectors/island"
export * from "./selectors/leaderboard"
export * from "./selectors/population"
export * from "./selectors/realm"
export * from "./selectors/season"
export * from "./selectors/staking"
export * from "./selectors/token"
export * from "./selectors/wallet"
export * from "./selectors/xp"
20 changes: 20 additions & 0 deletions src/redux-state/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createSelector } from "@reduxjs/toolkit"
import {
CreateIslandSelector,
CreateClaimSelector,
CreateWalletSelector,
} from "shared/types/selectors"
import { RootState } from "./reducers"

export const selectIsland = (state: RootState) => state.island
export const selectClaim = (state: RootState) => state.claim
export const selectWallet = (state: RootState) => state.wallet

export const createIslandSelector: CreateIslandSelector = (value) =>
createSelector(selectIsland, (island) => island[value])

export const createClaimSelector: CreateClaimSelector = (value) =>
createSelector(selectClaim, (claim) => claim[value])

export const createWalletSelector: CreateWalletSelector = (value) =>
createSelector(selectWallet, (wallet) => wallet[value])
43 changes: 17 additions & 26 deletions src/redux-state/selectors/claim.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import { createSelector } from "@reduxjs/toolkit"
import { RootState } from "redux-state/reducers"
import { truncateAddress } from "shared/utils"
import { RealmData } from "shared/types"
import { selectRealmById } from "./island"
import { createClaimSelector } from "redux-state/selectors"

export const selectClaimingUser = (state: RootState) => ({
name: state.claim.name || truncateAddress(state.claim.address),
address: state.claim.address,
})

export const selectHasClaimed = (state: RootState) => state.claim.hasClaimed

export const selectEligibility = (state: RootState) => state.claim.eligibility

export const selectUseConnectedWalletToClaim = (state: RootState) =>
state.claim.useConnectedWallet

export const selectStakingData = createSelector(
(state: RootState) => selectRealmById(state, state.claim.selectedRealmId),
(state: RootState) => state.claim.stakeAmount,
(realmData: RealmData | null, stakeAmount) => ({
realmContractAddress: realmData ? realmData.realmContractAddress : null,
stakeAmount,
})
export const selectHasClaimed = createClaimSelector("hasClaimed")
export const selectEligibility = createClaimSelector("eligibility")
export const selectRealmId = createClaimSelector("selectedRealmId")
export const selectClaimingStakeAmount = createClaimSelector("stakeAmount")
export const selectClaimAdress = createClaimSelector("address")
export const selectClaimName = createClaimSelector("name")
export const selectUseConnectedWalletToClaim =
createClaimSelector("useConnectedWallet")
export const selectRepresentativeAddress = createClaimSelector(
"representativeAddress"
)
export const selectClaimingSelectedRealmId =
createClaimSelector("selectedRealmId")

export const selectRepresentativeAddress = (state: RootState) =>
state.claim.representativeAddress

export const selectRealmId = (state: RootState) => state.claim.selectedRealmId
export const selectClaimingUser = (state: RootState) => ({
name: selectClaimName(state) || truncateAddress(selectClaimAdress(state)),
address: selectClaimAdress(state),
})
216 changes: 9 additions & 207 deletions src/redux-state/selectors/island.ts
Original file line number Diff line number Diff line change
@@ -1,211 +1,13 @@
import { createSelector } from "@reduxjs/toolkit"
import { RootState } from "redux-state/reducers"
import { DAY } from "shared/constants"
import { isSameAddress } from "shared/utils"
import { createIslandSelector } from "redux-state/selectors"
import { IslandModeType } from "redux-state/slices/island"

export const selectIslandMode = (state: RootState) => state.island.mode
export const selectIslandMode = createIslandSelector("mode")
export const selectIslandOverlay = createIslandSelector("overlay")
export const selectIslandZoomLevel = createIslandSelector("zoomLevel")

export const selectIsDefaultIslandMode = (state: RootState) =>
state.island.mode === "default"
const checkIslandMode = (value: IslandModeType) =>
createSelector(selectIslandMode, (mode) => mode === value)

export const selectIsJoinRealmIslandMode = (state: RootState) =>
state.island.mode === "join-realm"

export const selectIslandOverlay = (state: RootState) => state.island.overlay

export const selectRealms = (state: RootState) => state.island.realms

export const selectRealmById = createSelector(
[selectRealms, (_, realmId: string | null) => realmId],
(realms, realmId) => (realmId ? realms[realmId] : null)
)

export const selectRealmNameById = createSelector(
[selectRealms, (_, realmId: string | null) => realmId],
(realms, realmId) => (realmId ? realms[realmId].name : null)
)

export const selectRealmWithIdByAddress = createSelector(
[selectRealms, (_, realmAddress: string) => realmAddress],
(realms, realmAddress) =>
Object.entries(realms).find(([_, { realmContractAddress }]) =>
isSameAddress(realmContractAddress, realmAddress)
)
)

export const selectHasLoadedRealmData = createSelector(
selectRealms,
(realms) => Object.keys(realms).length !== 0
)

export const selectHasLoadedSeasonInfo = createSelector(
(state: RootState) => state.island.seasonInfo,
(seasonInfo) => seasonInfo !== null
)

/* Season info - selectors */
export const selectSeasonStartTimestamp = (state: RootState) =>
state.island.seasonInfo?.seasonStartTimestamp

export const selectSeasonEndTimestamp = (state: RootState) =>
state.island.seasonInfo?.seasonEndTimestamp

export const selectSeasonDurationInWeeks = (state: RootState) =>
state.island.seasonInfo?.durationInWeeks

export const selectIsEndOfSeason = createSelector(
selectSeasonEndTimestamp,
(seasonEndTimestamp) => {
if (seasonEndTimestamp) {
return Date.now() > seasonEndTimestamp
}
return null
}
)

export const selectSeasonWeek = createSelector(
selectSeasonStartTimestamp,
selectIsEndOfSeason,
selectSeasonDurationInWeeks,
(seasonStartTimestamp, isEndOfSeason, durationInWeeks) => {
if (isEndOfSeason) return durationInWeeks

if (seasonStartTimestamp && durationInWeeks) {
const hasSeasonStarted = seasonStartTimestamp < Date.now()
if (!hasSeasonStarted) return 1 // if the start date is placed in the future, set season week to 1

return Math.trunc((Date.now() - seasonStartTimestamp) / (7 * DAY) + 1)
}

return null
}
)

export const selectWeekStartDate = createSelector(
selectSeasonStartTimestamp,
selectSeasonWeek,
(seasonStartTimestamp, seasonWeek) => {
if (seasonStartTimestamp && seasonWeek) {
const startDate = new Date(seasonStartTimestamp)
startDate.setDate(startDate.getDate() + (seasonWeek - 1) * 7)
return startDate
}
return null
}
)

export const selectWeekEndDate = createSelector(
selectWeekStartDate,
(startDate) => {
if (!startDate) return null

const endDate = new Date(startDate)
endDate.setDate(startDate.getDate() + 6)
return endDate
}
)

/* Displayed Realm - selectors */
export const selectDisplayedRealmId = (state: RootState) =>
state.island.displayedRealmId

export const selectDisplayedRealmAddress = createSelector(
selectRealms,
selectDisplayedRealmId,
(realms, realmId) => realmId && realms[realmId]?.realmContractAddress
)

export const selectDisplayedRealmVeTokenAddress = createSelector(
selectRealms,
selectDisplayedRealmId,
(realms, realmId) => realmId && realms[realmId]?.veTokenContractAddress
)

/* Staking Realm - selectors */
export const selectStakingRealmId = (state: RootState) =>
state.island.stakingRealmId

export const selectStakingRealmAddress = createSelector(
selectRealms,
selectStakingRealmId,
(realms, stakingRealmId) =>
stakingRealmId && realms[stakingRealmId]?.realmContractAddress
)

/* Xp selectors */
export const selectLeaderboards = (state: RootState) =>
state.island.leaderboards

export const selectUnclaimedXp = (state: RootState) => state.island.unclaimedXp

const selectLeaderboardDataById = createSelector(
[(_, realmId: string) => realmId, selectLeaderboards],
(realmId, leaderboards) => leaderboards[realmId]
)

export const selectLeaderboardById = createSelector(
selectLeaderboardDataById,
(leaderboardData) => leaderboardData?.leaderboard ?? []
)

export const selectUserLeaderboardRankById = createSelector(
selectLeaderboardDataById,
(leaderboardData) => leaderboardData?.currentUser ?? null
)

export const selectUnclaimedXpById = createSelector(
[(_, realmId: string) => realmId, selectUnclaimedXp],
(realmId, unclaimedXp) => unclaimedXp[realmId]
)

export const selectUnclaimedXpSumById = createSelector(
[selectUnclaimedXpById],
(unclaimedXp) =>
unclaimedXp?.reduce((acc, item) => acc + BigInt(item.claim.amount), 0n) ??
0n
)
/* Population - selectors */
export const selectSortedPopulation = createSelector(selectRealms, (realms) => {
const realmsData = Object.entries(realms).map(([id, data]) => ({
id,
...data,
}))

const sortedRealms = realmsData.sort((a, b) => a.population - b.population)
return sortedRealms
})

export const selectPopulationById = createSelector(
selectRealmById,
(realm) => realm?.population ?? 0
)

export const selectTotalPopulation = createSelector(
selectSortedPopulation,
(realms) =>
realms.length
? realms.map((realm) => realm.population).reduce((a, b) => a + b)
: 0
)

export const selectMaxPopulation = createSelector(
selectSortedPopulation,
(realms) =>
realms.length ? Math.max(...realms.map((realm) => realm.population)) : 0
)

/* Helpful selectors */
export const selectIsStakingRealmDisplayed = createSelector(
selectStakingRealmAddress,
selectDisplayedRealmAddress,
(stakingAddress, displayedAddress) =>
!!stakingAddress &&
!!displayedAddress &&
isSameAddress(stakingAddress, displayedAddress)
)

export const selectStakeUnlockTime = (state: RootState) =>
state.island.stakeUnlockTime

export const selectIslandZoomLevel = (state: RootState) =>
state.island.zoomLevel
export const selectIsDefaultIslandMode = checkIslandMode("default")
export const selectIsJoinRealmIslandMode = checkIslandMode("join-realm")
19 changes: 19 additions & 0 deletions src/redux-state/selectors/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createSelector } from "@reduxjs/toolkit"
import { createIslandSelector } from "redux-state/selectors"

export const selectLeaderboards = createIslandSelector("leaderboards")

const selectLeaderboardDataById = createSelector(
[(_, realmId: string) => realmId, selectLeaderboards],
(realmId, leaderboards) => leaderboards[realmId]
)

export const selectLeaderboardById = createSelector(
selectLeaderboardDataById,
(leaderboardData) => leaderboardData?.leaderboard ?? []
)

export const selectUserLeaderboardRankById = createSelector(
selectLeaderboardDataById,
(leaderboardData) => leaderboardData?.currentUser ?? null
)
31 changes: 31 additions & 0 deletions src/redux-state/selectors/population.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createSelector } from "@reduxjs/toolkit"
import { RealmData } from "shared/types"
import { selectRealmById, selectRealms } from "./realm"

const getPopulationOfRealms = (realms: RealmData[]) =>
realms.map((realm) => realm.population)

export const selectSortedPopulation = createSelector(selectRealms, (realms) => {
const realmsData = Object.entries(realms).map(([id, data]) => ({
id,
...data,
}))

return realmsData.sort((a, b) => a.population - b.population)
})

export const selectPopulationById = createSelector(
selectRealmById,
(realm) => realm?.population ?? 0
)

export const selectTotalPopulation = createSelector(
selectSortedPopulation,
(realms) =>
realms.length ? getPopulationOfRealms(realms).reduce((a, b) => a + b) : 0
)

export const selectMaxPopulation = createSelector(
selectSortedPopulation,
(realms) => (realms.length ? Math.max(...getPopulationOfRealms(realms)) : 0)
)
Loading

0 comments on commit 6de8a48

Please sign in to comment.