Skip to content

Commit

Permalink
refactor: buidl components
Browse files Browse the repository at this point in the history
  • Loading branch information
marthendalnunes committed Dec 1, 2023
1 parent 684dc84 commit e8646c7
Show file tree
Hide file tree
Showing 73 changed files with 801 additions and 396 deletions.
14 changes: 14 additions & 0 deletions apps/www/__registry__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ export const Index: Record<string, any> = {
component: React.lazy(() => import("@/registry/default/buidl/erc721/erc721-metadata")),
files: ["registry/default/buidl/erc721/erc721-metadata.tsx"],
},
"error-message": {
name: "error-message",
type: "components:buidl",
registryDependencies: undefined,
component: React.lazy(() => import("@/registry/default/buidl/error-message")),
files: ["registry/default/buidl/error-message.tsx"],
},
"nonce-demo": {
name: "nonce-demo",
type: "components:example",
Expand Down Expand Up @@ -439,5 +446,12 @@ export const Index: Record<string, any> = {
component: React.lazy(() => import("@/registry/default/example/erc721-metadata-demo")),
files: ["registry/default/example/erc721-metadata-demo.tsx"],
},
"error-message-demo": {
name: "error-message-demo",
type: "components:example",
registryDependencies: ["error-message"],
component: React.lazy(() => import("@/registry/default/example/error-message-demo")),
files: ["registry/default/example/error-message-demo.tsx"],
},
},
}
10 changes: 10 additions & 0 deletions apps/www/config/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,15 @@ export const docsConfig: DocsConfig = {
},
],
},
{
title: "Miscellaneous",
items: [
{
title: "Error Message",
href: "/docs/components/error-message",
items: [],
},
],
},
],
}
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/balance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/block-number.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/blockie.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ wagmi:
npm add ethereum-blockies-base64
```

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="blockie" />
Expand Down
1 change: 1 addition & 0 deletions apps/www/content/docs/components/ens-address.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wagmi:
<Step>Install the following components:</Step>

- [Address](/docs/components/address)
- [ErrorMessage](/docs/components/error-message)

<Step>Copy and paste the following code into your project.</Step>

Expand Down
1 change: 1 addition & 0 deletions apps/www/content/docs/components/ens-name.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wagmi:
<Step>Install the following components:</Step>

- [Address](/docs/components/address)
- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)

<Step>Copy and paste the following code into your project.</Step>

Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc20-balance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc20-decimals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc20-name.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc20-symbol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc20-total-supply.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc721-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
8 changes: 8 additions & 0 deletions apps/www/content/docs/components/erc721-name.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="erc721-name" />
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc721-owner-of.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc721-symbol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc721-token-uri.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/erc721-total-supply.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
56 changes: 56 additions & 0 deletions apps/www/content/docs/components/error-message.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Error Message
description: Generic error message component.
component: true
---

<ComponentPreview
name="error-message-demo"
className="[&_.preview>[data-orientation=vertical]]:sm:max-w-[70%]"
/>

## Installation

<Tabs defaultValue="manual">

<TabsList>
<TabsTrigger value="manual">Manual</TabsTrigger>
<TabsTrigger disabled={true} value="cli">
CLI (Coming Soon)
</TabsTrigger>
</TabsList>

<TabsContent value="cli">

<Steps>

<Step>Coming soon...</Step>

</Steps>

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="error-message" />

</Steps>

</TabsContent>

</Tabs>

## Usage

```tsx
import { EnsName } from "@/components/buidl/error-message"
```

```tsx
<EnsName />
<EnsName address="0x0000000000000000000000000000000000000000" />
```
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/fee-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
8 changes: 8 additions & 0 deletions apps/www/content/docs/components/image-ipfs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="image-ipfs" />
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/nonce.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
8 changes: 8 additions & 0 deletions apps/www/content/docs/components/transaction-status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="transaction-status" />
Expand Down
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/transaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ wagmi:

<Steps>

<Step>Install the following components:</Step>

- [ErrorMessage](/docs/components/error-message)

<Step>Install the following shadcn/ui components:</Step>

- [Skeleton](https://ui.shadcn.com/docs/components/skeleton)
Expand Down
10 changes: 10 additions & 0 deletions apps/www/public/registry/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,15 @@
],
"folder": "erc721",
"type": "components:buidl"
},
{
"name": "error-message",
"dependencies": [
"wagmi"
],
"files": [
"buidl/error-message.tsx"
],
"type": "components:buidl"
}
]
2 changes: 1 addition & 1 deletion apps/www/public/registry/styles/default/balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
{
"name": "balance.tsx",
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useAccount, useBalance, type Address } from \"wagmi\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Skeleton } from \"@/registry/default/ui/skeleton\"\n\ninterface BalanceProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n address?: Address\n chainId?: number\n decimals?: number\n displayLoading?: boolean\n displayError?: boolean\n}\n\nfunction trimFormattedBalance(balance: string | undefined, decimals = 4) {\n if (!balance) {\n return \"0\"\n }\n const [integer, decimal] = balance.split(\".\")\n if (!decimal) return integer\n\n const trimmedDecimal = decimal.slice(0, decimals)\n return `${integer}.${trimmedDecimal}`\n}\n\nconst ErrorMessage = ({ error }: { error: Error | null }) => {\n return (\n <div className={cn(\"break-words text-sm font-medium text-red-500\")}>\n {error?.message ?? \"Error while fetching fee data\"}\n </div>\n )\n}\n\nconst Balance = React.forwardRef<HTMLDivElement, BalanceProps>(\n (\n {\n address,\n chainId,\n className,\n decimals = 4,\n displayError = true,\n displayLoading = true,\n ...props\n },\n ref\n ) => {\n const { address: connectedAddress } = useAccount()\n\n const selectedAddress = address ? address : connectedAddress\n\n const { data, isLoading, isSuccess, isError, error } = useBalance({\n chainId,\n address: selectedAddress,\n })\n\n if ((isLoading && displayLoading) || !selectedAddress)\n return <Skeleton className={cn(\"h-6 w-24\", className)} {...props} />\n\n if (isError && displayError) return <ErrorMessage error={error} />\n\n if (isSuccess) {\n return (\n <div ref={ref} className={className} {...props}>\n {trimFormattedBalance(data?.formatted, decimals)}\n </div>\n )\n }\n\n return null\n }\n)\n\nBalance.displayName = \"Balance\"\n\nexport { Balance }\n"
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useAccount, useBalance, type Address } from \"wagmi\"\n\nimport { cn } from \"@/lib/utils\"\nimport { ErrorMessage } from \"@/registry/default/buidl/error-message\"\nimport { Skeleton } from \"@/registry/default/ui/skeleton\"\n\ninterface BalanceProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n address?: Address\n chainId?: number\n decimals?: number\n displayLoading?: boolean\n displayError?: boolean\n}\n\nfunction trimFormattedBalance(balance: string | undefined, decimals = 4) {\n if (!balance) {\n return \"0\"\n }\n const [integer, decimal] = balance.split(\".\")\n if (!decimal) return integer\n\n const trimmedDecimal = decimal.slice(0, decimals)\n return `${integer}.${trimmedDecimal}`\n}\n\nconst Balance = React.forwardRef<HTMLDivElement, BalanceProps>(\n (\n {\n address,\n chainId,\n className,\n decimals = 4,\n displayError = true,\n displayLoading = true,\n ...props\n },\n ref\n ) => {\n const { address: connectedAddress } = useAccount()\n\n const selectedAddress = address ? address : connectedAddress\n\n const { data, isLoading, isSuccess, isError, error } = useBalance({\n chainId,\n address: selectedAddress,\n })\n\n if ((isLoading && displayLoading) || !selectedAddress)\n return <Skeleton className={cn(\"h-6 w-24\", className)} {...props} />\n\n if (isError && displayError)\n return (\n <ErrorMessage\n ref={ref}\n error={error}\n defaultErrorMessage=\"Error while fetching fee data\"\n {...props}\n />\n )\n\n if (isSuccess) {\n return (\n <div ref={ref} className={className} {...props}>\n {trimFormattedBalance(data?.formatted, decimals)}\n </div>\n )\n }\n\n return null\n }\n)\n\nBalance.displayName = \"Balance\"\n\nexport { Balance }\n"
}
],
"type": "components:buidl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
{
"name": "block-explorer-link.tsx",
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Chain, useNetwork, type Address } from \"wagmi\"\nimport { mainnet } from \"wagmi/chains\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface BlockExplorerLinkProps\n extends React.HTMLAttributes<HTMLAnchorElement> {\n chain?: Chain\n data: Address | undefined\n showBlockExplorerName?: boolean\n type?: \"address\" | \"tx\"\n}\n\nconst BlockExplorerLink = React.forwardRef<\n HTMLAnchorElement,\n BlockExplorerLinkProps\n>(\n (\n {\n chain: selectedChain,\n data,\n children,\n className,\n showBlockExplorerName,\n type = \"address\",\n ...props\n },\n ref\n ) => {\n const { chain: currentChain } = useNetwork()\n\n // Use mainnet as default chain\n const chain =\n selectedChain ?? (currentChain && !currentChain.unsupported)\n ? currentChain\n : mainnet\n const blockExplorer = chain?.blockExplorers?.default\n\n if (!data || !blockExplorer) return null\n\n return (\n <a\n ref={ref}\n className={cn(\n \"overflow-x-auto font-medium underline-offset-2 hover:underline\",\n className\n )}\n href={`${blockExplorer.url}/${type}/${data}`}\n rel=\"noreferrer\"\n target=\"_blank\"\n {...props}\n >\n {showBlockExplorerName ? blockExplorer.name : children ?? data}\n </a>\n )\n }\n)\n\nBlockExplorerLink.displayName = \"BlockExplorerLink\"\n\nexport { BlockExplorerLink }\n"
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useNetwork, type Address, type Chain } from \"wagmi\"\nimport { mainnet } from \"wagmi/chains\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface BlockExplorerLinkProps\n extends React.HTMLAttributes<HTMLAnchorElement> {\n chain?: Chain\n data: Address | undefined\n showBlockExplorerName?: boolean\n type?: \"address\" | \"tx\"\n}\n\nconst BlockExplorerLink = React.forwardRef<\n HTMLAnchorElement,\n BlockExplorerLinkProps\n>(\n (\n {\n chain: selectedChain,\n data,\n children,\n className,\n showBlockExplorerName,\n type = \"address\",\n ...props\n },\n ref\n ) => {\n const { chain: currentChain } = useNetwork()\n\n // Use mainnet as default chain\n const chain =\n selectedChain ?? (currentChain && !currentChain.unsupported)\n ? currentChain\n : mainnet\n const blockExplorer = chain?.blockExplorers?.default\n\n if (!data || !blockExplorer) return null\n\n return (\n <a\n ref={ref}\n className={cn(\n \"overflow-x-auto font-medium underline-offset-2 hover:underline\",\n className\n )}\n href={`${blockExplorer.url}/${type}/${data}`}\n rel=\"noreferrer\"\n target=\"_blank\"\n {...props}\n >\n {showBlockExplorerName ? blockExplorer.name : children ?? data}\n </a>\n )\n }\n)\n\nBlockExplorerLink.displayName = \"BlockExplorerLink\"\n\nexport { BlockExplorerLink }\n"
}
],
"type": "components:buidl"
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/registry/styles/default/block-number.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
{
"name": "block-number.tsx",
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useBlockNumber } from \"wagmi\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Skeleton } from \"@/registry/default/ui/skeleton\"\n\ninterface BlockNumberProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n chainId?: number\n displayLoading?: boolean\n displayError?: boolean\n}\n\nconst ErrorMessage = ({ error }: { error: Error | null }) => {\n return (\n <div className={cn(\"break-words text-sm font-medium text-red-500\")}>\n {error?.message ?? \"Error while fetching block number data\"}\n </div>\n )\n}\n\nconst BlockNumber = React.forwardRef<HTMLDivElement, BlockNumberProps>(\n (\n {\n chainId,\n className,\n displayError = true,\n displayLoading = true,\n ...props\n },\n ref\n ) => {\n const { data, isLoading, isSuccess, isError, error } = useBlockNumber({\n chainId,\n })\n\n if (isLoading && displayLoading)\n return <Skeleton className={cn(\"h-6 w-24\", className)} {...props} />\n\n if (isError && displayError) return <ErrorMessage error={error} />\n\n if (isSuccess) {\n return (\n <div ref={ref} className={className} {...props}>\n {data?.toString()}\n </div>\n )\n }\n\n return null\n }\n)\n\nBlockNumber.displayName = \"BlockNumber\"\n\nexport { BlockNumber }\n"
"content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useBlockNumber } from \"wagmi\"\n\nimport { cn } from \"@/lib/utils\"\nimport { ErrorMessage } from \"@/registry/default/buidl/error-message\"\nimport { Skeleton } from \"@/registry/default/ui/skeleton\"\n\ninterface BlockNumberProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n chainId?: number\n displayLoading?: boolean\n displayError?: boolean\n}\n\nconst BlockNumber = React.forwardRef<HTMLDivElement, BlockNumberProps>(\n (\n {\n chainId,\n className,\n displayError = true,\n displayLoading = true,\n ...props\n },\n ref\n ) => {\n const { data, isLoading, isSuccess, isError, error } = useBlockNumber({\n chainId,\n })\n\n if (isLoading && displayLoading)\n return <Skeleton className={cn(\"h-6 w-24\", className)} {...props} />\n\n if (isError && displayError)\n return (\n <ErrorMessage\n defaultErrorMessage=\"Error while fetching block number data\"\n error={error}\n />\n )\n\n if (isSuccess) {\n return (\n <div ref={ref} className={className} {...props}>\n {data?.toString()}\n </div>\n )\n }\n\n return null\n }\n)\n\nBlockNumber.displayName = \"BlockNumber\"\n\nexport { BlockNumber }\n"
}
],
"type": "components:buidl"
Expand Down
Loading

0 comments on commit e8646c7

Please sign in to comment.