Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fffcd2c
Deposit address demo
pedromcunha Nov 4, 2024
75af587
Use amount from deposit addresses response
pedromcunha Nov 4, 2024
d0069e4
Merge branch 'main' into feature/deposit-addresses
pedromcunha Nov 13, 2024
2b936d4
wip deposit address transaction modal
pedromcunha Nov 14, 2024
7e194e1
Add QR code logic and deeplink generation
pedromcunha Nov 17, 2024
9e2448b
Deposit address flow
pedromcunha Nov 18, 2024
4f421d0
Deposit address refund input
pedromcunha Nov 20, 2024
561b396
feat: changeset
pedromcunha Nov 20, 2024
a45f89f
cleanup dead code
pedromcunha Nov 20, 2024
3d52a7c
enable all vms for chain page
pedromcunha Nov 20, 2024
c8a624e
Update wallet selection ux for deposit addresses
ted-palmer Nov 25, 2024
f99914b
Merge pull request #379 from reservoirprotocol/ted/feature-deposit-ad…
ted-palmer Nov 25, 2024
0bf1394
Stop polling widget quote when deposit address modal is open
pedromcunha Nov 25, 2024
3862a8a
Merge branch 'feature/deposit-addresses' of github.com:reservoirproto…
pedromcunha Nov 25, 2024
0b4e528
Fix bugs with wallet connection ux
pedromcunha Nov 25, 2024
33b546b
Bug fixes for deposit addresses
pedromcunha Nov 26, 2024
42eda0b
Hide unbridgable assets and static tokens when using the deposit only…
pedromcunha Nov 26, 2024
702967e
Handle case where deposit address flow enabled but to or from token u…
pedromcunha Nov 26, 2024
1f6ad3e
Fix native currency not filtered for deposit address ux
pedromcunha Nov 27, 2024
6530d4e
Temporarily remove evm connections
pedromcunha Dec 2, 2024
f99d731
Fix hardcoded refund address
pedromcunha Dec 2, 2024
1716f00
Fix deposit address tooltip hit box
pedromcunha Dec 2, 2024
a99285e
Resolve conflicts
pedromcunha Dec 3, 2024
fabb0fe
Add loading property to DepositModal
pedromcunha Dec 3, 2024
ee5725a
Reorder deposit address modal waiting step
pedromcunha Dec 3, 2024
3723e66
Return transaction properly
pedromcunha Dec 4, 2024
047074a
Merge branch 'main' into feature/deposit-addresses
pedromcunha Dec 5, 2024
3b3ee3e
Remove refund address restriction for deposit address flow
pedromcunha Dec 5, 2024
c1a7a71
Truncate deposit address manually
pedromcunha Dec 6, 2024
559a15b
Filter out same chain swaps for deposit only flow
pedromcunha Dec 6, 2024
ec8f1ea
Fix ui bug with set currency step
pedromcunha Dec 6, 2024
0fd1c32
Fix connect wallet ux when no connected wallet exists
pedromcunha Dec 9, 2024
e57a748
Update deposit address ui
pedromcunha Dec 9, 2024
e8df44f
Bug fixes with deposit addresses and make all vms unsupported for tes…
pedromcunha Dec 9, 2024
450b405
Update button CTA for swapping
pedromcunha Dec 10, 2024
b30744f
Fix safari QR code icons not rendering
pedromcunha Dec 10, 2024
e4afcd4
Add more info about deposit addresses
pedromcunha Dec 11, 2024
2df86f2
Handle bitcoin deposit address flow as destination chain
pedromcunha Dec 12, 2024
22c7580
do not refresh the request api on window focus
pedromcunha Dec 12, 2024
f80dd7b
Resolve conflicts
pedromcunha Dec 12, 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/clever-rabbits-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@reservoir0x/relay-kit-ui': minor
'@reservoir0x/relay-kit-hooks': patch
---

