Skip to content

Commit

Permalink
Merge branch 'main' into badges
Browse files Browse the repository at this point in the history
  • Loading branch information
jagodarybacka authored Oct 20, 2023
2 parents 9d51973 + 3d0f375 commit 8155034
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "shared/hooks"
import LiquidityPool from "ui/LiquidityPool"
import {
selectHasLoadedBalances,
selectHasLoadedRealmData,
selectHasLoadedSeasonInfo,
selectIslandMode,
Expand All @@ -40,12 +41,13 @@ function DApp() {

const hasLoadedRealmData = useDappSelector(selectHasLoadedRealmData)
const hasLoadedSeasonInfo = useDappSelector(selectHasLoadedSeasonInfo)
const hasBalances = useDappSelector(selectHasLoadedBalances)

useWallet()
useGameLoadDataFetch()
useBalanceFetch()
useWalletChange()
useGameDataFetch()
useWalletChange()

return (
<>
Expand All @@ -56,7 +58,7 @@ function DApp() {
{walletOnboarded && isConnected && (
<>
<FullPageLoader
loaded={hasLoadedRealmData && hasLoadedSeasonInfo}
loaded={hasLoadedRealmData && hasLoadedSeasonInfo && hasBalances}
/>
<IslandComponent />
<TestingPanel />
Expand Down
10 changes: 8 additions & 2 deletions src/redux-state/slices/island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,24 @@ const islandSlice = createSlice({
) => {
immerState.seasonInfo = seasonInfo
},
resetIsland: (immerState) => {
resetIslandDisplay: (immerState) => {
immerState.mode = "default"
immerState.overlay = "dark"
},
resetIslandAccount: (immerState) => {
immerState.stakingRealmId = null
immerState.stakeUnlockTime = null
immerState.unclaimedXp = {}
},
},
})

export const {
setIslandMode,
setIslandOverlay,
setIslandZoomLevel,
resetIsland,
resetIslandDisplay,
resetIslandAccount,
setRealmPopulation,
setRealmXpAllocatable,
setRealmsData,
Expand Down
8 changes: 5 additions & 3 deletions src/redux-state/slices/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const walletSlice = createSlice({
immerState.name = payload.name || immerState.name || ""
immerState.avatar = payload.avatar || immerState.avatar || portrait
},
updateDisconnectedWallet: () => initialState,
resetWalletState: () => initialState,
updateBalances: (
immerState,
{ payload: balances }: { payload: TokenBalances }
Expand All @@ -57,7 +57,9 @@ const walletSlice = createSlice({
...immerState.balances,
...balances,
}
immerState.hasLoadedBalances = true
// First we are getting balances of ETH and TAHO, then veTAHO - to consider
// balances as fully loaded we need to know veTAHO as well
immerState.hasLoadedBalances = Object.keys(immerState.balances).length > 2
},
resetBalances: (immerState) => {
immerState.balances = initialState.balances
Expand Down Expand Up @@ -85,7 +87,7 @@ const walletSlice = createSlice({

export const {
updateConnectedWallet,
updateDisconnectedWallet,
resetWalletState,
updateBalances,
resetBalances,
updateTransactionStatus,
Expand Down
32 changes: 22 additions & 10 deletions src/redux-state/thunks/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { resolveAddressToName } from "shared/utils"
import {
updateBalances,
updateConnectedWallet,
updateDisconnectedWallet,
resetWalletState,
} from "redux-state/slices/wallet"
import { resetClaiming, setClaimingUser } from "redux-state/slices/claim"
import { getBalance, getStakeUnlockTime } from "shared/contracts"
import { ethers } from "ethers"
import { ETH_ADDRESS, SECOND, TAHO_ADDRESS } from "shared/constants"
import { TokenBalances } from "shared/types"
import {
resetIslandAccount,
resetIslandDisplay,
setStakingRealmId,
setStakingUnlockTime,
} from "redux-state/slices/island"
Expand Down Expand Up @@ -55,6 +57,17 @@ export const connectArbitrumProvider = createDappAsyncThunk(
}
)

export const prepareForWalletChange = createDappAsyncThunk(
"wallet/prepareForWalletChange",
async (_, { dispatch }) => {
// reseting whole thing, with balances
dispatch(resetWalletState())
dispatch(resetIslandDisplay())
dispatch(resetIslandAccount())
dispatch(resetClaiming())
}
)

export const connectWalletGlobally = createDappAsyncThunk(
"wallet/connectWalletGlobally",
async (
Expand All @@ -75,6 +88,8 @@ export const connectWalletGlobally = createDappAsyncThunk(

await transactionService.setArbitrumSigner(arbitrumSigner)

dispatch(prepareForWalletChange())

dispatch(
updateConnectedWallet({
address,
Expand All @@ -91,18 +106,15 @@ export const connectWalletGlobally = createDappAsyncThunk(

export const disconnectWalletGlobally = createDappAsyncThunk(
"wallet/disconnectWalletGlobally",
async (_, { dispatch, getState, extra: { transactionService } }) => {
const {
claim: { useConnectedWallet },
} = getState()

async (_, { dispatch, extra: { transactionService } }) => {
await transactionService.setArbitrumSigner(null)

dispatch(updateDisconnectedWallet())
dispatch(prepareForWalletChange())

if (useConnectedWallet) {
dispatch(resetClaiming())
}
// TODO: stale, fix it once we are back to claiming
// if (useConnectedWallet) {
// dispatch(resetClaiming())
// }
}
)

Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/RealmModal/RealmModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "redux-state"
import classNames from "classnames"
import { useHistory } from "react-router-dom"
import { resetIsland } from "redux-state/slices/island"
import { resetIslandDisplay } from "redux-state/slices/island"
import { setSelectedRealmId } from "redux-state/slices/claim"
import { ROUTES } from "shared/constants"
import RealmHeader from "./RealmHeader"
Expand All @@ -31,7 +31,7 @@ export default function RealmModalContent({

const handleClose = () => {
onClose()
dispatch(resetIsland())
dispatch(resetIslandDisplay())
dispatch(setSelectedRealmId(realmId))
location.push(ROUTES.CLAIM.DETAILS_SIGN)
}
Expand Down
8 changes: 1 addition & 7 deletions src/shared/hooks/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
selectWalletAddress,
fetchWalletBalances,
resetBalances,
resetIsland,
resetClaiming,
connectArbitrumProvider,
selectDisplayedRealmId,
} from "redux-state"
Expand Down Expand Up @@ -135,7 +133,7 @@ export function useConnect() {
return { isConnected: !!wallet, connect, disconnect: disconnectBound }
}

// Hook is invoked when user switches accounts
// Hook is invoked after user switched accounts
export function useWalletChange() {
const dispatch = useDappDispatch()

Expand All @@ -154,10 +152,6 @@ export function useWalletChange() {
}

if (address !== currentAddress) {
dispatch(resetBalances())
dispatch(resetIsland())
dispatch(resetClaiming())

updateWalletOnboarding("")

if (!assistant && !isStaked) {
Expand Down

0 comments on commit 8155034

Please sign in to comment.