Skip to content

Commit

Permalink
Backported improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Nov 1, 2024
1 parent d0c037b commit 583df60
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
8 changes: 2 additions & 6 deletions context/Web3Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { http, createConfig } from "wagmi";
import { injected } from "wagmi/connectors";
import { walletConnect, coinbaseWallet } from "wagmi/connectors";
import { walletConnect } from "wagmi/connectors";
import {
PUB_APP_DESCRIPTION,
PUB_APP_NAME,
Expand All @@ -10,7 +9,6 @@ import {
PUB_WALLET_ICON,
PUB_WEB3_ENDPOINT,
} from "@/constants";
import { mainnet } from "viem/chains";

// wagmi config
const metadata = {
Expand All @@ -21,18 +19,16 @@ const metadata = {
};

export const config = createConfig({
chains: [PUB_CHAIN, mainnet],
chains: [PUB_CHAIN],
ssr: true,
transports: {
[PUB_CHAIN.id]: http(PUB_WEB3_ENDPOINT, { batch: true }),
[mainnet.id]: http(PUB_WEB3_ENDPOINT, { batch: true }),
},
connectors: [
walletConnect({
projectId: PUB_WALLET_CONNECT_PROJECT_ID,
metadata,
showQrModal: false,
}),
// coinbaseWallet({ appName: metadata.name, appLogoUrl: metadata.icons[0] }),
],
});
2 changes: 1 addition & 1 deletion hooks/useIsContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useIsContract(address?: Address) {
refetchOnReconnect: false,
retryOnMount: true,
enabled: !!address && isAddress(address) && !!publicClient,
staleTime: Infinity,
staleTime: 1000 * 60 * 10,
});

return {
Expand Down
6 changes: 6 additions & 0 deletions utils/case.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Decodes a camel case string by adding spaces between words and capitalizing the first letter of each word.
*
* @param input - The camel case string to decode.
* @returns The decoded string.
*/
export function decodeCamelCase(input?: string): string {
if (!input || typeof input !== "string") return "";

Expand Down
12 changes: 6 additions & 6 deletions utils/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PUB_IPFS_ENDPOINTS, PUB_PINATA_JWT, PUB_APP_NAME } from "@/constants";
import { Hex, fromHex, toBytes } from "viem";
import { type Hex, fromHex, toBytes } from "viem";
import { CID } from "multiformats/cid";
import * as raw from "multiformats/codecs/raw";
import { sha256 } from "multiformats/hashes/sha2";

const IPFS_FETCH_TIMEOUT = 1000; // 1 second
const UPLOAD_FILE_NAME = PUB_APP_NAME.toLowerCase().trim().replaceAll(" ", "-") + ".json";
const IPFS_FETCH_TIMEOUT = 5000; // 1 second
const UPLOAD_FILE_NAME = `${PUB_APP_NAME.toLowerCase().trim().replaceAll(" ", "-")}.json`;

export function fetchIpfsAsJson(ipfsUri: string) {
return fetchRawIpfs(ipfsUri).then((res) => res.json());
Expand Down Expand Up @@ -37,16 +37,16 @@ export async function uploadToPinata(strBody: string) {

const resData = await res.json();

if (resData.error) throw new Error("Request failed: " + resData.error);
if (resData.error) throw new Error(`Request failed: ${resData.error}`);
else if (!resData.IpfsHash) throw new Error("Could not pin the metadata");
return "ipfs://" + resData.IpfsHash;
return `ipfs://${resData.IpfsHash}`;
}

export async function getContentCid(strMetadata: string) {
const bytes = raw.encode(toBytes(strMetadata));
const hash = await sha256.digest(bytes);
const cid = CID.create(1, raw.code, hash);
return "ipfs://" + cid.toV1().toString();
return `ipfs://${cid.toV1().toString()}`;
}

// Internal helpers
Expand Down
6 changes: 6 additions & 0 deletions utils/text.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Capitalizes the first letter of a string.
*
* @param str - The string to capitalize.
* @returns The string with the first letter capitalized.
*/
export function capitalizeFirstLetter(str: string) {
if (!str) return str; // Return the original string if it's empty or undefined
return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
Expand Down

0 comments on commit 583df60

Please sign in to comment.