diff --git a/src/pages/auth/login.tsx b/src/pages/auth/login.tsx index f583d64..0d25618 100644 --- a/src/pages/auth/login.tsx +++ b/src/pages/auth/login.tsx @@ -19,7 +19,7 @@ export default function Login() { const userStore = useUserStore() function doCallback() { - let redirectUrl = searchParams.get('redirect_url') + let redirectUrl = searchParams.get('redirect_uri') if (redirectUrl) { if (redirectUrl.startsWith('/')) { router.push(redirectUrl) diff --git a/src/pages/orders/[id].tsx b/src/pages/orders/[id].tsx new file mode 100644 index 0000000..8d88ecc --- /dev/null +++ b/src/pages/orders/[id].tsx @@ -0,0 +1,118 @@ +import { Box, Typography, Container, Button, TextField, Collapse, Alert } from '@mui/material' +import { GetServerSideProps, InferGetServerSidePropsType } from 'next' +import { EventHandler, FormEvent, FormEventHandler, useEffect, useState } from 'react' +import { checkAuthenticatedClient, redirectToLogin, sni } from 'solar-js-sdk' + +import ErrorIcon from '@mui/icons-material/Error' +import PriceCheckIcon from '@mui/icons-material/PriceCheck' + +type SnOrder = any + +export const getServerSideProps = (async (context) => { + const id = context.params!.id + try { + const { data: order } = await sni.get('/cgi/wa/orders/' + id) + return { props: { order, title: `Order #${order.id}` } } + } catch (err) { + console.error(err) + return { + notFound: true, + } + } +}) satisfies GetServerSideProps<{ order: SnOrder }> + +export default function Post({ order }: InferGetServerSidePropsType) { + useEffect(() => { + if (!checkAuthenticatedClient()) redirectToLogin() + }, []) + + const [error, setError] = useState(null) + const [password, setPassword] = useState('') + const [busy, setBusy] = useState(false) + const [paid, setPaid] = useState(false) + const [canceled, setCanceled] = useState(false) + + useEffect(() => { + if (order?.status === 1) { + setPaid(true) + } else if (order?.status === 2) { + setCanceled(true) + } + }, [order]) + + async function confirmPayment() { + try { + setBusy(true) + await sni.post('/cgi/wa/orders/' + order.id + '/pay', { + wallet_password: password, + }) + setPaid(true) + } catch (err: any) { + setError(err.toString()) + } finally { + setBusy(false) + } + } + + return ( + + { + evt.preventDefault() + confirmPayment() + }} + > + + Order #{order.id.toString().padStart(8, '0')} + + + {order.remark} + + + + {order.amount} SRC + + + + } severity="error"> + {error} + + + + + {paid || canceled ? ( + canceled ? ( + Canceled, you're not able to pay this order any more. + ) : ( + Paid, you can return to the seller now + ) + ) : ( + setPassword((evt.target as HTMLInputElement).value)} + /> + )} + + + + + Powered by HyperNet.Wallet + + + + ) +}