Skip to content
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

Solana UI support #273

Merged
merged 51 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b6c5b86
wip abstract evm logic and add support for svm in ui kit
pedromcunha Sep 12, 2024
6d442a5
Merge branch 'ted/relay-5705-create-a-solana-adapter-for-relaysdk' in…
pedromcunha Sep 12, 2024
f5fbfc1
wip: multi wallet ui
ted-palmer Sep 12, 2024
6ee563c
Abstract evm specific logic
pedromcunha Sep 12, 2024
c648971
Merge branch 'main' of https://github.com/reservoirprotocol/relay-kit…
ted-palmer Sep 12, 2024
8c8726b
Resolve conflicts
pedromcunha Sep 12, 2024
9f8a004
wip debugging solana ui support
pedromcunha Sep 12, 2024
10a47e1
Fix build errror
ted-palmer Sep 13, 2024
a397869
Upgrade dynamic to v3 and update integration
ted-palmer Sep 13, 2024
0d269f5
Fix dune balance bugs
pedromcunha Sep 13, 2024
e0c2c21
Resolve conflicts in demo
pedromcunha Sep 13, 2024
4790bc3
Remove test code
pedromcunha Sep 13, 2024
6a28206
Fix eth_balance issues when wallet is not evm
pedromcunha Sep 13, 2024
7d7f3d4
Display SOL in to chain, fix dune bug temporarily
pedromcunha Sep 13, 2024
4f67455
Add solana id to make it easier to read and maintain
pedromcunha Sep 13, 2024
e57c331
Add link wallet support in CustomAddressModal
pedromcunha Sep 16, 2024
cb9d601
Handle invalid wallet switching + cta ux
ted-palmer Sep 16, 2024
eb809fd
Show warning for SVM wallets that are not connected
pedromcunha Sep 16, 2024
330bdc3
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 16, 2024
679e5be
Fix address selection bug + filter our svm tokens if multiWallet is n…
ted-palmer Sep 16, 2024
426b32d
Add icons to wallet addresses in review step and selector
pedromcunha Sep 16, 2024
9e312ca
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 16, 2024
e8b0e99
Add icons to wallet addresses in review step and selector
pedromcunha Sep 16, 2024
19c4107
Fix icon bug in wallet dropdown
ted-palmer Sep 16, 2024
d45c4a3
Fix resetting of custom address bug + add generic wallet icon for pas…
ted-palmer Sep 17, 2024
809c9ea
Hide send ui
pedromcunha Sep 17, 2024
6b35721
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 17, 2024
6dc634a
Fix showing wallet icon when not selected
ted-palmer Sep 17, 2024
76c8fdf
Add walletFilter context
pedromcunha Sep 17, 2024
feaa395
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 17, 2024
6ca9d78
Fix wrapping of connected wallets in CustomAddressModal
pedromcunha Sep 17, 2024
3be8cd6
Fix bug with not connected address warning
pedromcunha Sep 17, 2024
e111c94
Remove hotpatch for dune solana balances
pedromcunha Sep 17, 2024
87eb5fe
Fix custom address modal ens lookup
pedromcunha Sep 17, 2024
d97f5e3
Fix build issue
pedromcunha Sep 17, 2024
30e5f66
Automatically switch primary and recipient based on context
pedromcunha Sep 17, 2024
83a9b03
Stying feedback
ted-palmer Sep 17, 2024
d33e198
Merge branch 'feature/solana-ui-support' of https://github.com/reserv…
ted-palmer Sep 17, 2024
8bbbe71
Handle disconnect ux and removing custom address
pedromcunha Sep 17, 2024
effae07
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 17, 2024
6e604bb
Resolve demo build errors
pedromcunha Sep 17, 2024
9d1993b
Remove comments
pedromcunha Sep 17, 2024
3488b13
Fix ens name display in widget
pedromcunha Sep 17, 2024
6b6531d
Update logic for max calculation to be based on native gas token
pedromcunha Sep 18, 2024
3df4769
Fix wallet connect issues when switching metamask accounts
pedromcunha Sep 18, 2024
9e395c6
Fix unit tests
pedromcunha Sep 18, 2024
cab139b
Switch from wallet icon to clipboard icon for pasted address
ted-palmer Sep 18, 2024
3e65687
Add events for tracking max button, currency step chain filter and sw…
pedromcunha Sep 18, 2024
3a483fb
Merge branch 'feature/solana-ui-support' of github.com:reservoirproto…
pedromcunha Sep 18, 2024
ff80b93
Handle non evm types when finding addresses in token selector
pedromcunha Sep 18, 2024
2c38afe
feat: changeset
pedromcunha Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fresh-dingos-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@reservoir0x/relay-kit-ui': major
'@reservoir0x/relay-sdk': patch
---

