Skip to content

Commit

Permalink
docs: added more info around Badge (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Apr 17, 2024
1 parent 75f309c commit df44687
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .changeset/funny-apricots-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@coinbase/onchainkit': minor
---

feat: add eas attestation to identity kit
- **feat**: added Ethereum Attestation `Badge` component to the Identity kit. By @kyhyco & @zizzamia #259 #289
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Patch Changes

- d61861f: - **feat**: added missing `address` and `transaction` field for `FrameValidationData` type. By @zizzamia & @SamuelLHuber #287
- **feat**: added missing `address` and `transaction` field for `FrameValidationData` type. By @zizzamia & @SamuelLHuber #287 d61861f

## 0.12.0

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<a href="https://onchainkit.xyz">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./site/docs/public/logo/v0-12.png">
<img alt="OnchainKit logo vibes" src="./site/docs/public/logo/v0-12.png" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="./site/docs/public/logo/v0-13.png">
<img alt="OnchainKit logo vibes" src="./site/docs/public/logo/v0-13.png" width="auto">
</picture>
</a>
</p>
Expand Down
10 changes: 6 additions & 4 deletions site/docs/pages/frame/frame-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Note: If you are using Next.js with App routing, it is recommended to use `getFr

## Usage

```tsx
:::code-group

```tsx [code]
import { FrameMetadata } from '@coinbase/onchainkit/frame';

export default function HomePage() {
Expand Down Expand Up @@ -44,9 +46,7 @@ export default function HomePage() {
}
```

## Returns

```html
```html [return html]
<meta name="fc:frame" content="vNext" />
<meta name="fc:frame:button:1" content="Tell me the story" />
<meta name="fc:frame:button:2" content="Link to Google" />
Expand All @@ -61,6 +61,8 @@ export default function HomePage() {
<meta name="fc:frame:post_url" content="https://zizzamia.xyz/api/frame" />
```

:::

## Props

[`FrameMetadataReact`](/frame/types#framemetadatareact)
40 changes: 28 additions & 12 deletions site/docs/pages/identity/avatar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,51 @@ When an ENS avatar is not available, it defaults to blue color avatar.

Address with an ENS avatar:

```tsx
:::code-group

```tsx [code]
import { Avatar } from '@coinbase/onchainkit/identity';
<Avatar address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1" />; // [!code focus]
```

```html [return html]
<img
loading="lazy"
width="32"
height="32"
decoding="async"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTAgMTEwIj48ZGVmcz48cmFkaWFsR3JhZGllbnQgaWQ9Imd6ciIgZ3JhZGllbnRUcmFuc2Zvcm09InRyYW5zbGF0ZSg2Ni40NTc4IDI0LjM1NzUpIHNjYWxlKDc1LjI5MDgpIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgcj0iMSIgY3g9IjAiIGN5PSIwJSI+PHN0b3Agb2Zmc2V0PSIxNS42MiUiIHN0b3AtY29sb3I9ImhzbCgyNDQsIDcxJSwgODglKSIgLz48c3RvcCBvZmZzZXQ9IjM5LjU4JSIgc3RvcC1jb2xvcj0iaHNsKDI0MSwgNzMlLCA4MSUpIiAvPjxzdG9wIG9mZnNldD0iNzIuOTIlIiBzdG9wLWNvbG9yPSJoc2woMjIzLCA3OCUsIDcwJSkiIC8+PHN0b3Agb2Zmc2V0PSI5MC42MyUiIHN0b3AtY29sb3I9ImhzbCgyMTcsIDkwJSwgNjAlKSIgLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9ImhzbCgyMTQsIDk1JSwgNTklKSIgLz48L3JhZGlhbEdyYWRpZW50PjwvZGVmcz48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSg1LDUpIj48cGF0aCBkPSJNMTAwIDUwQzEwMCAyMi4zODU4IDc3LjYxNDIgMCA1MCAwQzIyLjM4NTggMCAwIDIyLjM4NTggMCA1MEMwIDc3LjYxNDIgMjIuMzg1OCAxMDAgNTAgMTAwQzc3LjYxNDIgMTAwIDEwMCA3Ny42MTQyIDEwMCA1MFoiIGZpbGw9InVybCgjZ3pyKSIgLz48cGF0aCBzdHJva2U9InJnYmEoMCwwLDAsMC4wNzUpIiBmaWxsPSJ0cmFuc3BhcmVudCIgc3Ryb2tlLXdpZHRoPSIxIiBkPSJNNTAsMC41YzI3LjMsMCw0OS41LDIyLjIsNDkuNSw0OS41Uzc3LjMsOTkuNSw1MCw5OS41UzAuNSw3Ny4zLDAuNSw1MFMyMi43LDAuNSw1MCwwLjV6IiAvPjwvZz48L3N2Zz4="
alt="zizzamia.eth"
/>
```

:::

<App>
<Avatar address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1" />
</App>

Address without an ENS avatar, and it defaults to a blue color avatar:

```tsx
:::code-group

```tsx [code]
import { Avatar } from '@coinbase/onchainkit/identity';
<Avatar address="0x1234567890abcdef1234567890abcdef12345678" />; // [!code focus]
```

```html [return html]
<svg data-testid="avatar-default-svg" width="32" height="32" xmlns="http://www.w3.org/2000/svg">
<circle cx="16" cy="16" r="16" fill="blue"></circle>
</svg>
```

:::

<App>
<Avatar address="0x1234567890abcdef1234567890abcdef12345678" />
</App>

## Props

```ts
type UseAvatar = {
// Ethereum address to be resolved from ENS.
address: Address;
// Optional CSS class for custom styling.
className?: string;
// Additional HTML attributes for the span element.
props?: React.HTMLAttributes<HTMLSpanElement>;
};
```
[`AvatarReact`](/identity/types#AvatarReact)
52 changes: 38 additions & 14 deletions site/docs/pages/identity/name.mdx
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
import { Name } from '@coinbase/onchainkit/identity';
import App from './App';

# `<Name />`

The `Name` component is used to display ENS names associated with Ethereum addresses.
When an ENS name is not available, it defaults to showing a truncated version of the address.

## Usage

```tsx
Address with an ENS:

:::code-group

```tsx [code]
import { Name } from '@coinbase/onchainkit/identity';
<Name address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1" sliced={false} />; // [!code focus]
```

<Name address="0x1234567890abcdef1234567890abcdef12345678" sliced={false} />; // [!code focus]
```html [return html]
<span>zizzamia.eth</span>
```

## Props
:::

<App>
<Name address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1" />
</App>

Address without an ENS avatar, and it defaults to his sliced address:

:::code-group

```ts
type UseName = {
// Ethereum address to be resolved from ENS.
address: Address;
// Optional CSS class for custom styling.
className?: string;
// Determines if the address should be sliced when no ENS name is available.
sliced?: boolean;
// Additional HTML attributes for the span element.
props?: React.HTMLAttributes<HTMLSpanElement>;
};
```tsx [code]
import { Name } from '@coinbase/onchainkit/identity';
<Name address="0x1234567890abcdef1234567890abcdef12345678" />; // [!code focus]
```

```html [return html]
<span>0x123...5678</span>
```

:::

<App>
<Name address="0x1234567890abcdef1234567890abcdef12345678" />
</App>

## Props

[`NameReact`](/identity/types#NameReact)
29 changes: 27 additions & 2 deletions site/docs/pages/identity/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ deescription: Glossary of Types in Identity Kit.

# Types [Glossary of Types in Identity Kit.]

## `AvatarReact`

```ts
type AvatarReact = {
address: Address; // The Ethereum address to fetch the avatar for.
className?: string; // Optional additional CSS class to apply to the avatar.
loadingComponent?: JSX.Element; // Optional custom component to display while the avatar data is loading.
defaultComponent?: JSX.Element; // Optional custom component to display when no ENS name or avatar is available.
props?: React.ImgHTMLAttributes<HTMLImageElement>; // Optional additional image attributes to apply to the avatar.
showAttestation?: boolean; // Optional flag to show the EAS attestation badge.
};
```

## `EASSchemaUid`

```ts
Expand Down Expand Up @@ -41,11 +54,23 @@ type GetEASAttestationsOptions = {
## `GetAvatarReturnType`

```ts
export type GetAvatarReturnType = string | null;
type GetAvatarReturnType = string | null;
```

## `GetNameReturnType`

```ts
export type GetNameReturnType = string | null;
type GetNameReturnType = string | null;
```

## `NameReact`

```ts
type NameReact = {
address: Address; // Ethereum address to be displayed.
className?: string; // Optional CSS class for custom styling.
props?: React.HTMLAttributes<HTMLSpanElement>; // Additional HTML attributes for the span element.
showAttestation?: boolean; // Optional flag to show the EAS attestation badge.
sliced?: boolean; // Determines if the address should be sliced when no ENS name is available.
};
```
Binary file added site/docs/public/logo/v0-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"preview": "vocs preview"
},
"dependencies": {
"@coinbase/onchainkit": "0.11.1",
"@coinbase/onchainkit": "0.12.1",
"@tanstack/react-query": "^5.28.4",
"@types/react": "latest",
"graphql": "14",
Expand Down
14 changes: 7 additions & 7 deletions site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,18 @@ __metadata:
languageName: node
linkType: hard

"@coinbase/onchainkit@npm:0.11.1":
version: 0.11.1
resolution: "@coinbase/onchainkit@npm:0.11.1"
"@coinbase/onchainkit@npm:0.12.1":
version: 0.12.1
resolution: "@coinbase/onchainkit@npm:0.12.1"
peerDependencies:
"@tanstack/react-query": ^5
"@xmtp/frames-validator": ^0.5.0
"@xmtp/frames-validator": ^0.6.0
graphql: ^14 || ^15 || ^16
graphql-request: ^6
graphql-request: ^6.1.0
react: ^18
react-dom: ^18
viem: ^2.7.0
checksum: e40a9759333071fb979e9867a86b22f468c553ef0f3f1a1e7df187c1b14f0aaac284c6e3d0c10cc705f6ad31a84961109b922c3cb2f603225325be8b1d0a3e8c
checksum: c2503baca02a1152756d218950da5e37cfd77a515eda1940821ce274d50707a7cf25ca5faa12d3692640a8f01789c9be948304c44fdd007036d01d99b8184f81
languageName: node
linkType: hard

Expand Down Expand Up @@ -5312,7 +5312,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "onchainkit@workspace:."
dependencies:
"@coinbase/onchainkit": "npm:0.11.1"
"@coinbase/onchainkit": "npm:0.12.1"
"@tanstack/react-query": "npm:^5.28.4"
"@types/react": "npm:latest"
graphql: "npm:14"
Expand Down
41 changes: 41 additions & 0 deletions src/OnchainKitProvider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @jest-environment jsdom
*/
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';

import { EASSchemaUid } from './identity/types';
import { OnchainKitProvider } from './OnchainKitProvider';
import { useOnchainKit } from './useOnchainKit';

const TestComponent = () => {
const { identity } = useOnchainKit();
return <div>{identity.eas.schemaId}</div>;
};

describe('OnchainKitProvider', () => {
it('provides the context value correctly', async () => {
const schemaId: EASSchemaUid = `0x${'1'.repeat(64)}`;

render(
<OnchainKitProvider identity={{ easConfig: { schemaId } }}>
<TestComponent />
</OnchainKitProvider>,
);

await waitFor(() => {
expect(screen.getByText(schemaId)).toBeInTheDocument();
});
});

it('throws an error if schemaId does not meet the required length', () => {
expect(() =>
render(
<OnchainKitProvider identity={{ easConfig: { schemaId: '0x123' } }}>
<TestComponent />
</OnchainKitProvider>,
),
).toThrow('EAS schemaId must be 64 characters prefixed with "0x"');
});
});
45 changes: 45 additions & 0 deletions src/OnchainKitProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ReactNode, createContext, useMemo } from 'react';
import { Chain } from 'viem';
import { base } from 'viem/chains';

import { EASSchemaUid } from './identity/types';
import { checkHashLength } from './utils/checkHashLength';

type OnchainKitContextType = {
identity: {
eas: {
schemaId: EASSchemaUid;
chain: Chain;
};
};
};

export const OnchainKitContext = createContext<OnchainKitContextType | null>(null);

type OnchainKitProviderProps = {
identity: {
easConfig: {
schemaId: EASSchemaUid;
chain?: Chain;
};
};
children: ReactNode;
};

export function OnchainKitProvider({ identity: { easConfig }, children }: OnchainKitProviderProps) {
if (!checkHashLength(easConfig.schemaId, 64)) {
throw Error('EAS schemaId must be 64 characters prefixed with "0x"');
}
const value = useMemo(() => {
const { schemaId, chain = base } = easConfig;
return {
identity: {
eas: {
schemaId,
chain,
},
},
};
}, [easConfig]);
return <OnchainKitContext.Provider value={value}>{children}</OnchainKitContext.Provider>;
}
Loading

0 comments on commit df44687

Please sign in to comment.