@openocean.finance/widget
Version:
Openocean Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
23 lines (19 loc) • 599 B
text/typescript
import type { GetChainById } from '../hooks/useAvailableChains.js'
const CHAIN_LABEL_IN_ERROR_REGEX =
/\b(Destination|Origin|Source) chain (\d+)\b/gi
export const formatServerErrorMessage = (
message: string | null | undefined,
getChainById: GetChainById
): string | null | undefined => {
if (!message) {
return message
}
return message.replace(
CHAIN_LABEL_IN_ERROR_REGEX,
(_match, label: string, chainId: string) => {
const chain = getChainById(Number(chainId))
const chainName = chain?.name ?? chainId
return `${label} chain ${chainName}`
}
)
}