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

resolve circular dependencies #1414

Merged
merged 13 commits into from
Jul 29, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useGuild from "components/[guild]/hooks/useGuild"
import useShowErrorToast from "hooks/useShowErrorToast"
import { SignedValidation, useSubmitWithSign } from "hooks/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import useToast from "hooks/useToast"
import fetcher from "utils/fetcher"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AccessCheckJob, JoinJob } from "@guildxyz/types"
import useGuild from "components/[guild]/hooks/useGuild"
import useMembership from "components/explorer/hooks/useMembership"
import { useFetcherWithSign } from "hooks/useFetcherWithSign"
import { UseSubmitOptions } from "hooks/useSubmit/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import { atom, useAtom } from "jotai"
import useSWRImmutable from "swr/immutable"
import { groupBy } from "../utils/mapAccessJobState"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { env } from "env"
import { useFetcherWithSign } from "hooks/useFetcherWithSign"
import usePopupWindow from "hooks/usePopupWindow"
import useSubmit, { SignedValidation, useSubmitWithSign } from "hooks/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import { useSetAtom } from "jotai"
import { OAuthResultParams } from "pages/oauth-result"
import { useCallback, useMemo } from "react"
Expand Down
4 changes: 2 additions & 2 deletions src/components/[guild]/JoinModal/hooks/useJoin.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JoinJob } from "@guildxyz/types"
import { CircleWavyCheck } from "@phosphor-icons/react"
import { GUILD_PIN_MAINTENANCE } from "components/[guild]/Requirements/components/GuildCheckout/MintGuildPin/MintGuildPin"
import { GUILD_PIN_MAINTENANCE } from "components/[guild]/Requirements/components/GuildCheckout/MintGuildPin/constants"
import { useMintGuildPinContext } from "components/[guild]/Requirements/components/GuildCheckout/MintGuildPinContext"
import useGuild from "components/[guild]/hooks/useGuild"
import useUser from "components/[guild]/hooks/useUser"
import { UseSubmitOptions } from "hooks/useSubmit/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import { useToastWithButton, useToastWithTweetButton } from "hooks/useToast"
import { useRouter } from "next/router"
import { useState } from "react"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useMembership from "components/explorer/hooks/useMembership"
import useCustomPosthogEvents from "hooks/useCustomPosthogEvents"
import { useFetcherWithSign } from "hooks/useFetcherWithSign"
import useSubmit from "hooks/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/useSubmit"
import { UseSubmitOptions } from "hooks/useSubmit/types"
import { atom, useAtom } from "jotai"
import useUsersPoints from "rewards/Points/useUsersPoints"
import getGuildPlatformsOfRoles from "../utils/getGuildPlatformsOfRoles"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Modal } from "components/common/Modal"
import { useMintGuildPinContext } from "../../MintGuildPinContext"
import AlphaTag from "../../components/AlphaTag"
import GuildPinImage from "../../components/GuildPinImage"
import { GUILD_PIN_MAINTENANCE } from "../MintGuildPin"
import { GUILD_PIN_MAINTENANCE } from "../constants"
import FuelGuildPinFees from "./FuelGuildPinFees"
import MintFuelGuildPinButton from "./MintFuelGuildPinButton"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import TransactionStatusModal from "../components/TransactionStatusModal"
import GuildPinOpenseaLink from "../components/TransactionStatusModal/components/GuildPinOpenseaLink"
import MintGuildPinButton from "../components/buttons/MintGuildPinButton"
import SwitchNetworkButton from "../components/buttons/SwitchNetworkButton"

export const GUILD_PIN_MAINTENANCE = false
import { GUILD_PIN_MAINTENANCE } from "./constants"

