-
Notifications
You must be signed in to change notification settings - Fork 584
Add SwapWidget in SDK, add in dashboard, BuyWidget UI improvements #8044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
50c1a19
temp
MananTank c917607
screen cleanup
MananTank 751bd0a
add success and error screens
MananTank ce099a3
resolve todo
MananTank ad7daa8
UI improvements
MananTank 0b70ce8
Fix theme in select-sell ui
MananTank dbba64d
add JSdoc, export component
MananTank 2fe8436
add swap widget in public token page
MananTank 814acd6
padding changes
MananTank a630bc9
remove log
MananTank 8513839
fix knip lint
MananTank 7681650
show balance, show not enough balance error
MananTank a5011af
Fix notEnoughBalance
MananTank 3d7fd1e
use Sell/prepare when selling
MananTank ebf6eef
Save token selection and amounts when going back
MananTank 6fb8a4e
Merge branch 'main' into mnn/swap-ui
MananTank ae43ed5
Remove extra quote loading step
MananTank abf8eea
fix lint
MananTank 2f2f8de
UI tweaks
MananTank 8ff84b5
use quote when wallet is not connected
MananTank 9d17bdc
combine owned tokens and all tokens
MananTank ed5ce8a
update
MananTank b2d6429
Fix buy widget showing payment method selection screen
MananTank 2a78c45
ui improvements
MananTank 654cc82
show quote error message
MananTank 0349636
Add JSDoc, fix lint
MananTank 1d98c3e
improve fiat onramp ui
MananTank 8f75d50
ui updates in buy widget
MananTank 9cf8688
better switch ux, swap label
MananTank b3fe76a
move token selection to modal
MananTank 33fa31a
address comments
MananTank 0d2d39d
pass quote to callbacks, add events
MananTank 1405e11
add embed in chain, bridge page
MananTank f0c4fc8
cleanup
MananTank 43b06e1
add changeset
MananTank d87c23b
fix build
MananTank b1f23a2
update changeset version
MananTank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"thirdweb": minor | ||
--- | ||
|
||
Add `SwapWidget` component for swapping tokens using thirdweb Bridge | ||
|
||
```tsx | ||
<SwapWidget client={thirdwebClient} /> | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
"use client"; | ||
|
||
import { useTheme } from "next-themes"; | ||
import { useState } from "react"; | ||
import type { Chain, ThirdwebClient } from "thirdweb"; | ||
import { BuyWidget, SwapWidget } from "thirdweb/react"; | ||
import { | ||
reportAssetBuyCancelled, | ||
reportAssetBuyFailed, | ||
reportAssetBuySuccessful, | ||
reportTokenSwapCancelled, | ||
reportTokenSwapFailed, | ||
reportTokenSwapSuccessful, | ||
} from "@/analytics/report"; | ||
import { Button } from "@/components/ui/button"; | ||
import { cn } from "@/lib/utils"; | ||
import { parseError } from "@/utils/errorParser"; | ||
import { getSDKTheme } from "@/utils/sdk-component-theme"; | ||
|
||
export function BuyAndSwapEmbed(props: { | ||
client: ThirdwebClient; | ||
chain: Chain; | ||
tokenAddress: string | undefined; | ||
buyAmount: string | undefined; | ||
pageType: "asset" | "bridge" | "chain"; | ||
}) { | ||
const { theme } = useTheme(); | ||
const [tab, setTab] = useState<"buy" | "swap">("swap"); | ||
const themeObj = getSDKTheme(theme === "light" ? "light" : "dark"); | ||
return ( | ||
<div className="bg-card rounded-2xl border overflow-hidden flex flex-col"> | ||
<div className="flex gap-2.5 p-4 border-b border-dashed"> | ||
<TabButton | ||
label="Swap" | ||
onClick={() => setTab("swap")} | ||
isActive={tab === "swap"} | ||
/> | ||
<TabButton | ||
label="Buy" | ||
onClick={() => setTab("buy")} | ||
isActive={tab === "buy"} | ||
/> | ||
</div> | ||
|
||
{tab === "buy" && ( | ||
<BuyWidget | ||
amount={props.buyAmount || "1"} | ||
chain={props.chain} | ||
className="!rounded-2xl !w-full !border-none" | ||
title="" | ||
client={props.client} | ||
connectOptions={{ | ||
autoConnect: false, | ||
}} | ||
onError={(e) => { | ||
const errorMessage = parseError(e); | ||
if (props.pageType === "asset") { | ||
reportAssetBuyFailed({ | ||
assetType: "coin", | ||
chainId: props.chain.id, | ||
contractType: "DropERC20", | ||
error: errorMessage, | ||
}); | ||
} | ||
}} | ||
onCancel={() => { | ||
if (props.pageType === "asset") { | ||
reportAssetBuyCancelled({ | ||
assetType: "coin", | ||
chainId: props.chain.id, | ||
contractType: "DropERC20", | ||
}); | ||
} | ||
}} | ||
onSuccess={() => { | ||
if (props.pageType === "asset") { | ||
reportAssetBuySuccessful({ | ||
assetType: "coin", | ||
chainId: props.chain.id, | ||
contractType: "DropERC20", | ||
}); | ||
} | ||
}} | ||
theme={themeObj} | ||
tokenAddress={props.tokenAddress as `0x${string}`} | ||
paymentMethods={["card"]} | ||
/> | ||
)} | ||
|
||
{tab === "swap" && ( | ||
<SwapWidget | ||
client={props.client} | ||
theme={themeObj} | ||
className="!rounded-2xl !border-none !w-full" | ||
prefill={{ | ||
sellToken: { | ||
chainId: props.chain.id, | ||
tokenAddress: props.tokenAddress, | ||
}, | ||
buyToken: { | ||
chainId: props.chain.id, | ||
}, | ||
}} | ||
onError={(error, quote) => { | ||
const errorMessage = parseError(error); | ||
reportTokenSwapFailed({ | ||
errorMessage: errorMessage, | ||
buyTokenChainId: quote.intent.destinationChainId, | ||
buyTokenAddress: quote.intent.destinationTokenAddress, | ||
sellTokenChainId: quote.intent.originChainId, | ||
sellTokenAddress: quote.intent.originTokenAddress, | ||
pageType: props.pageType, | ||
}); | ||
}} | ||
onSuccess={(quote) => { | ||
reportTokenSwapSuccessful({ | ||
buyTokenChainId: quote.intent.destinationChainId, | ||
buyTokenAddress: quote.intent.destinationTokenAddress, | ||
sellTokenChainId: quote.intent.originChainId, | ||
sellTokenAddress: quote.intent.originTokenAddress, | ||
pageType: props.pageType, | ||
}); | ||
}} | ||
onCancel={(quote) => { | ||
reportTokenSwapCancelled({ | ||
buyTokenChainId: quote.intent.destinationChainId, | ||
buyTokenAddress: quote.intent.destinationTokenAddress, | ||
sellTokenChainId: quote.intent.originChainId, | ||
sellTokenAddress: quote.intent.originTokenAddress, | ||
pageType: props.pageType, | ||
}); | ||
}} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
function TabButton(props: { | ||
label: string; | ||
onClick: () => void; | ||
isActive: boolean; | ||
}) { | ||
return ( | ||
<Button | ||
onClick={props.onClick} | ||
className={cn( | ||
"rounded-full text-muted-foreground px-5 text-base bg-accent", | ||
props.isActive && "text-foreground border-foreground", | ||
)} | ||
variant="outline" | ||
> | ||
{props.label} | ||
</Button> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/dashboard/src/@/components/blocks/grid-pattern-embed-container.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GridPattern } from "@/components/ui/background-patterns"; | ||
|
||
export function GridPatternEmbedContainer(props: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<div className=" sm:flex sm:justify-center w-full sm:border sm:border-dashed sm:bg-accent/20 sm:py-12 rounded-lg overflow-hidden relative"> | ||
<GridPattern | ||
width={30} | ||
height={30} | ||
x={-1} | ||
y={-1} | ||
strokeDasharray={"4 2"} | ||
className="text-border dark:text-border/70 hidden lg:block" | ||
style={{ | ||
maskImage: | ||
"linear-gradient(to bottom right,white,transparent,transparent)", | ||
}} | ||
/> | ||
<div className="sm:w-[420px] z-10">{props.children}</div> | ||
</div> | ||
); | ||
} |
24 changes: 12 additions & 12 deletions
24
...pp/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/BuyFundsSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
"use client"; | ||
import { useTheme } from "next-themes"; | ||
import { defineChain, type ThirdwebClient } from "thirdweb"; | ||
import type { ThirdwebClient } from "thirdweb"; | ||
import type { ChainMetadata } from "thirdweb/chains"; | ||
import { BuyWidget } from "thirdweb/react"; | ||
import { getSDKTheme } from "@/utils/sdk-component-theme"; | ||
import { BuyAndSwapEmbed } from "@/components/blocks/BuyAndSwapEmbed"; | ||
import { GridPatternEmbedContainer } from "@/components/blocks/grid-pattern-embed-container"; | ||
import { defineDashboardChain } from "@/lib/defineDashboardChain"; | ||
|
||
export function BuyFundsSection(props: { | ||
chain: ChainMetadata; | ||
client: ThirdwebClient; | ||
}) { | ||
const { theme } = useTheme(); | ||
return ( | ||
<section className="flex flex-col gap-4 items-center justify-center"> | ||
<BuyWidget | ||
amount="0" | ||
// eslint-disable-next-line no-restricted-syntax | ||
chain={defineChain(props.chain.chainId)} | ||
<GridPatternEmbedContainer> | ||
<BuyAndSwapEmbed | ||
client={props.client} | ||
theme={getSDKTheme(theme === "dark" ? "dark" : "light")} | ||
// eslint-disable-next-line no-restricted-syntax | ||
chain={defineDashboardChain(props.chain.chainId, props.chain)} | ||
buyAmount={undefined} | ||
tokenAddress={undefined} | ||
pageType="chain" | ||
/> | ||
</section> | ||
</GridPatternEmbedContainer> | ||
); | ||
} |
48 changes: 0 additions & 48 deletions
48
...)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_components/PayEmbedSection.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.