Add solana ui support in SwapWidget
33 changes: 33 additions & 0 deletions demo/context/walletFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { createContext, useContext, useState, ReactNode } from 'react'

interface WalletFilterContextState {
walletFilter?: 'EVM' | 'SOL'
setWalletFilter: (value: 'EVM' | 'SOL' | undefined) => void
}

const WalletFilterContext = createContext<WalletFilterContextState | undefined>(
undefined
)

export const WalletFilterProvider: React.FC<{ children: ReactNode }> = ({
children
}) => {
const [walletFilter, setWalletFilter] = useState<'EVM' | 'SOL' | undefined>(
undefined
)

return (
<WalletFilterContext.Provider value={{ walletFilter, setWalletFilter }}>
{children}
</WalletFilterContext.Provider>
)
}

// Custom hook to use the context
export const useWalletFilter = () => {
const context = useContext(WalletFilterContext)
if (!context) {
throw new Error('useWalletFilter must be used within a WalletFilterContext')
}
return context
}
10 changes: 5 additions & 5 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"trailingComma": "none"
},
"dependencies": {
"@dynamic-labs/ethereum": "^2.6.0",
"@dynamic-labs/sdk-react-core": "^2.6.0",
"@dynamic-labs/solana": "^2.6.0",
"@dynamic-labs/wagmi-connector": "^2.6.0",
"@dynamic-labs/ethereum": "3.0.0",
"@dynamic-labs/sdk-react-core": "3.0.0",
"@dynamic-labs/solana": "3.0.0",
"@dynamic-labs/wagmi-connector": "3.0.0",
"@radix-ui/colors": "^0.1.8",
"@reservoir0x/relay-kit-hooks": "workspace:*",
"@reservoir0x/relay-kit-ui": "workspace:*",
Expand All @@ -34,7 +34,7 @@
"wagmi": "~2.9.8"
},
"devDependencies": {
"@dynamic-labs/types": "^2.6.0",
"@dynamic-labs/types": "3.0.0",
"@types/node": "^12.12.21",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
Expand Down
32 changes: 25 additions & 7 deletions demo/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import {
} from '@reservoir0x/relay-sdk'
import { ThemeProvider } from 'next-themes'
import { useRouter } from 'next/router'
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core'
import {
DynamicContextProvider,
FilterChain
} from '@dynamic-labs/sdk-react-core'
import { EthereumWalletConnectors } from '@dynamic-labs/ethereum'
import { SolanaWalletConnectors } from '@dynamic-labs/solana'
import { convertRelayChainToDynamicNetwork } from 'utils/dynamic'
import { DynamicWagmiConnector } from '@dynamic-labs/wagmi-connector'
import { HttpTransport } from 'viem'
import { chainIdToAlchemyNetworkMap } from 'utils/chainIdToAlchemyNetworkMap'
import { useWalletFilter, WalletFilterProvider } from 'context/walletFilter'

type AppWrapperProps = {
children: ReactNode
Expand All @@ -32,6 +36,7 @@ const ALCHEMY_API_KEY = process.env.NEXT_PUBLIC_ALCHEMY_KEY || ''
const queryClient = new QueryClient()

const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
const { walletFilter, setWalletFilter } = useWalletFilter()
const [wagmiConfig, setWagmiConfig] = useState<
ReturnType<typeof createConfig> | undefined
>()
Expand Down Expand Up @@ -153,6 +158,12 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
EthereumWalletConnectors,
SolanaWalletConnectors
],
cssOverrides: `
[data-testid="send-balance-button"] {
display: none;
}
`,
walletsFilter: walletFilter ? FilterChain(walletFilter) : undefined,
overrides: {
evmNetworks: () => {
return (
Expand All @@ -165,7 +176,12 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
)
}
},
initialAuthenticationMode: 'connect-only'
initialAuthenticationMode: 'connect-only',
events: {
onAuthFlowClose: () => {
setWalletFilter(undefined)
}
}
}}
>
<WagmiProvider config={wagmiConfig}>
Expand All @@ -179,11 +195,13 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {

function MyApp({ Component, pageProps }: AppProps) {
return (
<QueryClientProvider client={queryClient}>
<AppWrapper>
<Component {...pageProps} />
</AppWrapper>
</QueryClientProvider>
<WalletFilterProvider>
<QueryClientProvider client={queryClient}>
<AppWrapper>
<Component {...pageProps} />
</AppWrapper>
</QueryClientProvider>
</WalletFilterProvider>
)
}

Expand Down
28 changes: 12 additions & 16 deletions demo/pages/sdk/actions/swap.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NextPage } from 'next'
import { useState } from 'react'
import { useWalletClient } from 'wagmi'
import { base, zora } from 'viem/chains'
import { Address } from 'viem'
import { useRelayClient } from '@reservoir0x/relay-kit-ui'
import { ConnectButton } from 'components/ConnectButton'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
import { ISolana } from '@dynamic-labs/solana'
import { Connection } from '@solana/web3.js'
import { isEthereumWallet } from '@dynamic-labs/ethereum'
import { isSolanaWallet } from '@dynamic-labs/solana'
import { adaptSolanaWallet } from '@reservoir0x/relay-solana-wallet-adapter'
import { adaptViemWallet } from '@reservoir0x/relay-sdk'