const DynamicActivateGuildPinModal = dynamic(
() => import("./components/ActivateGuildPinModal")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GUILD_PIN_MAINTENANCE = false
25 changes: 3 additions & 22 deletions src/components/lexical/plugins/ToolbarPlugin/ToolbarPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
$createQuoteNode,
$isHeadingNode,
} from "@lexical/rich-text"
import { $isAtNodeEnd, $wrapNodes } from "@lexical/selection"
import { $wrapNodes } from "@lexical/selection"
import { $getNearestNodeOfType, mergeRegister } from "@lexical/utils"
import {
ArrowClockwise,
Expand Down Expand Up @@ -56,8 +56,8 @@ import {
import { useCallback, useEffect, useRef, useState } from "react"
import ImageEditor from "./components/ImageEditor"
import LinkEditor from "./components/LinkEditor"

export const LOW_PRIORITY = 1
import { LOW_PRIORITY } from "./constants"
import { getSelectedNode } from "./utils"

const supportedBlockTypes = [
"paragraph",
Expand Down Expand Up @@ -94,25 +94,6 @@ const blockTypeToBlockIcon: Record<
code: Code,
}

export const getSelectedNode = (selection) => {
const anchor = selection.anchor
const focus = selection.focus
const anchorNode = selection.anchor.getNode()
const focusNode = selection.focus.getNode()

if (anchorNode === focusNode) {
return anchorNode
}

const isBackward = selection.isBackward()

if (isBackward) {
return $isAtNodeEnd(focus) ? anchorNode : focusNode
} else {
return $isAtNodeEnd(anchor) ? focusNode : anchorNode
}
}

const BlockOptionsMenuList = ({
editor,
blockType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND } from "lexi
import { useCallback, useEffect, useRef, useState } from "react"
import { FormProvider, useForm } from "react-hook-form"
import { ensureUrlProtocol } from "utils/ensureUrlProtocol"
import { LOW_PRIORITY, getSelectedNode } from "../ToolbarPlugin"
import { LOW_PRIORITY } from "../constants"
import { getSelectedNode } from "../utils"

type LinkEditorProps = {
isOpen: boolean
Expand Down
1 change: 1 addition & 0 deletions src/components/lexical/plugins/ToolbarPlugin/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LOW_PRIORITY = 1
20 changes: 20 additions & 0 deletions src/components/lexical/plugins/ToolbarPlugin/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { $isAtNodeEnd } from "@lexical/selection"

export const getSelectedNode = (selection) => {
const anchor = selection.anchor
const focus = selection.focus
const anchorNode = selection.anchor.getNode()
const focusNode = selection.focus.getNode()

if (anchorNode === focusNode) {
return anchorNode
}

const isBackward = selection.isBackward()

if (isBackward) {
return $isAtNodeEnd(focus) ? anchorNode : focusNode
} else {
return $isAtNodeEnd(anchor) ? focusNode : anchorNode
}
}
2 changes: 1 addition & 1 deletion src/hooks/useSetKeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StoredKeyPair, setKeyPairToIdb } from "utils/keyPair"
import { recaptchaAtom, shouldUseReCAPTCHAAtom } from "utils/recaptcha"
import { checksumAddress } from "viem"
import useSubmit from "./useSubmit"
import { MessageParams, SignProps, UseSubmitOptions } from "./useSubmit/useSubmit"
import { MessageParams, SignProps, UseSubmitOptions } from "./useSubmit/types"

function getSiweMessage({
addr,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSubmit/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEFAULT_MESSAGE = "Please sign this message"
export const DEFAULT_SIGN_LOADING_TEXT = "Check your wallet"
4 changes: 2 additions & 2 deletions src/hooks/useSubmit/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default, sign, useSubmitWithSign } from "./useSubmit"
export type { SignedValidation, Validation } from "./useSubmit"
export { default, useSubmitWithSign } from "./useSubmit"
export type { SignedValidation, Validation } from "./types"
46 changes: 46 additions & 0 deletions src/hooks/useSubmit/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Account } from "fuels"
import { ValidationMethod } from "types"
import { PublicClient, WalletClient } from "viem"

type SignBaseProps = {
address: `0x${string}`
payload: string
chainId?: string
forcePrompt: boolean
keyPair?: CryptoKeyPair
msg?: string
ts?: number
getMessageToSign?: (params: MessageParams) => string
}

export type SignProps = SignBaseProps & {
publicClient: PublicClient
walletClient: WalletClient
}

export type FuelSignProps = SignBaseProps & { wallet: Account }

export type SignedValidation = { signedPayload: string; validation: Validation }

export type Validation = {
params: MessageParams
sig: string
}

export type MessageParams = {
msg: string
addr: string
method: ValidationMethod
chainId?: string
hash?: string
nonce: string
ts: string
}

export type UseSubmitOptions<ResponseType = void> = {
onSuccess?: (response: ResponseType) => void
onError?: (error: any) => void

// Use catefully! If this is set to true, a .onSubmit() call can reject!
allowThrow?: boolean
}
Loading
Loading