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

Improve codebase consistency and bump dependencies #4

Merged
merged 4 commits into from
Dec 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 163 additions & 116 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bonfida/sns-widget",
"version": "0.0.3",
"version": "0.0.4",
"description": "SNS Widget for 3rd-party apps for quick domain search and register",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,10 +37,10 @@
"analyse": "vite-bundle-visualizer"
},
"peerDependencies": {
"@pythnetwork/client": "^2.19.0",
"@solana/wallet-adapter-react": "^0.15",
"@solana/wallet-adapter-react-ui": "^0.9",
"@solana/wallet-adapter-wallets": "^0.19.23",
"@pythnetwork/client": "^2.19.0",
"@solana/web3.js": "^1.87.6",
"react": "^18",
"react-dom": "^18"
Expand All @@ -50,37 +50,37 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@types/react": "^18.2.41",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vitejs/plugin-react": "^4.2.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.54.0",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"eslint-plugin-react-refresh": "^0.4.5",
"gh-pages": "^6.1.0",
"postcss": "^8.4.31",
"postcss": "^8.4.32",
"prettier": "3.1.0",
"tailwind-merge": "^2.0.0",
"tailwind-merge": "^2.1.0",
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vite": "^4.5.0",
"vite-bundle-visualizer": "^0.11.0",
"vite-plugin-dts": "^3.6.3",
"vite-plugin-node-polyfills": "^0.16.0"
"vite-plugin-dts": "^3.6.4",
"vite-plugin-node-polyfills": "^0.17.0"
},
"dependencies": {
"@bonfida/emojis": "^1.0.1",
"@bonfida/spl-name-service": "2.0.0-alpha.23",
"@bonfida/emojis": "^1.0.2",
"@bonfida/sns-react": "^2.0.2",
"@bonfida/spl-name-service": "2.0.1",
"@pythnetwork/client": "^2.19.0",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-react-ui": "^0.9.34",
"@solana/wallet-adapter-react": "^0.15",
"@solana/wallet-adapter-react-ui": "^0.9",
"@solana/wallet-adapter-wallets": "^0.19.23",
"@solana/web3.js": "^1.87.6",
"ahooks": "^3.7.8",
"react-async-hook": "^4.0.0",
"split-graphemes": "^0.5.0"
"react-async-hook": "^4.0.0"
},
"volta": {
"node": "20.9.0"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions preview-build/assets/punycode-06c60053.js

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions preview-build/assets/solanaEmbed.esm-47ad5150.js

Large diffs are not rendered by default.

110 changes: 0 additions & 110 deletions preview-build/assets/solanaEmbed.esm-f41f2732.js

This file was deleted.

9 changes: 0 additions & 9 deletions preview-build/assets/widget-93dd4fab.js

This file was deleted.

12 changes: 12 additions & 0 deletions preview-build/assets/widget-e5024a77.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion preview-build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<title>SNS Registration Widget</title>
<script type="module" crossorigin src="/sns-widget/assets/index-fa8ce1ea.js"></script>
<script type="module" crossorigin src="/sns-widget/assets/index-f54a1fc2.js"></script>
<link rel="stylesheet" href="/sns-widget/assets/index-1ee6beac.css">
</head>
<body>
Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/domain-search-result-row.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { twMerge } from "tailwind-merge";
import { getDomainPriceFromName } from "@bonfida/spl-name-service";
import { ShoppingBasketHorizontal, TrashBent, Tick } from "../components/icons";
import { useContext, useEffect, useState } from "react";
import { CartContext } from "../contexts/cart";
import { DomainCardBase } from "./domain-card-base";
import { priceFromLength } from "../utils";

export const DomainSearchResultRow = ({
domain,
available = false,
Expand All @@ -15,7 +14,7 @@ export const DomainSearchResultRow = ({
price?: number;
}) => {
const { cart, addToCart, removeFromCart } = useContext(CartContext);
price = price ?? priceFromLength(domain);
price = price ?? getDomainPriceFromName(domain);
const isInCart = Boolean(cart[domain]);

const [showRemoveButton, toggleRemoveButton] = useState(isInCart);
Expand Down
2 changes: 0 additions & 2 deletions src/lib/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from "./useSearch";
export * from "./useDomainSuggestions";
export * from "./usePyth";
export * from "./useWalletBalances";
36 changes: 0 additions & 36 deletions src/lib/hooks/useDomainSuggestions.ts

This file was deleted.

68 changes: 0 additions & 68 deletions src/lib/hooks/useSearch.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/lib/types/split-graphemes.d.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/lib/utils/price.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
import { splitGraphemes } from "split-graphemes";

export const priceFromLength = (name: string, discountMultiplier = 1) => {
const split: string[] = splitGraphemes(name);
const length = split.length;
switch (length) {
case 1:
return 750 * discountMultiplier;
case 2:
return 700 * discountMultiplier;
case 3:
return 640 * discountMultiplier;
case 4:
return 160 * discountMultiplier;
default:
return 20 * discountMultiplier;
}
};

const formatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/views/cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../../components/icons";
import { twMerge } from "tailwind-merge";
import { NATIVE_MINT, getAssociatedTokenAddressSync } from "@solana/spl-token";
import { getDomainPriceFromName } from "@bonfida/spl-name-service";
import {
PublicKey,
Transaction,
Expand All @@ -22,7 +23,6 @@ import { BaseModal } from "../../components/modal";
import {
tokenList,
FIDA_MINT,
priceFromLength,
formatPrice,
wrapSol,
unwrapSol,
Expand Down Expand Up @@ -72,7 +72,7 @@ export const CartView = ({ backHandler }: CartViewProps) => {
const isSelectedTokenFIDA = selectedToken.mintAddress === FIDA_MINT;
const discountMul = isSelectedTokenFIDA ? 0.95 : 1;
const totalUsd = Object.values(cart).reduce(
(acc, v) => acc + priceFromLength(v.domain, discountMul),
(acc, v) => acc + getDomainPriceFromName(v.domain) * discountMul,
0,
);

Expand Down
11 changes: 7 additions & 4 deletions src/lib/views/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useContext,
type CSSProperties,
} from "react";
import { useSearch, useDomainSuggestions } from "@bonfida/sns-react";
import { InputField } from "../components/input-field";
import { Discord, ExternalLink, SearchShort } from "../components/icons";
import { twMerge } from "tailwind-merge";
Expand All @@ -14,9 +15,7 @@ import { CustomButton } from "../components/button";
import { FidaLogo } from "../components/fida-logo";
import { CartView } from "./cart";
import { useWalletPassThrough } from "../contexts/wallet-passthrough-provider";
import { useSearch } from "../hooks/useSearch";
import { sanitize } from "../utils";
import { useDomainSuggestions } from "../hooks/useDomainSuggestions";
import { ConnectWalletButton } from "../components/connect-wallet-button";
import { GlobalStatusCard } from "../components/global-status";
import { GlobalStatusContext } from "../contexts/status-messages";
Expand All @@ -37,6 +36,7 @@ export const WidgetHome = ({
connected,
setVisible,
visible: isWalletSelectorVisible,
connection,
} = useWalletPassThrough();
const [currentView, setCurrentView] = useState<Views>("home");
const [finished, toggleTransitionFinish] = useState(false);
Expand All @@ -45,8 +45,11 @@ export const WidgetHome = ({
const [searchQuery, setSearchQuery] = useState("");
const { isCartEmpty } = useContext(CartContext);
const { status } = useContext(GlobalStatusContext);
const domains = useSearch(searchQuery);
const suggestions = useDomainSuggestions(searchQuery);
const domains = useSearch({ connection: connection!, domain: searchQuery });
const suggestions = useDomainSuggestions({
connection: connection!,
domain: searchQuery,
});
const [timeoutId, setTimeoutId] = useState<ReturnType<
typeof setTimeout
> | null>(null);
Expand Down
Loading