Skip to content

Commit

Permalink
Merge pull request #848 from starknet-id/testnet
Browse files Browse the repository at this point in the history
MEP 28/06/24
  • Loading branch information
fricoben authored Jun 28, 2024
2 parents 92cb242 + 1545c3f commit 5cc87db
Show file tree
Hide file tree
Showing 16 changed files with 4,155 additions and 3,138 deletions.
7 changes: 4 additions & 3 deletions components/UI/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TextField, styled } from "@mui/material";
import styles from "../../styles/search.module.css";
import SearchResult from "../UI/searchResult";
import { utils } from "starknetid.js";
import { Abi, Contract, Provider } from "starknet";
import { Abi, Contract, Provider, Result } from "starknet";
import naming_abi from "../../abi/starknet/naming_abi.json";
import { StarknetIdJsContext } from "../../context/StarknetIdJsProvider";
import { isValidDomain, getDomainWithStark } from "../../utils/stringService";
Expand Down Expand Up @@ -205,8 +205,9 @@ const SearchBar: FunctionComponent<SearchBarProps> = ({
if (signal?.aborted) {
return reject("Aborted");
}
contract?.call("domain_to_data", [encoded]).then((res) => {
if (Number(res?.["expiry"]) < currentTimeStamp) {
contract?.call("domain_to_data", [encoded]).then((res: Result) => {
const callResult = res as CallResult;
if (Number(callResult?.["expiry"]) < currentTimeStamp) {
resolve({
name,
error: false,
Expand Down
5 changes: 4 additions & 1 deletion components/discount/freeRenewalDiscount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({
}
// Add AutoRenewal calls for all currencies
selectedDomainsToArray(selectedDomains).map((domain) => {
if (needSubscription && needSubscription[domain]?.[currency]) {
if (
needSubscription &&
needSubscription.needSubscription[domain]?.[currency]
) {
const encodedDomain = utils
.encodeDomain(domain)
.map((element) => element.toString())[0];
Expand Down
15 changes: 14 additions & 1 deletion components/discount/registerDiscount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { FunctionComponent, useEffect, useState } from "react";
import Button from "../UI/button";
import { useAccount, useContractWrite } from "@starknet-react/core";
import { utils } from "starknetid.js";
import { getDomainWithStark, isValidEmail } from "../../utils/stringService";
import {
formatHexString,
getDomainWithStark,
isValidEmail,
} from "../../utils/stringService";
import { applyRateToBigInt, hexToDecimal } from "../../utils/feltService";
import { useDisplayName } from "../../hooks/displayName.tsx";
import { Call } from "starknet";
Expand Down Expand Up @@ -37,6 +41,7 @@ import {
} from "../../utils/altcoinService";
import { getPriceFromDomain } from "@/utils/priceService";
import { useRouter } from "next/router";
import { formatDomainData } from "@/utils/cacheDomainData";

type RegisterDiscountProps = {
domain: string;
Expand Down Expand Up @@ -309,6 +314,14 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
status: "pending",
},
});
formatDomainData(
tokenIdRedirect,
formatHexString(address as string),
getDomainWithStark(domain),
duration,
Boolean(!hasMainDomain), // isMainDomain
undefined // Selected PFPs
);
router.push(`/confirmation?tokenId=${tokenIdRedirect}`);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [registerData]); // We want to execute this only once after the tx is sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
StarknetSignature,
} from "@anima-protocol/personhood-sdk-react";
import { useAccount } from "@starknet-react/core";
import { Call, constants, typedData } from "starknet";
import { Call, TypedData, constants } from "starknet";
import { useContractWrite } from "@starknet-react/core";
import { hexToDecimal } from "../../../../utils/feltService";
import { minifyDomain } from "../../../../utils/stringService";
Expand Down Expand Up @@ -102,7 +102,7 @@ const ClickablePersonhoodIcon: FunctionComponent<

const sign = useCallback(
(payload: string | object) => {
return account?.signMessage(payload as typedData.TypedData) as Promise<
return account?.signMessage(payload as TypedData) as Promise<
string | StarknetSignature
>;
},
Expand Down
4 changes: 1 addition & 3 deletions context/StarknetIdJsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export const StarknetIdJsProvider: FunctionComponent<Context> = ({

const provider = useMemo(() => {
return new Provider({
rpc: {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL,
},
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL,
});
}, []);

Expand Down
5 changes: 3 additions & 2 deletions hooks/naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ export function useDataFromDomain(domain: string): FullDomainData {
args: [encoded],
});

const res = data as CallResult;
return {
expiry: data?.["expiry"],
owner: data?.["owner"],
expiry: res?.["expiry"],
owner: res?.["owner"],
error: error?.message as string,
};
}
7 changes: 4 additions & 3 deletions hooks/useAllowanceCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ export default function useAllowanceCheck(
});

useEffect(() => {
const erc20AllowanceRes = erc20AllowanceData as CallResult;
if (
erc20AllowanceError ||
(erc20AllowanceData &&
erc20AllowanceData["remaining"].low !== UINT_128_MAX &&
erc20AllowanceData["remaining"].high !== UINT_128_MAX)
(erc20AllowanceRes &&
erc20AllowanceRes["remaining"].low !== UINT_128_MAX &&
erc20AllowanceRes["remaining"].high !== UINT_128_MAX)
) {
setNeedsAllowance(true);
} else {
Expand Down
5 changes: 3 additions & 2 deletions hooks/useBalances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ export default function useBalances(address?: string) {

useEffect(() => {
if (erc20BalanceError || !erc20BalanceData) return;
const erc20BalanceRes = erc20BalanceData as bigint[][];
const currencies = Object.values(CurrencyType);
const balanceEntries: TokenBalance = {};
currencies.forEach((currency, index) => {
const balance = fromUint256(
BigInt(erc20BalanceData[index][0]),
BigInt(erc20BalanceData[index][1])
BigInt(erc20BalanceRes[index][0]),
BigInt(erc20BalanceRes[index][1])
);
balanceEntries[currency] = balance;
});
Expand Down
5 changes: 3 additions & 2 deletions hooks/useNeedAllowances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export default function useNeedsAllowances(
if (erc20AllowanceError || !erc20AllowanceData) return;
const currencyNames = Object.values(CurrencyType);
const needsAllowancesEntries: Record<string, boolean> = {};
const erc20AllowanceRes = erc20AllowanceData as bigint[][];
currencyNames.forEach((currency, index) => {
const balance = fromUint256(
BigInt(erc20AllowanceData[index][0]),
BigInt(erc20AllowanceData[index][1])
BigInt(erc20AllowanceRes[index][0]),
BigInt(erc20AllowanceRes[index][1])
);
needsAllowancesEntries[currency] = balance === "0";
});
Expand Down
37 changes: 27 additions & 10 deletions hooks/useNotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { atomWithStorage } from "jotai/utils";
import { useEffect } from "react";
import { hexToDecimal } from "../utils/feltService";
import { NotificationType } from "../utils/constants";
import {
RejectedTransactionReceiptResponse,
RevertedTransactionReceiptResponse,
} from "starknet";

const notificationsAtom = atomWithStorage<SIDNotification<NotificationData>[]>(
"userNotifications_SID",
Expand All @@ -24,21 +28,34 @@ export function useNotificationManager() {
if (notification.address !== hexToDecimal(address)) return;
if (notification.data.status === "pending") {
const transaction = notification.data;
const data = await provider.getTransactionReceipt(transaction.hash);
const transactionReceipt = await provider.waitForTransaction(
transaction.hash
);
const updatedTransactions = [...notifications];

if (data?.status === "REJECTED" || data?.status === "REVERTED") {
if (
transactionReceipt.isRejected() ||
transactionReceipt.isReverted() ||
transactionReceipt.isError()
) {
updatedTransactions[index].data.status = "error";
updatedTransactions[index].data.txStatus = "REJECTED";
transactionReceipt.match({
rejected: (txR: RejectedTransactionReceiptResponse) => {
updatedTransactions[index].data.txStatus = txR.status;
},
reverted: (txR: RevertedTransactionReceiptResponse) => {
updatedTransactions[index].data.txStatus = txR.status;
},
error: (err: Error) => {
console.log("Error while fetching transaction receipt", err);
updatedTransactions[index].data.txStatus = undefined;
},
success: () => {},
});
setNotifications(updatedTransactions);
} else if (
data?.status === "ACCEPTED_ON_L2" ||
data?.status === "ACCEPTED_ON_L1" ||
data?.finality_status === "ACCEPTED_ON_L2" ||
data?.finality_status === "ACCEPTED_ON_L1"
) {
} else if (transactionReceipt.isSuccess()) {
updatedTransactions[index].data.txStatus =
data?.status ?? data?.finality_status;
transactionReceipt.finality_status;
updatedTransactions[index].data.status = "success";
setNotifications(updatedTransactions);
}
Expand Down
Loading

0 comments on commit 5cc87db

Please sign in to comment.