This repository has been archived by the owner on Apr 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a landing page for app purchases
This page doesn't display anything yet, it just asks the backend for a token and then redirects to another page to give flathub-authenticator the token. Finally, flathub-authenticator redirects once again to another landing page to let the user know the transaction is finished.
- Loading branch information
1 parent
86f2125
commit 6382258
Showing
6 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { GetStaticProps } from 'next' | ||
import { useTranslation } from 'next-i18next' | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations' | ||
import { NextSeo } from 'next-seo' | ||
import Main from '../../src/components/layout/Main' | ||
|
||
export default function Purchase({ providers }) { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<Main> | ||
<NextSeo title={t('thank-you-for-your-purchase')} noindex={true} /> | ||
<div className='main-container'> | ||
<h1>{t('thank-you-for-your-purchase')}</h1> | ||
{t('safe-to-close-page')} | ||
</div> | ||
</Main> | ||
) | ||
} | ||
|
||
export const getStaticProps: GetStaticProps = async ({ locale }) => { | ||
return { | ||
props: { | ||
...(await serverSideTranslations(locale, ['common'])), | ||
}, | ||
} | ||
} |
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,74 @@ | ||
import { GetStaticProps } from 'next' | ||
import { useTranslation } from 'next-i18next' | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations' | ||
import { NextSeo } from 'next-seo' | ||
import { useRouter } from 'next/router' | ||
import { ReactElement, useEffect, useState } from 'react' | ||
import { toast } from 'react-toastify' | ||
import Main from '../../src/components/layout/Main' | ||
import Spinner from '../../src/components/Spinner' | ||
import { generateTokens } from '../../src/context/actions' | ||
import { fetchLoginProviders } from '../../src/fetchers' | ||
import { LoginProvider } from '../../src/types/Login' | ||
|
||
const PERMITTED_REDIRECTS = [/http:\/\/localhost:\d+/, /http:\/\/127.0.0.1:\d+/]; | ||
|
||
export default function Purchase({ providers }) { | ||
const { t } = useTranslation(); | ||
const [waiting, setWaiting] = useState(false); | ||
const [error, setError] = useState(''); | ||
const [token, setToken] = useState(''); | ||
|
||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (!router.isReady) return; | ||
|
||
let redirect = router.query.return.toString(); | ||
if (!PERMITTED_REDIRECTS.some(r => redirect.match(r))) { | ||
setError(t('incorrect-redirect')); | ||
return; | ||
} | ||
|
||
let refs = router.query.refs.toString().split(";"); | ||
/* We get refs in the form app/<app ID>/<arch>/<branch>, we just want the app ID part */ | ||
let appIDs = refs.map(ref => ref.split("/")[1]); | ||
|
||
setWaiting(true); | ||
generateTokens(setToken, appIDs) | ||
.catch(err => toast.error(t(err))) | ||
.finally(() => setWaiting(false)); | ||
}, [router]); | ||
|
||
useEffect(() => { | ||
if (token) { | ||
window.location.href = router.query.return.toString() + "?token=" + token; | ||
} | ||
}, [token]); | ||
|
||
let content: ReactElement = null; | ||
|
||
if (waiting) | ||
content = <Spinner size={150} />; | ||
|
||
return ( | ||
<Main> | ||
<NextSeo title={t('purchase-apps-title')} noindex={true} /> | ||
<div className='main-container'> | ||
{content} | ||
</div> | ||
</Main> | ||
) | ||
} | ||
|
||
// Need available login providers to show options on page | ||
export const getStaticProps: GetStaticProps = async ({ locale }) => { | ||
const providers: LoginProvider[] = await fetchLoginProviders() | ||
|
||
return { | ||
props: { | ||
...(await serverSideTranslations(locale, ['common'])), | ||
providers, | ||
} | ||
} | ||
} |
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,8 @@ | ||
export interface Transaction { | ||
token?: string; | ||
appids: string[]; | ||
} | ||
|
||
export interface TransactionStateAction { | ||
token: string; | ||
} |