-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jumper-requirements
- Loading branch information
Showing
15 changed files
with
1,804 additions
and
959 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 was deleted.
Oops, something went wrong.
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
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,66 @@ | ||
"use client" | ||
|
||
import { platformMergeAlertAtom } from "@/components/Providers/atoms" | ||
import { useToast } from "@/components/ui/hooks/useToast" | ||
import { useSetAtom } from "jotai" | ||
import { usePathname, useRouter, useSearchParams } from "next/navigation" | ||
import { useEffect } from "react" | ||
import rewards from "rewards" | ||
import { PlatformName } from "types" | ||
|
||
export function OAuthResultToast() { | ||
const { toast } = useToast() | ||
|
||
const { replace } = useRouter() | ||
const pathname = usePathname() | ||
const readonlyQuery = useSearchParams() | ||
|
||
const showPlatformMergeAlert = useSetAtom(platformMergeAlertAtom) | ||
|
||
useEffect(() => { | ||
if (readonlyQuery?.get("oauth-status")) { | ||
const newQuery = new URLSearchParams(readonlyQuery.toString()) | ||
|
||
const oauthPlatform = readonlyQuery.get("oauth-platform") | ||
const oauthStatus = readonlyQuery.get("oauth-status") | ||
const oauthMessage = readonlyQuery.get("oauth-message") | ||
|
||
const platformNameHumanReadable = | ||
rewards[(oauthPlatform as PlatformName) ?? ""]?.name ?? "Social" | ||
|
||
const title = | ||
oauthStatus === "success" | ||
? `${platformNameHumanReadable} successfully connected` | ||
: `Failed to connect ${platformNameHumanReadable}` | ||
|
||
if ( | ||
oauthStatus === "error" && | ||
oauthMessage?.toString()?.startsWith("Before connecting your") | ||
) { | ||
const [, addressOrDomain] = oauthMessage | ||
.toString() | ||
.match( | ||
/^Before connecting your (?:.*?) account, please disconnect it from this address: (.*?)$/ | ||
) | ||
|
||
showPlatformMergeAlert({ | ||
addressOrDomain, | ||
platformName: oauthPlatform as PlatformName, | ||
}) | ||
} else { | ||
toast({ | ||
variant: oauthStatus as "success" | "error", | ||
title, | ||
description: oauthMessage, | ||
}) | ||
} | ||
|
||
replace(`${pathname}?${newQuery.toString()}`) | ||
} | ||
// replace is intentionally left out | ||
// toast is intentionally left out, as it causes the toast to fire twice | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [readonlyQuery, showPlatformMergeAlert, pathname]) | ||
|
||
return null | ||
} |