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

Read query parameters (key, sigAlgo and source) from URL #40

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions components/CreateAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import {accountCreated} from "../lib/metrics"

export default function CreateAccountForm({
clientCreateAccount,
publicKey,
trafficSource,
sigAlgo,
}: {
clientCreateAccount: ClientCreateAccount
clientCreateAccount: ClientCreateAccount,
publicKey: string,
trafficSource: string,
sigAlgo: string,
}) {
const [errors, setErrors] = useState<string[]>([])
const [captchaToken, setCaptchaToken] = useState("")
Expand All @@ -26,8 +32,8 @@ export default function CreateAccountForm({
<FormContainer>
<Formik
initialValues={{
publicKey: "",
signatureAlgorithm: "ECDSA_P256",
publicKey,
signatureAlgorithm: sigAlgo || "ECDSA_P256",
hashAlgorithm: "SHA3_256",
}}
validationSchema={createAccountSchemaClient}
Expand All @@ -50,8 +56,7 @@ export default function CreateAccountForm({
} else if (response.address) {
const {address} = response
setAddress(address)
mixpanel.track("Faucet: Create Account", {address})

mixpanel.track("Faucet: Create Account", {address, trafficSource})
try {
await accountCreated(mixpanel.get_distinct_id(), address)
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions components/CreateAccountPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Sidebar from "components/Sidebar"
import {clientCreateAccount} from "lib/client"
import {clientCreateAccount, CreateAccountURLParams} from "lib/client"
import {Box, Grid} from "theme-ui"
import CreateAccountForm from "./CreateAccountForm"

export default function CreateAccountPanel() {
export default function CreateAccountPanel({ publicKey, trafficSource, sigAlgo} : CreateAccountURLParams) {
return (
<div>
<Grid gap={[0, 0, 40, 100]} columns={["auto", "auto", "1.6fr 1fr"]}>
<Box>
<CreateAccountForm clientCreateAccount={clientCreateAccount} />
<CreateAccountForm sigAlgo={sigAlgo} publicKey={publicKey} trafficSource={trafficSource} clientCreateAccount={clientCreateAccount} />
</Box>
<Box>
<Sidebar />
Expand Down
6 changes: 6 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {CREATE_ACCOUNT_ERROR, FUND_ACCOUNT_ERROR} from "lib/constants"

export type CreateAccountURLParams = {
publicKey: string
trafficSource: string
sigAlgo: string
}

export type ClientCreateAccountResult = {
address: string
token: string
Expand Down
12 changes: 10 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import AppContainer from "components/AppContainer"
import CreateAccountPanel from "components/CreateAccountPanel"
import Header from "components/Header"
import PageTitle from "components/PageTitle"
import { CreateAccountURLParams } from "lib/client"

export default function Home() {
export default function Home(props: CreateAccountURLParams) {
return (
<AppContainer>
<PageTitle>Create Account</PageTitle>
<Header fund={true} />
<CreateAccountPanel />
<CreateAccountPanel {...props} />
</AppContainer>
)
}

Home.getInitialProps = async (context: any) => {
const key: string = context.query.key || ""
const source: string = context.query.source || ""
const sigAlgo: string = context.query["sig-algo"] || "ECDSA_P256"
return { publicKey: key, sigAlgo, trafficSource: source }
}