const SwapActionPage: NextPage = () => {
const [recipient, setRecipient] = useState<string | undefined>()
Expand All @@ -23,11 +23,9 @@ const SwapActionPage: NextPage = () => {
)
const [txs, setTxs] = useState<string[]>([])
const [tx, setTx] = useState<string>('')
const { data: wallet } = useWalletClient()
const client = useRelayClient()

const { primaryWallet } = useDynamicContext()
const walletAddress = primaryWallet?.address

return (
<div
Expand Down Expand Up @@ -198,27 +196,25 @@ const SwapActionPage: NextPage = () => {

let executionWallet

if (fromChainId === 792703809) {
const connection = await primaryWallet.connector.getPublicClient<
Connection | undefined
>()
const signer = await primaryWallet.connector?.getSigner<ISolana>()
if (fromChainId === 792703809 && isSolanaWallet(primaryWallet)) {
const connection = await primaryWallet.getConnection()
const signer = await primaryWallet.getSigner()

if (!connection || !signer?.signTransaction || !walletAddress) {
if (!connection || !signer?.signTransaction) {
throw 'Unable to setup Solana wallet'
}

executionWallet = adaptSolanaWallet(
walletAddress,
primaryWallet.address,
792703809,
connection,
signer.signAndSendTransaction
)
} else if (isEthereumWallet(primaryWallet)) {
const walletClient = await primaryWallet.getWalletClient()
executionWallet = adaptViemWallet(walletClient)
} else {
if (!wallet) {
throw 'Please connect to execute transactions'
}
executionWallet = wallet
throw 'Unable to configure wallet'
}

const quote = await client?.actions.getQuote({
Expand Down
16 changes: 13 additions & 3 deletions demo/pages/ui/chain.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { NextPage } from 'next'
import { ChainWidget } from '@reservoir0x/relay-kit-ui'
import { Layout } from 'components/Layout'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
import {
useDynamicContext,
useDynamicModals
} from '@dynamic-labs/sdk-react-core'

const ChainWidgetPage: NextPage = () => {
const { setShowAuthFlow } = useDynamicContext()
const { setShowAuthFlow, primaryWallet } = useDynamicContext()
const { setShowLinkNewWalletModal } = useDynamicModals()

return (
<Layout>
Expand Down Expand Up @@ -46,7 +50,13 @@ const ChainWidgetPage: NextPage = () => {
logoURI: 'https://ethereum-optimism.github.io/data/USDC/logo.png'
}}
// defaultAmount={'5'}
onConnectWallet={() => setShowAuthFlow(true)}
onConnectWallet={() => {
if (primaryWallet) {
setShowLinkNewWalletModal(true)
} else {
setShowAuthFlow(true)
}
}}
onAnalyticEvent={(eventName, data) => {
console.log('Analytic Event', eventName, data)
}}
Expand Down
Loading