From 8d360abfaf9711be5a218673f0b21819efb39580 Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Wed, 12 Jun 2024 18:25:11 -0700 Subject: [PATCH 1/3] chore: release --- .changeset/spicy-pears-attend.md | 5 +++++ CHANGELOG.md | 6 +++--- package.json | 2 +- src/swap/index.ts | 6 ++++++ src/swap/types.ts | 6 ++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .changeset/spicy-pears-attend.md diff --git a/.changeset/spicy-pears-attend.md b/.changeset/spicy-pears-attend.md new file mode 100644 index 0000000000..37e4b4ef6e --- /dev/null +++ b/.changeset/spicy-pears-attend.md @@ -0,0 +1,5 @@ +--- +"@coinbase/onchainkit": patch +--- + +- **feat**: exported `Swap` components. By @zizzamia diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c23164f8..64b717803c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,14 @@ ### Patch Changes -- 9fef5e9: - **feat**: added `Swap` component. By @abcrane123 & @kyhyco #522 +- **feat**: added `Swap` component. By @abcrane123 & @kyhyco #522 9fef5e9 ## 0.20.1 ### Patch Changes -- ccb069e: - **feat**: added `buildSwapTransaction`. By @0xAlec & @zizzamia #503 #518 - - **fix**: added tailwind utilities to exported styles.css. By @kyhyco #515 +- **feat**: added `buildSwapTransaction`. By @0xAlec & @zizzamia #503 #518 ccb069e +- **fix**: added tailwind utilities to exported styles.css. By @kyhyco #515 ## 0.20.0 diff --git a/package.json b/package.json index 84d2014251..a7a987aa9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coinbase/onchainkit", - "version": "0.20.2", + "version": "0.20.3", "type": "module", "repository": "https://github.com/coinbase/onchainkit.git", "license": "MIT", diff --git a/src/swap/index.ts b/src/swap/index.ts index d56f333e70..4c699827c8 100644 --- a/src/swap/index.ts +++ b/src/swap/index.ts @@ -1,11 +1,17 @@ // 🌲☀️🌲 +export { Swap } from './components/Swap'; +export { SwapAmountInput } from './components/SwapAmountInput'; +export { SwapButton } from './components/SwapButton'; +export { buildSwapTransaction } from './core/buildSwapTransaction'; export { getSwapQuote } from './core/getSwapQuote'; export type { BuildSwapTransactionParams, BuildSwapTransactionResponse, GetSwapQuoteParams, GetSwapQuoteResponse, + SwapReact, SwapAmountInputReact, + SwapButtonReact, SwapError, SwapTransaction, } from './types'; diff --git a/src/swap/types.ts b/src/swap/types.ts index b60ab3f295..af9b4b676e 100644 --- a/src/swap/types.ts +++ b/src/swap/types.ts @@ -105,6 +105,9 @@ export type SwapAPIResponse = { tx: RawTransactionData; // The trade transaction }; +/** + * Note: exported as public Type + */ export type SwapButtonReact = { onError?: (error: SwapError) => void; onSubmit?: (swapTransaction: BuildSwapTransaction) => void; @@ -129,6 +132,9 @@ export type SwapParams = { to: Token; }; +/** + * Note: exported as public Type + */ export type SwapReact = { account: Account; children: ReactNode; From 4118aa3b7db193a9e7ceec93493f8d5f4a4ffcbf Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Wed, 12 Jun 2024 18:32:08 -0700 Subject: [PATCH 2/3] chore: release --- .changeset/spicy-pears-attend.md | 2 +- site/docs/pages/swap/types.mdx | 55 ++++++++++++++++++- src/frame/components/FrameMetadata.tsx | 20 +++---- src/frame/getFrameMessage.ts | 3 +- src/identity/components/Name.test.tsx | 2 +- src/identity/components/WithAvatarBadge.tsx | 4 +- src/identity/components/WithNameBadge.tsx | 2 +- src/swap/components/Swap.tsx | 4 +- src/swap/components/SwapAmountInput.test.tsx | 6 +- src/swap/components/SwapAmountInput.tsx | 4 +- src/swap/components/SwapButton.tsx | 2 +- src/swap/context.ts | 2 +- src/swap/core/getSwapQuote.ts | 4 +- src/swap/index.ts | 2 + src/swap/types.ts | 38 +++++++------ src/token/components/TextInput.tsx | 6 +- src/token/components/TokenChip.tsx | 4 +- src/token/components/TokenRow.tsx | 8 +-- src/token/components/TokenSelectButton.tsx | 6 +- .../neynar/frame/neynarFrameValidation.ts | 2 +- .../user/getCustodyAddressForFidNeynar.ts | 2 +- .../user/getVerifiedAddressesForFidNeynar.ts | 2 +- src/wallet/components/ConnectAccount.tsx | 2 +- src/wallet/isWalletASmartWallet.test.ts | 2 +- 24 files changed, 122 insertions(+), 62 deletions(-) diff --git a/.changeset/spicy-pears-attend.md b/.changeset/spicy-pears-attend.md index 37e4b4ef6e..ad01fc621c 100644 --- a/.changeset/spicy-pears-attend.md +++ b/.changeset/spicy-pears-attend.md @@ -2,4 +2,4 @@ "@coinbase/onchainkit": patch --- -- **feat**: exported `Swap` components. By @zizzamia +- **feat**: exported `Swap` components. By @zizzamia #530 diff --git a/site/docs/pages/swap/types.mdx b/site/docs/pages/swap/types.mdx index 163997b6b7..b20474166b 100644 --- a/site/docs/pages/swap/types.mdx +++ b/site/docs/pages/swap/types.mdx @@ -5,6 +5,50 @@ description: Glossary of Types in Swap components & utilities. # Types [Glossary of Types in Swap components & utilities.] +## `BuildSwapTransaction` + +```ts +type BuildSwapTransaction = { + approveTransaction?: SwapTransaction; // The approval transaction + fee: Fee; // The fee for the swap + quote: SwapQuote; // The quote for the swap + transaction: SwapTransaction; // The swap transaction + warning?: QuoteWarning; // The warning associated with the swap +}; +``` + +## `BuildSwapTransactionResponse` + +```ts +type BuildSwapTransactionResponse = BuildSwapTransaction | SwapError; +``` + +## `BuildSwapTransactionParams` + +```ts +type BuildSwapTransactionParams = GetSwapQuoteParams & { + fromAddress: Address; // The address of the user +}; +``` + +## `GetSwapQuoteParams` + +```ts +export type GetSwapQuoteParams = { + from: Token; // The source token for the swap + to: Token; // The destination token for the swap + amount: string; // The amount to be swapped + amountReference?: string; // The reference amount for the swap + isAmountInDecimals?: boolean; // Whether the amount is in decimals +}; +``` + +## `GetSwapQuoteResponse` + +```ts +export type GetSwapQuoteResponse = SwapQuote | SwapError; +``` + ## `SwapAmountInputReact` ```ts @@ -15,10 +59,19 @@ type SwapAmountInputReact = { }; ``` +## `SwapError` + +```ts +type SwapError = { + code: number; // The error code + error: string; // The error message +}; +``` + ## `SwapReact` ```ts -export type SwapReact = { +type SwapReact = { account: Account; // Ethereum account children: ReactNode; // Children components to render onError?: (error: SwapError) => void; // Callback when swap is unsuccessful diff --git a/src/frame/components/FrameMetadata.tsx b/src/frame/components/FrameMetadata.tsx index 5c80c39bb7..992d60c661 100644 --- a/src/frame/components/FrameMetadata.tsx +++ b/src/frame/components/FrameMetadata.tsx @@ -19,10 +19,10 @@ export function FrameMetadata({ state, wrapper: Wrapper = Fragment, }: FrameMetadataReact) { - const button1 = buttons && buttons[0]; - const button2 = buttons && buttons[1]; - const button3 = buttons && buttons[2]; - const button4 = buttons && buttons[3]; + const button1 = buttons?.[0]; + const button2 = buttons?.[1]; + const button3 = buttons?.[2]; + const button4 = buttons?.[3]; const postUrlToUse = postUrl || post_url; const refreshPeriodToUse = refreshPeriod || refresh_period; const imageSrc = typeof image === 'string' ? image : image.src; @@ -47,7 +47,7 @@ export function FrameMetadata({ {!!(button1 && !!button1.action) && ( )} - {!!(button1 && button1.target) && ( + {!!(button1?.target) && ( )} {!!(button1 && button1.action === 'tx' && button1.postUrl) && ( @@ -58,7 +58,7 @@ export function FrameMetadata({ {!!(button2 && !!button2.action) && ( )} - {!!(button2 && button2.target) && ( + {!!(button2?.target) && ( )} {!!(button2 && button2.action === 'tx' && button2.postUrl) && ( @@ -69,7 +69,7 @@ export function FrameMetadata({ {!!(button3 && !!button3.action) && ( )} - {!!(button3 && button3.target) && ( + {!!(button3?.target) && ( )} {!!(button3 && button3.action === 'tx' && button3.postUrl) && ( @@ -80,7 +80,7 @@ export function FrameMetadata({ {!!(button4 && !!button4.action) && ( )} - {!!(button4 && button4.target) && ( + {!!(button4?.target) && ( )} {!!(button4 && button4.action === 'tx' && button4.postUrl) && ( @@ -95,8 +95,8 @@ export function FrameMetadata({ {!!isOpenFrame && } - {!!isOpenFrame && accepts && accepts['xmtp'] && ( - + {!!isOpenFrame && accepts && accepts.xmtp && ( + )} {!!isOpenFrame && imageSrc && } diff --git a/src/frame/getFrameMessage.ts b/src/frame/getFrameMessage.ts index a990c0db71..cb50844cf4 100644 --- a/src/frame/getFrameMessage.ts +++ b/src/frame/getFrameMessage.ts @@ -46,13 +46,12 @@ async function getFrameMessage( isValid: true, message: response, }; - } else { + } // Security best practice, don't return anything if we can't validate the frame. return { isValid: false, message: undefined, }; - } } export { getFrameMessage }; diff --git a/src/identity/components/Name.test.tsx b/src/identity/components/Name.test.tsx index d95dfaa635..2a73cf557f 100644 --- a/src/identity/components/Name.test.tsx +++ b/src/identity/components/Name.test.tsx @@ -17,7 +17,7 @@ jest.mock('../getSlicedAddress', () => ({ getSlicedAddress: jest.fn(), })); -const mockSliceAddress = (addr: string) => addr.slice(0, 6) + '...' + addr.slice(-4); +const mockSliceAddress = (addr: string) => `${addr.slice(0, 6)}...${addr.slice(-4)}`; describe('OnchainAddress', () => { const testAddress = '0x1234567890abcdef1234567890abcdef12345678'; diff --git a/src/identity/components/WithAvatarBadge.tsx b/src/identity/components/WithAvatarBadge.tsx index 123b7c6ed6..0799cc489e 100644 --- a/src/identity/components/WithAvatarBadge.tsx +++ b/src/identity/components/WithAvatarBadge.tsx @@ -21,8 +21,8 @@ function WithAvatarBadgeInner({ children, address }: WithAvatarBadgeInnerReact) return (
{children} - {attestations && attestations[0] && ( -
+ {attestations?.[0] && ( +
diff --git a/src/identity/components/WithNameBadge.tsx b/src/identity/components/WithNameBadge.tsx index 3cc30c5245..47edfb91c5 100644 --- a/src/identity/components/WithNameBadge.tsx +++ b/src/identity/components/WithNameBadge.tsx @@ -21,7 +21,7 @@ function WithNameBadgeInner({ children, address }: WithNameBadgeInnerReact) { return (
{children} - {attestations && attestations[0] && ( + {attestations?.[0] && (
diff --git a/src/swap/components/Swap.tsx b/src/swap/components/Swap.tsx index 7cc2e7c873..d9580e6c22 100644 --- a/src/swap/components/Swap.tsx +++ b/src/swap/components/Swap.tsx @@ -94,8 +94,8 @@ export function Swap({ account, children, onError }: SwapReact) {