-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from reservoirprotocol/pedro/relay-5758-add-e…
…xplorer-params-on-trade-details-popup Improve block explorer tx url generation
- Loading branch information
Showing
5 changed files
with
60 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@reservoir0x/relay-kit-ui': patch | ||
--- | ||
|
||
Include additional parameters when generating tx urls |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,31 @@ | ||
import type { RelayChain } from '@reservoir0x/relay-sdk' | ||
import getChainBlockExplorerUrl from './getChainBlockExplorerUrl.js' | ||
|
||
const appendQueryParams = (url: string, params: Record<string, any>) => { | ||
if (params) { | ||
const queryParams = new URLSearchParams(params) | ||
return `${url}?${queryParams.toString()}` | ||
} | ||
return url | ||
} | ||
|
||
export const getTxBlockExplorerUrl = ( | ||
chainId?: number, | ||
chains?: RelayChain[], | ||
txHash?: string | ||
) => { | ||
const chain = chains?.find((chain) => chain.id === chainId) | ||
let blockExplorerUrl = getChainBlockExplorerUrl(chainId, chains) | ||
|
||
if (txHash) { | ||
blockExplorerUrl = `${blockExplorerUrl}/tx/${txHash}` | ||
} | ||
|
||
blockExplorerUrl = appendQueryParams( | ||
blockExplorerUrl, | ||
//@ts-ignore: TODO until we update the sdk | ||
chain?.explorerQueryParams | ||
) | ||
|
||
return blockExplorerUrl | ||
} |