-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 [QA] Update release environment (#721)
This is a pull request that upon merging will update production environment with recent `stage-live` changes. The environment that will be updated: * Production: https://taho-development.netlify.app/ (aka https://app.taho.xyz/) Read more: [Deployment to Production Flow](https://github.com/tahowallet/dapp/blob/main/docs/testing-env.md)
- Loading branch information
Showing
21 changed files
with
860 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"server": "./src/shared/utils/reflect.ts", | ||
"apps": { | ||
"default": { | ||
"appID": "loztnkex" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export * from "./wallets" | ||
export * from "./assistant" | ||
export * from "./helpers" | ||
export * from "./island" | ||
export * from "./transactions" | ||
export * from "./assistant" | ||
export * from "./reflect" | ||
export * from "./tenderly" | ||
export * from "./transactions" | ||
export * from "./wallets" | ||
export * from "./population" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { useEffect, useState } from "react" | ||
import { | ||
selectDisplayedRealmId, | ||
selectRealmNameById, | ||
selectStakingRealmId, | ||
selectWalletName, | ||
useDappSelector, | ||
} from "redux-state" | ||
import { usePresence, useSubscribe } from "@rocicorp/reflect/react" | ||
import { getClientState, reflectInstance } from "shared/utils" | ||
import { getRealmMapData } from "shared/constants" | ||
import { RootState } from "redux-state/reducers" | ||
|
||
export function useReflect() { | ||
const name = useDappSelector(selectWalletName) | ||
const stakingRealmId = useDappSelector(selectStakingRealmId) | ||
const realmName = | ||
useDappSelector((state: RootState) => | ||
selectRealmNameById(state, stakingRealmId) | ||
) ?? null | ||
|
||
const realmMapData = stakingRealmId ? getRealmMapData(stakingRealmId) : null | ||
|
||
const [reflectInitialized, setReflectInitialized] = useState(false) | ||
|
||
const stakingRealmColor = realmMapData?.color ?? "#2C2C2C" | ||
const cursorTextColor = realmMapData?.cursorText ?? "#FFF" | ||
|
||
useEffect(() => { | ||
const initReflect = async () => { | ||
if (reflectInitialized || !reflectInstance) return | ||
|
||
await reflectInstance.mutate.initClientState({ | ||
id: reflectInstance.clientID, | ||
cursor: null, | ||
userInfo: { | ||
name, | ||
realmName, | ||
stakingRealmColor, | ||
cursorTextColor, | ||
}, | ||
isPresent: true, | ||
}) | ||
|
||
setReflectInitialized(true) | ||
} | ||
|
||
const updateUserInfo = async () => { | ||
if (!reflectInstance) return | ||
|
||
await reflectInstance.mutate.setUserInfo({ | ||
name, | ||
realmName, | ||
stakingRealmColor, | ||
cursorTextColor, | ||
}) | ||
} | ||
|
||
initReflect() | ||
updateUserInfo() | ||
}, [reflectInitialized, name, realmName, stakingRealmColor, cursorTextColor]) | ||
|
||
useEffect(() => { | ||
const handleReflectCursor = async (e: MouseEvent) => { | ||
if (!reflectInstance) return | ||
|
||
await reflectInstance.mutate.setCursor({ x: e.clientX, y: e.clientY }) | ||
} | ||
|
||
window.addEventListener("mousemove", handleReflectCursor) | ||
return () => window.removeEventListener("mousemove", handleReflectCursor) | ||
}, []) | ||
} | ||
|
||
export function useReflectPresence() { | ||
const presentClientsdIds = usePresence(reflectInstance) | ||
const presentClients = useSubscribe( | ||
reflectInstance, | ||
async (tx) => { | ||
const clients = await Promise.all( | ||
presentClientsdIds.map(async (clientID) => { | ||
const presentClient = await getClientState(tx, clientID) | ||
return presentClient ? [presentClient] : [] | ||
}) | ||
) | ||
|
||
return clients | ||
.flatMap((client) => client) | ||
.filter((client) => client.isPresent) | ||
}, | ||
[], | ||
[presentClientsdIds] | ||
) | ||
|
||
return presentClients | ||
} | ||
|
||
export function useReflectCurrentUser() { | ||
return useSubscribe( | ||
reflectInstance, | ||
async (tx) => { | ||
const currentUser = await getClientState(tx, tx.clientID) | ||
return currentUser | ||
}, | ||
null | ||
) | ||
} | ||
|
||
export function useReflectCursors() { | ||
useReflect() | ||
|
||
const reflectClients = useReflectPresence() | ||
const currentUser = useReflectCurrentUser() | ||
const realmModalOpened = useDappSelector(selectDisplayedRealmId) | ||
|
||
// Find index of current user to determine the "room" placement | ||
const currentUserIndex = reflectClients.findIndex( | ||
(client) => client.id === currentUser?.id | ||
) | ||
|
||
// Set max number of visible cursors in .env (or default to 5) | ||
const maxNumberOfVisibleCursors = | ||
Number(process.env.REFLECT_MAX_CAPACITY) || 5 | ||
|
||
const currentUserRoom = Math.floor( | ||
currentUserIndex / maxNumberOfVisibleCursors | ||
) | ||
|
||
const currentRoomValue = currentUserRoom * maxNumberOfVisibleCursors | ||
|
||
// We want users to always have a chance to interact with each other so we split them | ||
// into "rooms" based on their index in the reflectClients array. This way map stays interactive | ||
// while still being not overcrowded. | ||
const visibleClients = reflectClients.slice( | ||
currentRoomValue, | ||
currentRoomValue + maxNumberOfVisibleCursors | ||
) | ||
|
||
// Hide current user cursor when the realm modal is opened | ||
return !realmModalOpened | ||
? visibleClients | ||
: visibleClients.filter((client) => client.id !== currentUser?.id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as TransactionService } from "./transaction" | ||
export { default as StorageService } from "./storage" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type ReflectCursor = { | ||
x: number | ||
y: number | ||
} | ||
|
||
export type ReflectUserInfo = { | ||
name: string | ||
realmName: string | null | ||
stakingRealmColor: string | ||
cursorTextColor: string | ||
} | ||
|
||
export type ReflectClient = { | ||
id: string | ||
cursor: ReflectCursor | null | ||
userInfo: ReflectUserInfo | ||
isPresent: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.