Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fixes redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway committed Nov 14, 2023
1 parent a60c3db commit ac74701
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 47 deletions.
1 change: 0 additions & 1 deletion apps/next/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ function App({ Component, pageProps, router }: AppProps) {
<VerifyPhoneNumberScreen />
<UnlockedChannelScreen />
<CreatorTokenBuyScreen />
<CreatorTokensShareModalScreen />
<CreatorTokenInviteSignInScreen />
<InviteCreatorTokenScreen />
<CreatorTokensSelfServeExplainerScreen />
Expand Down
19 changes: 0 additions & 19 deletions apps/next/src/pages/creator-token/crossmint-purchase-redirect.tsx

This file was deleted.

29 changes: 5 additions & 24 deletions packages/app/components/creator-token/buy-creator-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ export const BuyCreatorToken = () => {
process.env.NEXT_PUBLIC_STAGE === "production" ? "production" : "staging",
successCallbackURL:
typeof window !== "undefined"
? window.location.origin + `/creator-token/crossmint-purchase-redirect`
? window.location.origin +
`/creator-token/${profileData?.data?.profile.username}/share`
: undefined,
} as const;

Expand Down Expand Up @@ -330,7 +331,7 @@ export const BuyCreatorToken = () => {
height={44}
/>
)}
{crossmintConfig.collectionId && selectedAction === "buy" ? (
{selectedAction === "buy" ? (
<View>
{(priceToBuyNext.isLoading && paymentMethod === "USDC") ||
(ethPriceToBuyNext.isLoading &&
Expand Down Expand Up @@ -469,7 +470,7 @@ export const BuyCreatorToken = () => {
</Text>
</View>
</View>
{selectedAction === "buy" ? (
{selectedAction === "buy" && crossmintConfig.collectionId ? (
<>
<View tw="mx-auto my-2 h-[1px] w-[20%] rounded-full bg-gray-400" />
<CrossmintPayButton
Expand All @@ -485,27 +486,7 @@ export const BuyCreatorToken = () => {
e.preventDefault();
return;
}

function listenCrossmintMessage(event: any) {
if (event.data.type === "purchase.succeeded") {
if (profileData?.data?.profile) {
redirectToCreatorTokensShare({
username: profileData?.data?.profile.username,
type: "collected",
collectedCount: tokenAmount,
});
router.pop();
console.log(
`Received message from crossmint window: ${event.data}`
);
window.removeEventListener(
"message",
listenCrossmintMessage
);
}
}
}
window.addEventListener("message", listenCrossmintMessage);
router.pop();
}}
{...crossmintConfig}
/>
Expand Down
21 changes: 19 additions & 2 deletions packages/app/components/creator-token/creator-tokens-share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,30 @@ const { useParam } = createParam<{
username: string;
type: TokenShareType;
collectedCount: string;
p: string;
}>();

export const CreatorTokensShareModal = memo(function CreatorTokens() {
const linearOpaticy = useSharedValue(0);
const [username] = useParam("username");
const [collectedCount] = useParam("collectedCount");
const [type] = useParam("type");
let [collectedCount] = useParam("collectedCount");
let [type] = useParam("type");

// Redirect from crossmint
// https://docs.crossmint.com/docs/redirect-url#redirection-payload
const [p] = useParam("p");

if (p) {
try {
const params = JSON.parse(p);
if (params && params[0] && params[0].type === "purchase.succeeded") {
collectedCount = params?.[0]?.tokenIds?.length;
type = "collected";
}
} catch (e) {
// noop
}
}

const { data: userInfo } = useUserProfile({ address: username });
const profileData = userInfo?.data?.profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const CreatorTokenSocialShareScreen = withModalScreen(
CreatorTokenSocialShare,
{
title: "",
matchingPathname: "/creator-token/[username]/share",
matchingPathname: "/creator-token/[username]/social-share",
matchingQueryParam: "creatorTokenSocialShareModal",
snapPoints: ["100%"],
enableHandlePanningGesture: true,
Expand Down

0 comments on commit ac74701

Please sign in to comment.