forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44a41b3
commit 94cc724
Showing
9 changed files
with
130 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { createContext, useEffect, useState } from "react"; | ||
|
||
export const SuperheroContext = createContext<{ | ||
verifiedAccounts: Record<string, string>; | ||
}>({ | ||
verifiedAccounts: {}, | ||
}); | ||
|
||
/** | ||
* Provides the superhero context to its children components. | ||
* @param children The child components to be wrapped by the provider. | ||
* @returns The superhero provider component. | ||
*/ | ||
export const SuperheroProvider = ({ children, config }: any): any => { | ||
const [verifiedAccounts, setVerifiedAccounts] = useState<Record<string, string>>({}); | ||
|
||
function loadVerifiedAccounts(): void { | ||
fetch(`${config.bots_backend_url}/ae-wallet-bot/get-verified-accounts`, { | ||
method: "POST", | ||
}) | ||
.then((res) => res.json()) | ||
.then(setVerifiedAccounts); | ||
} | ||
|
||
useEffect(() => { | ||
loadVerifiedAccounts(); | ||
|
||
const interval = setInterval(() => { | ||
loadVerifiedAccounts(); | ||
}, 10000); | ||
|
||
return () => clearInterval(interval); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return <SuperheroContext.Provider value={{ verifiedAccounts }}>{children}</SuperheroContext.Provider>; | ||
}; |
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,24 @@ | ||
import { IPublicRoomsChunkRoom, Room } from "matrix-js-sdk/src/matrix"; | ||
import { useMemo } from "react"; | ||
|
||
/** | ||
* Determines if a room is a token gated room | ||
* @param room - The room model | ||
* @returns {boolean} true if the room is token gated | ||
*/ | ||
export function isTokenGatedRoom(room?: Room | IPublicRoomsChunkRoom): boolean { | ||
return !!room?.name?.startsWith("[TG]"); | ||
} | ||
|
||
/** | ||
* Custom hook to check if a room is verified | ||
* @param room - The room model | ||
* @returns {boolean} true if the room is verified, false otherwise | ||
*/ | ||
export function useVerifiedRoom(room?: Room | IPublicRoomsChunkRoom): boolean { | ||
const isVerifiedRoom = useMemo(() => { | ||
return isTokenGatedRoom(room); | ||
}, [room]); | ||
|
||
return isVerifiedRoom; | ||
} |
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 @@ | ||
import { useContext, useMemo } from "react"; | ||
|
||
import { SuperheroContext } from "../context/SuperheroProvider"; | ||
|
||
/** | ||
* Custom hook to check if a user is verified. | ||
* @param userId - The ID of the user to check. | ||
* @returns A boolean indicating whether the user is verified or not. | ||
*/ | ||
export function useVerifiedUser(userId?: string): boolean { | ||
const { verifiedAccounts } = useContext(SuperheroContext); | ||
|
||
const isVerifiedUser: boolean = useMemo(() => { | ||
return !!(userId && !!verifiedAccounts[userId]); | ||
}, [userId, verifiedAccounts]); | ||
|
||
return isVerifiedUser; | ||
} |
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