Skip to content

Commit

Permalink
fix: merge conflicts with testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Oct 20, 2023
2 parents e0f3c74 + 554145b commit bc2cf95
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 67 deletions.
18 changes: 9 additions & 9 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
about: Describe the feature you want and propose some steps to achieve it
title: ""
labels: "open for contribution, Type: feature"
labels: ""
assignees: ""
---

**Is your feature request related to a problem? Please describe.**
## Description
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
## PROPOSED TODO

- [ ] Your task number 1
- [ ] Your task number 2
- [ ] Your task number 3
...

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
59 changes: 10 additions & 49 deletions components/UI/wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FunctionComponent, useEffect } from "react";
import { Modal } from "@mui/material";
import WalletIcons from "./iconsComponents/icons/walletIcons";
import getDiscoveryWallets from "get-starknet-core";
import useGetDiscoveryWallets from "../../hooks/useGetDiscoveryWallets";

type WalletsProps = {
closeWallet: () => void;
Expand All @@ -18,64 +19,21 @@ const Wallets: FunctionComponent<WalletsProps> = ({
}) => {
const { connect, connectors } = useConnectors();
const { account } = useAccount();
const [argent, setArgent] = useState<string>("");
const [braavos, setBraavos] = useState<string>("");
const combinations = [
[0, 1, 2],
[0, 2, 1],
[1, 0, 2],
[1, 2, 0],
[2, 0, 1],
[2, 1, 0],
];
const rand = useMemo(() => Math.floor(Math.random() * 6), []);
const downloadLinks = useGetDiscoveryWallets(
getDiscoveryWallets.getDiscoveryWallets()
);

useEffect(() => {
if (account) {
closeWallet();
}
}, [account, closeWallet]);

useEffect(() => {
// get wallets download links from get-starknet-core
// if browser is not recognized, it will default to their download pages
getDiscoveryWallets.getDiscoveryWallets().then((wallets) => {
const browser = getBrowser();

wallets.map((wallet) => {
if (wallet.id === "argentX") {
setArgent(
browser
? wallet.downloads[browser]
: "https://www.argent.xyz/argent-x/"
);
} else if (wallet.id === "braavos") {
setBraavos(
browser
? wallet.downloads[browser]
: "https://braavos.app/download-braavos-wallet/"
);
}
});
});
}, []);

function connectWallet(connector: Connector): void {
connect(connector);
closeWallet();
}

function getBrowser(): string | undefined {
const userAgent = navigator.userAgent;
if (userAgent.includes("Chrome")) {
return "chrome";
} else if (userAgent.includes("Firefox")) {
return "firefox";
} else {
return undefined;
}
}

return (
<Modal
disableAutoFocus
Expand All @@ -101,8 +59,7 @@ const Wallets: FunctionComponent<WalletsProps> = ({
</svg>
</button>
<p className={styles.menu_title}>You need a Starknet wallet</p>
{combinations[rand].map((index) => {
const connector = connectors[index];
{connectors.map((connector) => {
if (connector.available()) {
return (
<div className="mt-5 flex justify-center" key={connector.id}>
Expand All @@ -123,7 +80,11 @@ const Wallets: FunctionComponent<WalletsProps> = ({
<Button
onClick={() =>
window.open(
`${connector.id === "braavos" ? braavos : argent}`
`${
downloadLinks[
connector.id as keyof typeof downloadLinks
]
}`
)
}
>
Expand Down
2 changes: 1 addition & 1 deletion components/discount/registerDiscount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
setMetadataHash(
await computeMetadataHash(
email,
mailGroups,
//mailGroups,
isUsResident ? usState : "none",
salt
)
Expand Down
19 changes: 19 additions & 0 deletions components/domains/registerV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { utils } from "starknetid.js";
import {
getDomainWithStark,
formatHexString,
isHexString,
isValidEmail,
} from "../../utils/stringService";
Expand Down Expand Up @@ -107,7 +108,11 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
setMetadataHash(
await computeMetadataHash(
email,
<<<<<<< HEAD
renewalBox ? groups : [groups[0]], // default group for domain Owner
=======
//groups, // default group for domain Owner
>>>>>>> testnet
isUsResident ? usState : "none",
salt
)
Expand Down Expand Up @@ -241,14 +246,28 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
body: JSON.stringify({
meta_hash: metadataHash,
email,
<<<<<<< HEAD
groups: renewalBox ? groups : [groups[0]],
=======
>>>>>>> testnet
tax_state: isUsResident ? usState : "none",
salt: salt,
}),
})
.then((res) => res.json())
.catch((err) => console.log("Error on sending metadata:", err));

fetch(`${process.env.NEXT_PUBLIC_SALES_SERVER_LINK}/mail_subscribe`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tx_hash: formatHexString(registerData.transaction_hash),
groups,
}),
})
.then((res) => res.json())
.catch((err) => console.log("Error on registering to email:", err));

addTransaction({ hash: registerData.transaction_hash });
setIsTxModalOpen(true);
}, [registerData, salt, email, usState]);
Expand Down
15 changes: 13 additions & 2 deletions components/domains/renewal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useTransactionManager,
} from "@starknet-react/core";
import {
formatHexString,
isValidEmail,
selectedDomainsToArray,
selectedDomainsToEncodedArray,
Expand Down Expand Up @@ -90,14 +91,24 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
body: JSON.stringify({
meta_hash: metadataHash,
email,
groups: renewalBox ? groups : [groups[0]],
tax_state: isUsResident ? usState : "none",
salt: salt,
}),
})
.then((res) => res.json())
.catch((err) => console.log("Error on sending metadata:", err));

fetch(`${process.env.NEXT_PUBLIC_SALES_SERVER_LINK}/mail_subscribe`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tx_hash: formatHexString(renewData.transaction_hash),
groups,
}),
})
.then((res) => res.json())
.catch((err) => console.log("Error on registering to email:", err));

addTransaction({ hash: renewData.transaction_hash });
setIsTxModalOpen(true);
}, [renewData, salt, email, usState]);
Expand All @@ -115,7 +126,7 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
setMetadataHash(
await computeMetadataHash(
email,
renewalBox ? groups : [groups[0]], // default group for domain Owner
//groups, // default group for domain Owner
isUsResident ? usState : "none",
salt
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const ClickablePersonhoodIcon: FunctionComponent<
process.env.NEXT_PUBLIC_VERIFIER_POP_CONTRACT as string,
tokenId,
Math.floor(Date.now() / 1000 + 15 * 60),
shortString.encodeShortString("proof_of_personhood"),
"proof_of_personhood",
hexToDecimal(hexSessionId),
[sig.r, sig.s]
)
Expand Down
36 changes: 36 additions & 0 deletions hooks/useGetDiscoveryWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useEffect, useState } from "react";
import { WalletProvider } from "get-starknet-core";
import { getBrowser } from "../utils/browserService";

export default function useGetDiscoveryWallets(
getDiscoveryWallets: Promise<WalletProvider[]>
) {
const [argentX, setArgentX] = useState<string>("");
const [braavos, setBraavos] = useState<string>("");

useEffect(() => {
if (typeof navigator !== "undefined") {
getDiscoveryWallets.then((wallets) => {
const browser = getBrowser(navigator.userAgent);

wallets.map((wallet) => {
if (wallet.id === "argentX") {
setArgentX(
browser
? wallet.downloads[browser as keyof typeof wallet.downloads]
: "https://www.argent.xyz/argent-x/"
);
} else if (wallet.id === "braavos") {
setBraavos(
browser
? wallet.downloads[browser as keyof typeof wallet.downloads]
: "https://braavos.app/download-braavos-wallet/"
);
}
});
});
}
}, [getDiscoveryWallets]);

return { argentX, braavos };
}
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import posthog from "posthog-js";
import AcceptCookies from "../components/legal/acceptCookies";

const connectors = [
new InjectedConnector({ options: { id: "argentX" } }),
new InjectedConnector({ options: { id: "braavos" } }),
new InjectedConnector({ options: { id: "argentX" } }),
new WebWalletConnector({
url:
process.env.NEXT_PUBLIC_IS_TESTNET === "true"
Expand Down
28 changes: 28 additions & 0 deletions tests/utils/browserService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
getBrowser,
} from "../../utils/browserService";

describe("Should test getBrowser function", () => {
it("Should return Chrome", () => {
expect(
getBrowser(
"userAgent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
)
).toEqual(
"chrome"
);
});

it("Should return firefox", () => {
expect(
getBrowser(
"userAgent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/116.0"
)
).toEqual("firefox");
});

it("Should return an undefined if it's another browser or an empty string", () => {
expect(getBrowser("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15")).toEqual(undefined);
expect(getBrowser("")).toEqual(undefined);
});
});
48 changes: 47 additions & 1 deletion tests/utils/stringService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getDomainWithoutStark,
isStarkRootDomain,
isHexString,
formatHexString,
isSubdomain,
minifyAddress,
minifyDomain,
Expand All @@ -24,7 +25,7 @@ import {
isValidDomain,
getDomainLength,
selectedDomainsToArray,
selectedDomainsToEncodedArray
selectedDomainsToEncodedArray,
} from "../../utils/stringService";

describe("Should test is1234Domain", () => {
Expand Down Expand Up @@ -174,6 +175,51 @@ describe("Should test isHexString", () => {
});
});

describe("Should test formatHexString", () => {
it("Should format a hex string without 0x prefix and add leading zeros", () => {
const input = "a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
const expected =
"0x0000000a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
expect(formatHexString(input)).toEqual(expected);
});

it("Should format a hex string with 0x prefix and add leading zeros", () => {
const input = "0xa78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
const expected =
"0x0000000a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
expect(formatHexString(input)).toEqual(expected);
});

it("Should format a hex string without leading zeros", () => {
const input =
"0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
const expected =
"0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3";
expect(formatHexString(input)).toEqual(expected);
});

it("Should format a short hex string with many leading zeros", () => {
const input = "0x1b";
const expected =
"0x000000000000000000000000000000000000000000000000000000000000001b";
expect(formatHexString(input)).toEqual(expected);
});

it("Should handle an empty string", () => {
const input = "";
const expected =
"0x0000000000000000000000000000000000000000000000000000000000000000";
expect(formatHexString(input)).toEqual(expected);
});

it("Should handle non-hex characters by not altering them (though this might not be intended behavior)", () => {
const input = "0xabcg";
const expected =
"0x000000000000000000000000000000000000000000000000000000000000abcg";
expect(formatHexString(input)).toEqual(expected);
});
});

describe("Should test isSubdomain", () => {
it("Should return false cause string is not a subdomain", () => {
expect(isSubdomain("1232575.stark")).toBeFalsy();
Expand Down
9 changes: 9 additions & 0 deletions utils/browserService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function getBrowser(userAgent: string): string | undefined {
if (userAgent.includes("Chrome")) {
return "chrome";
} else if (userAgent.includes("Firefox")) {
return "firefox";
} else {
return undefined;
}
}
Loading

0 comments on commit bc2cf95

Please sign in to comment.