Deposit Address fallback functionality
8 changes: 4 additions & 4 deletions demo/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
logLevel: 'INFO',
environmentId: process.env.NEXT_PUBLIC_DYNAMIC_ENV_ID ?? '',
walletConnectors: [
EthereumWalletConnectors,
SolanaWalletConnectors,
BitcoinWalletConnectors,
EclipseWalletConnectors
// EthereumWalletConnectors
// SolanaWalletConnectors,
// BitcoinWalletConnectors,
// EclipseWalletConnectors
],
cssOverrides: `
[data-testid="send-balance-button"] {
Expand Down
1 change: 1 addition & 0 deletions demo/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Index: NextPage = () => {
<nav style={{ display: 'flex', gap: 15 }}>
<Link href="/ui/swap">SwapWidget</Link>
<Link href="/ui/chain">ChainWidget</Link>
<Link href="/ui/depositAddresses">Deposit Addresses</Link>
</nav>
<h2>
<b>SDK Write Actions</b>
Expand Down
1 change: 1 addition & 0 deletions demo/pages/ui/chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const ChainWidgetPage: NextPage = () => {
<SwapWidget
lockChainId={8453}
wallet={wallet}
supportedWalletVMs={['bvm', 'evm', 'svm']}
tokens={[
{
chainId: 8453,
Expand Down
167 changes: 167 additions & 0 deletions demo/pages/ui/depositAddresses.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { NextPage } from 'next'
import { Layout } from 'components/Layout'
import { useTheme } from 'next-themes'
import { Address, zeroAddress } from 'viem'
import { useState } from 'react'
import { Execute, getQuote, GetQuoteParameters } from '@reservoir0x/relay-sdk'

const DepositAddressesPage: NextPage = () => {
const { theme } = useTheme()
const [amount, setAmount] = useState<number | undefined>()
const [refundAddress, setRefundAddress] = useState('')
const [currencyAddress, setCurrencyAddress] = useState<string>(zeroAddress)
const [recipientAddress, setRecipientAddress] = useState('')
const [originChainId, setOriginChainId] = useState<number | undefined>()
const [destinationChainId, setDestinationChainId] = useState<
number | undefined
>()
const [quote, setQuote] = useState<Execute>()
const [depositAddress, setDepositAddress] = useState<string | undefined>()
const [depositAmount, setDepositAmount] = useState<string | undefined>()
return (
<Layout
styles={{
minHeight: '100%',
height: 'auto',
background: theme === 'light' ? 'rgba(245, 242, 255, 1)' : '#1c172b'
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
paddingTop: 50,
flexDirection: 'column',
gap: 20
}}
>
<div>
<label>Amount (wei): </label>
<input
type="number"
placeholder="How much to deposit?"
value={amount}
onChange={(e) =>
setAmount(e.target.value ? Number(e.target.value) : undefined)
}
/>
</div>
<div>
<label>Refund Address: </label>
<input
type="string"
placeholder="Where to send refunds to?"
value={refundAddress}
onChange={(e) => setRefundAddress(e.target.value)}
/>
</div>
<div>
<label>Currency Address: </label>
<input
type="string"
placeholder="What currency address?"
value={currencyAddress}
onChange={(e) => setCurrencyAddress(e.target.value)}
/>
</div>
<div>
<label>Origin Chain Id: </label>
<input
type="string"
placeholder="What origin chain id?"
value={originChainId}
onChange={(e) =>
setOriginChainId(
e.target.value ? Number(e.target.value) : undefined
)
}
/>
</div>
<div>
<label>Destination Chain Id: </label>
<input
type="string"
placeholder="What destination chain id?"
value={destinationChainId}
onChange={(e) =>
setDestinationChainId(
e.target.value ? Number(e.target.value) : undefined
)
}
/>
</div>
<div>
<label>Recipient address: </label>
<input
type="string"
placeholder="What is the recipient address?"
value={recipientAddress}
onChange={(e) => setRecipientAddress(e.target.value)}
/>
</div>

<button
onClick={async () => {
if (
!destinationChainId ||
!originChainId ||
!recipientAddress ||
!refundAddress
) {
throw 'Missing required data'
}

const quoteData: GetQuoteParameters = {
amount: `${amount}`,
recipient: recipientAddress as Address,
tradeType: 'EXACT_INPUT',
toChainId: destinationChainId,
toCurrency: currencyAddress,
chainId: originChainId,
currency: currencyAddress,
options: {
useDepositAddress: true,
refundTo: refundAddress
}
}
const data = await getQuote(quoteData)
setQuote(data)
const depositStepData =
data.steps &&
data.steps[0] &&
data.steps[0].items &&
data.steps[0].items[0]
? data.steps[0].items[0].data
: undefined
if (depositStepData) {
setDepositAddress(depositStepData.to)
setDepositAmount(depositStepData.value)
}
}}
>
Get Quote
</button>

{quote ? (
<div>
<div style={{ fontSize: 22, fontWeight: 600 }}>
Instructions to relay:
</div>
<div>
Send {depositAmount} wei to this address: {depositAddress}
</div>
<br />
<div style={{ fontSize: 22, fontWeight: 600 }}>Quote Response:</div>
<div style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
{JSON.stringify(quote, null, 2)}
</div>
</div>
) : undefined}
</div>
</Layout>
)
}

export default DepositAddressesPage
1 change: 1 addition & 0 deletions demo/pages/ui/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const SwapWidgetPage: NextPage = () => {
key={`swap-widget-${singleChainMode ? 'single' : 'multi'}-chain`}
lockChainId={singleChainMode ? 8453 : undefined}
singleChainMode={singleChainMode}
supportedWalletVMs={[]}
defaultToToken={
singleChainMode
? {
Expand Down
103 changes: 103 additions & 0 deletions packages/hooks/src/hooks/useExecutionStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
MAINNET_RELAY_API,
RelayClient,
setParams,
type Execute,
type paths,
type ProgressData
} from '@reservoir0x/relay-sdk'
import fetcher from '../fetcher.js'
import {
useQuery,
type DefaultError,
type QueryKey
} from '@tanstack/react-query'
import { useMemo } from 'react'
import type { AxiosRequestConfig } from 'axios'

type ExecutionStatusParams =
paths['/intents/status/v2']['get']['parameters']['query']

export type ExecutionStatusResponse =
paths['/intents/status/v2']['get']['responses']['200']['content']['application/json']

type QueryType = typeof useQuery<
ExecutionStatusResponse,
DefaultError,
ExecutionStatusResponse,
QueryKey
>
type QueryOptions = Parameters<QueryType>['0']

export const queryExecutionStatus = function (
baseApiUrl: string = MAINNET_RELAY_API,
options?: ExecutionStatusParams
): Promise<ExecutionStatusResponse> {
return new Promise((resolve, reject) => {
const url = new URL(`${baseApiUrl}/intents/status/v2`)
let query: ExecutionStatusParams = { ...options }
setParams(url, query)

fetcher(url.href)
.then((response) => {
const request: AxiosRequestConfig = {
url: url.href,
method: 'get'
}
resolve({
...response,
request
})
})
.catch((e) => {
reject(e)
})
})
}

export type onProgress = (data: ProgressData) => void

export default function (
client?: RelayClient,
options?: ExecutionStatusParams,
onRequest?: () => void,
onResponse?: (data: Execute) => void,
queryOptions?: Partial<QueryOptions>
) {
const queryKey = ['useExecutionStatus', options]
const response = (useQuery as QueryType)({
queryKey: queryKey,
queryFn: () => {
onRequest?.()
const promise = queryExecutionStatus(client?.baseApiUrl, options)
promise.then((response: any) => {
onResponse?.(response)
})
return promise
},
enabled: client !== undefined && options !== undefined,
retry: false,
...queryOptions
})

return useMemo(
() =>
({
...response,
data: response.error ? undefined : response.data,
queryKey
}) as Omit<ReturnType<QueryType>, 'data'> & {
data?: ExecutionStatusResponse
queryKey: QueryKey
},
[
response.data,
response.error,
response.isLoading,
response.isFetching,
response.isRefetching,
response.dataUpdatedAt,
queryKey
]
)
}
8 changes: 6 additions & 2 deletions packages/hooks/src/hooks/useQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export default function (
onResponse?: (data: Execute) => void,
queryOptions?: Partial<QueryOptions>
) {
const queryKey = ['useQuote', options]
const response = (useQuery as QueryType)({
queryKey: ['useQuote', options],
queryKey: queryKey,
queryFn: () => {
onRequest?.()
if (options && client?.source && !options.referrer) {
Expand Down Expand Up @@ -108,9 +109,11 @@ export default function (
({
...response,
data: response.error ? undefined : response.data,
queryKey,
executeQuote
}) as Omit<ReturnType<QueryType>, 'data'> & {
data?: QuoteResponse
queryKey: QueryKey
executeQuote: (onProgress: onProgress) => Promise<Execute> | undefined
},
[
Expand All @@ -120,7 +123,8 @@ export default function (
response.isFetching,
response.isRefetching,
response.dataUpdatedAt,
executeQuote
executeQuote,
queryKey
]
)
}
4 changes: 4 additions & 0 deletions packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export {
default as useRelayConfig,
queryRelayConfig
} from './hooks/useRelayConfig.js'
export {
default as useExecutionStatus,
queryExecutionStatus
} from './hooks/useExecutionStatus.js'

//types
export type { CurrencyList, Currency } from './hooks/useTokenList.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const routes = [
"/chains",
"/chains/health",
"/config",
"/config/v2",
"/execute/bridge",
Expand All @@ -11,13 +12,13 @@ export const routes = [
"/execute/permits",
"/quote",
"/price",
"/execute/user-op/{chainId}",
"/lives",
"/intents/status",
"/intents/status/v2",
"/intents/quote",
"/intents/quote/v2",
"/requests/{requestId}/signature",
"/requests/{requestId}/signature/v2",
"/requests",
"/requests/v2",
"/transactions/index",
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/Execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type Execute = {
kind: 'transaction' | 'signature'
id: string
requestId?: string
depositAddress?: string
items?: {
status: 'complete' | 'incomplete'
progressState?: TransactionStepState | SignatureStepState
Expand Down
Loading
Loading