Skip to content

Commit

Permalink
feat: Reuse hooks and utils
Browse files Browse the repository at this point in the history
- reuse `useSearch` and `useDomainsSuggestions` from `@bonfida/sns-react`
- reuse `getDomainPriceFromName` from `@bonfida/spl-name-service`
- bump dependencies
  • Loading branch information
letehaha authored and dr497 committed Dec 8, 2023
1 parent 839d0db commit 530ac02
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 197 deletions.
209 changes: 144 additions & 65 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"name": "sns-manager",
"version": "1.0.2",
"private": true,
"homepage": ".",
"scripts": {
Expand All @@ -25,8 +27,8 @@
"@bonfida/name-offers": "0.0.10",
"@bonfida/name-tokenizer": "0.0.12",
"@bonfida/sns-emitter": "0.1.7",
"@bonfida/sns-react": "2.0.1",
"@bonfida/spl-name-service": "1.0.7",
"@bonfida/sns-react": "2.0.2",
"@bonfida/spl-name-service": "2.0.3",
"@coral-xyz/common-public": "0.2.0-latest.3375",
"@expo-google-fonts/dev": "*",
"@expo/html-elements": "0.5.1",
Expand Down Expand Up @@ -77,7 +79,6 @@
"react-native-svg": "13.9.0",
"react-native-web": "~0.19.6",
"recoil": "*",
"split-graphemes": "0.5.0",
"twrnc": "*",
"use-latest-callback": "0.1.7"
},
Expand Down Expand Up @@ -105,7 +106,5 @@
"volta": {
"node": "20.9.0"
},
"prettier": "@bonfida/prettier-config",
"name": "sns-manager",
"version": "1.0.1"
"prettier": "@bonfida/prettier-config"
}
4 changes: 2 additions & 2 deletions src/components/DomainSearchResultRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { domainViewScreenProp } from "@src/types";
import { abbreviate } from "@src/utils/abbreviate";
import tw from "@src/utils/tailwind";
import { tokenIconBySymbol } from "@src/utils/tokens/popular-tokens";
import { priceFromLength } from "@src/utils/price/price-from-length";
import { getDomainPriceFromName } from "@bonfida/spl-name-service";
import { cartState } from "@src/atoms/cart";

export const DomainSearchResultRow = ({
Expand All @@ -21,7 +21,7 @@ export const DomainSearchResultRow = ({
}) => {
const [cart, setCart] = useRecoilState(cartState);
const inCart = cart.includes(domain);
price = price ?? priceFromLength(domain);
price = price ?? getDomainPriceFromName(domain);
const navigation = useNavigation<domainViewScreenProp>();

const handle = () => {
Expand Down
30 changes: 0 additions & 30 deletions src/hooks/useDomainSuggestions.tsx

This file was deleted.

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

This file was deleted.

6 changes: 3 additions & 3 deletions src/screens/Cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { cartState } from "@src/atoms/cart";
import { referrerState } from "@src/atoms/referrer";
import tw from "@src/utils/tailwind";
import { FIDA_MINT, tokenList } from "@src/utils/tokens/popular-tokens";
import { priceFromLength } from "@src/utils/price/price-from-length";
import { getDomainPriceFromName } from "@bonfida/spl-name-service";
import { wrapSol } from "@src/utils/tokens/wrap-sol";
import { unwrapSol } from "@src/utils/tokens/unwrap-sol";
import { chunkIx } from "@src/utils/tx/chunk-tx";
Expand Down Expand Up @@ -94,7 +94,7 @@ export const Cart = () => {

const discountMul = mint === FIDA_MINT ? 0.95 : 1;
const totalUsd = cart.reduce(
(acc, v) => acc + priceFromLength(v, discountMul),
(acc, v) => acc + getDomainPriceFromName(v) * discountMul,
0,
);

Expand Down Expand Up @@ -288,7 +288,7 @@ export const Cart = () => {
<Text
style={tw`text-sm font-medium text-content-primary`}
>
{priceFromLength(item)}
{getDomainPriceFromName(item)}
</Text>
</View>
<TouchableOpacity
Expand Down
12 changes: 8 additions & 4 deletions src/screens/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { useStatusModalContext } from "@src/contexts/StatusModalContext";
import tw from "@src/utils/tailwind";
import { trimTld, validate } from "@src/utils/validate";
import { isPubkey } from "@src/utils/publickey";
import { useSearch } from "@src/hooks/useSearch";
import { useDomainSuggestions } from "@src/hooks/useDomainSuggestions";
import { useSearch, useDomainSuggestions } from "@bonfida/sns-react";
import { useTopDomainsSales } from "@src/hooks/useTopDomainsSales";
import { Screen } from "@src/components/Screen";
import { CustomTextInput } from "@src/components/CustomTextInput";
import { UiButton } from "@src/components/UiButton";
import { DomainSearchResultRow } from "@src/components/DomainSearchResultRow";
import { useSolanaConnection } from "@src/hooks/xnft-hooks";

export const SearchResult = ({
domain,
Expand All @@ -24,12 +24,16 @@ export const SearchResult = ({
domain: string;
loadPopular?: boolean;
}) => {
const connection = useSolanaConnection();
const { currentModal } = useModal();
const { setStatus } = useStatusModalContext();
const [search, setSearch] = useState(domain || "");
const [input, setInput] = useState(domain || "");
const results = useSearch(search);
const suggestions = useDomainSuggestions(search);
const results = useSearch({ connection: connection!, domain: search });
const suggestions = useDomainSuggestions({
connection: connection!,
domain: search,
});
const navigation = useNavigation<profileScreenProp>();
const isFocused = useIsFocused();
const topDomainsSales = useTopDomainsSales(loadPopular);
Expand Down
19 changes: 0 additions & 19 deletions src/utils/price/price-from-length.tsx

This file was deleted.

0 comments on commit 530ac02

Please sign in to comment.