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

frontend,backend and database changes done #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ const transformUser = (
*/
export const createUser = async (
username: string,
firstName: string,
lastName: string,
blockchainPublicKeys: Array<{ blockchain: Blockchain; publicKey: string }>,
waitlistId?: string | null,
referrerId?: string
Expand Down Expand Up @@ -329,6 +331,8 @@ export const createUser = async (
{
object: {
username: username,
firstName: firstName,
lastName: lastName,
public_keys: {
data: blockchainPublicKeys.map((b) => ({
blockchain: b.blockchain,
Expand Down
7 changes: 6 additions & 1 deletion backend/native/backpack-api/src/routes/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ router.get("/jwt/xnft", extractUserId, async (req, res) => {
* Create a new user.
*/
router.post("/", async (req, res) => {
const { username, waitlistId, blockchainPublicKeys } =
const { username, waitlistId, blockchainPublicKeys, firstName, lastName } =
CreateUserWithPublicKeys.parse(req.body);

console.log(firstName);
console.log(lastName);

// Validate all the signatures
for (const blockchainPublicKey of blockchainPublicKeys) {
const signedMessage = getCreateMessage(blockchainPublicKey.publicKey);
Expand Down Expand Up @@ -182,6 +185,8 @@ router.post("/", async (req, res) => {

const user = await createUser(
username,
firstName,
lastName,
blockchainPublicKeys.map((b) => ({
...b,
// Cast blockchain to correct type
Expand Down
12 changes: 12 additions & 0 deletions backend/native/backpack-api/src/validation/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export const BaseCreateUser = z.object({
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
firstName: z
.string()
.regex(
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
lastName: z
.string()
.regex(
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
inviteCode: z
.string()
.regex(
Expand Down
1 change: 1 addition & 0 deletions backend/native/zeus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"graphql": "^16.8.1",
"tsc-alias": "^1.7.1",
"typescript": "~4.9.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const OnboardAccount = ({
<UsernameForm
key="UsernameForm"
inviteCode={inviteCode!}
onNext={(username) => {
setOnboardingData({ username });
onNext={(username, firstName, lastName) => {
setOnboardingData({ username, firstName, lastName });
nextStep();
}}
/>,
Expand Down Expand Up @@ -161,79 +161,80 @@ export const OnboardAccount = ({
}

return (
<WithNav
navButtonLeft={
step > 0 && step !== steps.length - 1 ? (
<NavBackButton onClick={prevStep} />
) : undefined
}
{...navProps}
// Only display the onboarding menu on the first step
navButtonRight={step === 0 ? navProps.navButtonRight : undefined}
>
{steps[step]}
// <WithNav
// navButtonLeft={
// step > 0 && step !== steps.length - 1 ? (
// <NavBackButton onClick={prevStep} />
// ) : undefined
// }
// {...navProps}
// // Only display the onboarding menu on the first step
// navButtonRight={step === 0 ? navProps.navButtonRight : undefined}
// >
// {steps[step]}

<WithContaineredDrawer
containerRef={containerRef}
openDrawer={openDrawer}
setOpenDrawer={setOpenDrawer}
paperStyles={{
height: "calc(100% - 56px)",
borderTopLeftRadius: "12px",
borderTopRightRadius: "12px",
}}
>
{keyringType === "ledger" ? (
<HardwareOnboard
blockchain={blockchain!}
// @ts-expect-error not assignable to type string ...
action={action}
signMessage={(publicKey: string) => getCreateMessage(publicKey)}
signText="Sign the message to authenticate with Backpack."
onClose={() => setOpenDrawer(false)}
onComplete={(signedWalletDescriptor: SignedWalletDescriptor) => {
setOnboardingData({
signedWalletDescriptors: [
...signedWalletDescriptors,
signedWalletDescriptor,
],
});
setOpenDrawer(false);
}}
/>
) : (
<ImportWallets
blockchain={blockchain!}
mnemonic={mnemonic!}
allowMultiple={false}
onNext={async (walletDescriptors: Array<WalletDescriptor>) => {
// Should only be one public key path
const walletDescriptor = walletDescriptors[0];
const signature = await signMessageForWallet(
walletDescriptor.blockchain,
walletDescriptor.publicKey,
getCreateMessage(walletDescriptor.publicKey),
{
mnemonic: mnemonic!,
signedWalletDescriptors: [
{ ...walletDescriptor, signature: "" },
],
}
);
setOnboardingData({
signedWalletDescriptors: [
...signedWalletDescriptors,
{
...walletDescriptor,
signature,
},
],
});
setOpenDrawer(false);
}}
/>
)}
</WithContaineredDrawer>
</WithNav>
// <WithContaineredDrawer
// containerRef={containerRef}
// openDrawer={openDrawer}
// setOpenDrawer={setOpenDrawer}
// paperStyles={{
// height: "calc(100% - 56px)",
// borderTopLeftRadius: "12px",
// borderTopRightRadius: "12px",
// }}
// >
// {keyringType === "ledger" ? (
// <HardwareOnboard
// blockchain={blockchain!}
// // @ts-expect-error not assignable to type string ...
// action={action}
// signMessage={(publicKey: string) => getCreateMessage(publicKey)}
// signText="Sign the message to authenticate with Backpack."
// onClose={() => setOpenDrawer(false)}
// onComplete={(signedWalletDescriptor: SignedWalletDescriptor) => {
// setOnboardingData({
// signedWalletDescriptors: [
// ...signedWalletDescriptors,
// signedWalletDescriptor,
// ],
// });
// setOpenDrawer(false);
// }}
// />
// ) : (
// <ImportWallets
// blockchain={blockchain!}
// mnemonic={mnemonic!}
// allowMultiple={false}
// onNext={async (walletDescriptors: Array<WalletDescriptor>) => {
// // Should only be one public key path
// const walletDescriptor = walletDescriptors[0];
// const signature = await signMessageForWallet(
// walletDescriptor.blockchain,
// walletDescriptor.publicKey,
// getCreateMessage(walletDescriptor.publicKey),
// {
// mnemonic: mnemonic!,
// signedWalletDescriptors: [
// { ...walletDescriptor, signature: "" },
// ],
// }
// );
// setOnboardingData({
// signedWalletDescriptors: [
// ...signedWalletDescriptors,
// {
// ...walletDescriptor,
// signature,
// },
// ],
// });
// setOpenDrawer(false);
// }}
// />
// )}
// </WithContaineredDrawer>
// </WithNav>
<div>{steps[step]}</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type FormEvent, useCallback, useEffect, useState } from "react";
import { PrimaryButton,TextInput } from "@coral-xyz/react-common";
import { PrimaryButton, TextInput } from "@coral-xyz/react-common";
import { useCustomTheme } from "@coral-xyz/themes";
import { AlternateEmail } from "@mui/icons-material";
import { Box, InputAdornment } from "@mui/material";
Expand All @@ -11,9 +11,11 @@ export const UsernameForm = ({
onNext,
}: {
inviteCode: string;
onNext: (username: string) => void;
onNext: (username: string, firstName: string, lastName: string) => void;
}) => {
const [username, setUsername] = useState("");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [error, setError] = useState("");
const theme = useCustomTheme();

Expand All @@ -31,15 +33,19 @@ export const UsernameForm = ({
"x-backpack-invite-code": String(inviteCode),
},
});
console.log("response here", res);
const json = await res.json();
console.log("json here", json);
if (!res.ok) throw new Error(json.message || "There was an error");

onNext(username);
onNext(username, firstName, lastName);
} catch (err: any) {
console.log(err);

setError(err.message);
}
},
[username]
[username, firstName, lastName] // this change made the lastname and firstname appear in payload of request in network tab
);

return (
Expand Down Expand Up @@ -104,6 +110,70 @@ export const UsernameForm = ({
</InputAdornment>
}
/>

{/* name */}
<TextInput
inputProps={{
name: "firstName",
autoComplete: "off",
spellCheck: "false",
autoFocus: true,
}}
placeholder="First Name"
type="text"
value={firstName}
setValue={(e) => {
setFirstName(
e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "")
);
}}
error={error ? true : false}
errorMessage={error}
startAdornment={
<InputAdornment position="start">
<AlternateEmail
style={{
color: theme.custom.colors.secondary,
fontSize: 18,
marginRight: -2,
userSelect: "none",
}}
/>
</InputAdornment>
}
/>

{/* last name */}
<TextInput
inputProps={{
name: "lastName",
autoComplete: "off",
spellCheck: "false",
autoFocus: true,
}}
placeholder="Last Name"
type="text"
value={lastName}
setValue={(e) => {
setLastName(
e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "")
);
}}
error={error ? true : false}
errorMessage={error}
startAdornment={
<InputAdornment position="start">
<AlternateEmail
style={{
color: theme.custom.colors.secondary,
fontSize: 18,
marginRight: -2,
userSelect: "none",
}}
/>
</InputAdornment>
}
/>
</Box>
<PrimaryButton label="Continue" type="submit" />
</Box>
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ export const ALCHEMY_ETHEREUM_MAINNET_API_KEY =
"DlJr6QuBC2EaE-L60-iqQQGq9hi9-XSZ";

export const AVATAR_BASE_URL = "https://swr.xnfts.dev/avatars";
export const BACKEND_API_URL = "https://backpack-api.xnfts.dev";
// export const BACKEND_API_URL = "https://backpack-api.xnfts.dev";
export const BACKEND_API_URL = "http://localhost:8080";
export const REALTIME_API_URL = "https://backend-ws.xnfts.dev";
export const MESSAGING_COMMUNICATION_PUSH = "MESSAGING_COMMUNICATION_PUSH";
export const MESSAGING_COMMUNICATION_FETCH = "MESSAGING_COMMUNICATION_FETCH";
Expand Down
9 changes: 8 additions & 1 deletion packages/recoil/src/context/OnboardingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export type OnboardingData = {
complete: boolean;
inviteCode: string | undefined;
username: string | null;
firstName: string | null;
lastName: string | null;
action: string;
keyringType: KeyringType | null;
blockchain: Blockchain | null;
Expand All @@ -102,6 +104,8 @@ const defaultState = {
complete: false,
inviteCode: undefined,
username: null,
firstName: null,
lastName: null,
action: "create",
keyringType: null,
blockchain: null,
Expand Down Expand Up @@ -278,7 +282,8 @@ export function OnboardingProvider({
//
const createUser = useCallback(
async (data: Partial<OnboardingData>) => {
const { inviteCode, userId, username, keyringType } = data;
const { inviteCode, userId, username, firstName, lastName, keyringType } =
data;

// If userId is provided, then we are onboarding via the recover flow.
if (userId) {
Expand Down Expand Up @@ -312,6 +317,8 @@ export function OnboardingProvider({
//
const body = JSON.stringify({
username,
firstName,
lastName,
inviteCode,
waitlistId: getWaitlistId?.(),
blockchainPublicKeys,
Expand Down