Skip to content

Commit

Permalink
Migrate improvements and features for Neutron upstream (#77)
Browse files Browse the repository at this point in the history
Includes support for IBC routes, fixes for cosmos, and some minor UX improvements.
  • Loading branch information
jmrossy authored Nov 9, 2023
1 parent 024dc5e commit ea2479e
Show file tree
Hide file tree
Showing 61 changed files with 1,192 additions and 615 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperlane-xyz/warp-ui-template",
"description": "A web app template for building Hyperlane Warp Route UIs",
"version": "1.5.3",
"version": "3.1.0-beta3",
"author": "J M Rossy",
"dependencies": {
"@chakra-ui/next-js": "^2.1.5",
Expand All @@ -11,12 +11,13 @@
"@cosmos-kit/core": "^2.7.2",
"@cosmos-kit/cosmostation": "^2.4.4",
"@cosmos-kit/keplr": "^2.4.4",
"@cosmos-kit/leap": "^2.4.3",
"@cosmos-kit/react": "^2.5.3",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@headlessui/react": "^1.7.14",
"@hyperlane-xyz/sdk": "^3.1.0-beta0",
"@hyperlane-xyz/utils": "^3.1.0-beta0",
"@hyperlane-xyz/sdk": "^3.1.0-beta3",
"@hyperlane-xyz/utils": "^3.1.0-beta3",
"@hyperlane-xyz/widgets": "^1.5.0",
"@metamask/jazzicon": "https://github.com/jmrossy/jazzicon#7a8df28974b4e81129bfbe3cab76308b889032a6",
"@rainbow-me/rainbowkit": "0.12.16",
Expand Down
Binary file modified public/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/background-texture.png
Binary file not shown.
Binary file modified public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicon.ico
Binary file not shown.
Binary file modified public/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions public/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/buttons/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props {
width: number;
height: number;
copyValue: string;
classes: string;
classes?: string;
}

export function CopyButton({ width, height, copyValue, classes }: Props) {
Expand Down
6 changes: 5 additions & 1 deletion src/components/buttons/SolidButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PropsWithChildren, ReactElement } from 'react';

interface ButtonProps {
type?: 'submit' | 'reset' | 'button';
color?: 'white' | 'blue' | 'green' | 'red' | 'gray' | 'pink'; // defaults to blue
color?: 'white' | 'blue' | 'green' | 'red' | 'gray' | 'pink' | 'mint'; // defaults to blue
bold?: boolean;
classes?: string;
icon?: ReactElement;
Expand Down Expand Up @@ -38,6 +38,10 @@ export function SolidButton(
baseColors = 'bg-green-500 text-white';
onHover = 'hover:bg-green-600';
onActive = 'active:bg-green-700';
} else if (color === 'mint') {
baseColors = 'bg-mint-500 text-white';
onHover = 'hover:bg-mint-600';
onActive = 'active:bg-mint-700';
} else if (color === 'red') {
baseColors = 'bg-red-600 text-white';
onHover = 'hover:bg-red-500';
Expand Down
16 changes: 16 additions & 0 deletions src/components/icons/WideChevron.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WideChevron as WideChevronInner } from '@hyperlane-xyz/widgets';

import { Color } from '../../styles/Color';

export function WideChevron({ classes }: { classes?: string }) {
return (
<WideChevronInner
width="17"
height="100%"
direction="e"
color={Color.lightGray}
classes={classes}
rounded={true}
/>
);
}
8 changes: 4 additions & 4 deletions src/components/layout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function AppLayout({ children }: PropsWithChildren) {
<Head>
{/* https://nextjs.org/docs/messages/no-document-viewport-meta */}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hyperlane Warp Route Template UI</title>
<title>Hyperlane Nexus Bridge</title>
</Head>
<div
style={styles.container}
Expand All @@ -24,10 +24,10 @@ export function AppLayout({ children }: PropsWithChildren) {
<Image src={Planet1} alt="Planet 1" width={200} priority={false} quality={50}></Image>
</div>
<div className="hidden md:flex absolute right-[8%] bottom-1/4">
<Image src={Planet2} alt="Planet 2" width={300} priority={false} quality={50}></Image>
<Image src={Planet2} alt="Planet 2" width={220} priority={false} quality={50}></Image>
</div>
<Header />
<div className="px-4 mx-auto grow flex items-center max-w-screen-xl">
<div className="sm:px-4 mx-auto grow flex items-center max-w-screen-xl">
<main className="w-full flex-1 my-4 flex items-center justify-center">{children}</main>
</div>
<Footer />
Expand All @@ -41,6 +41,6 @@ const styles = {
backgroundImage: 'url(/backgrounds/lines-bg-top.svg)',
backgroundSize: '94vw',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center 60px',
backgroundPosition: 'center 80px',
},
};
2 changes: 1 addition & 1 deletion src/components/layout/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
export function Card({ className, children }: PropsWithChildren<Props>) {
return (
<div
className={`p-3 md:p-3.5 relative bg-white ring ring-blue-300 rounded-3xl overflow-auto ${className}`}
className={`p-1.5 sm:p-3 md:p-3.5 relative bg-white ring ring-blue-300 rounded-3xl overflow-auto ${className}`}
>
{children}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function Modal({
<Dialog.Panel
className={`w-full ${
width || 'max-w-xs'
} max-h-[90vh] transform overflow-auto rounded-md bg-white ${
} max-h-[90vh] transform overflow-auto rounded-2xl bg-white ${
padding || 'px-4 py-4'
} text-left shadow-lg transition-all`}
>
Expand Down
10 changes: 5 additions & 5 deletions src/components/toast/IgpDetailsToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { toast } from 'react-toastify';

import { links } from '../../consts/links';

export function toastIgpDetails() {
toast.error(<IgpDetailsToast />, {
export function toastIgpDetails(igpFee: number, tokenName = 'native token') {
toast.error(<IgpDetailsToast tokenName={tokenName} igpFee={igpFee} />, {
autoClose: 5000,
});
}

export function IgpDetailsToast() {
export function IgpDetailsToast({ tokenName, igpFee }) {
return (
<div>
Cross-chain transfers require a small amount of extra gas to fund delivery. Your native token
balance is insufficient.{' '}
Cross-chain transfers require a small fee of {igpFee} {tokenName} to fund delivery transaction
costs. Your {tokenName} balance is insufficient.{' '}
<a className="underline" href={links.gasDocs} target="_blank" rel="noopener noreferrer">
Learn More
</a>
Expand Down
4 changes: 4 additions & 0 deletions src/consts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface Config {
walletConnectProjectId: string; // Project ID provided by walletconnect
withdrawalWhitelist: string; // comma-separated list of CAIP2 chain IDs to which transfers are supported
transferBlacklist: string; // comma-separated list of routes between which transfers are disabled. Expects Caip2Id-Caip2Id (e.g. ethereum:1-sealevel:1399811149)
enableExplorerLink: boolean; // Include a link to the hyperlane explorer in the transfer modal
enableAutoTokenSelection: boolean; // Automatically select the first valid for the token field
}

export const config: Config = Object.freeze({
Expand All @@ -25,4 +27,6 @@ export const config: Config = Object.freeze({
walletConnectProjectId,
withdrawalWhitelist,
transferBlacklist,
enableExplorerLink: false,
enableAutoTokenSelection: false,
});
4 changes: 4 additions & 0 deletions src/consts/ibcRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { IbcRoute, IbcToWarpRoute } from '../features/tokens/routes/types';

// Configs for manually-defined IBC-only routes
export const ibcRoutes: Array<IbcRoute | IbcToWarpRoute> = [];
4 changes: 3 additions & 1 deletion src/consts/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const COSMOS_ZERO_ADDRESS = 'cosmos10000000000000000000000000000000000000
// Strangely, this is not included in any of the Solana packages
export const SOL_SPL_NOOP_ADDRESS = 'noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV';
export const SOL_IGP_QUOTE = '10000';
export const COSM_IGP_QUOTE = '100';
export const COSM_IGP_QUOTE = '270000';
// Placeholder chain for use with cosmos-kit wallet hooks that require a chain name
export const PLACEHOLDER_COSMOS_CHAIN = 'cosmoshub';
6 changes: 3 additions & 3 deletions src/features/caip/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function parseCaip2Id(id: ChainCaip2Id) {
return { protocol, reference };
}

export function tryParseCaip2Id(id: ChainCaip2Id) {
export function tryParseCaip2Id(id?: ChainCaip2Id) {
if (!id) return undefined;
try {
return parseCaip2Id(id);
Expand All @@ -45,7 +45,7 @@ export function getProtocolType(id: ChainCaip2Id) {
return protocol;
}

export function tryGetProtocolType(id: ChainCaip2Id) {
export function tryGetProtocolType(id?: ChainCaip2Id) {
return tryParseCaip2Id(id)?.protocol;
}

Expand All @@ -54,7 +54,7 @@ export function getChainReference(id: ChainCaip2Id) {
return reference;
}

export function tryGetChainReference(id: ChainCaip2Id) {
export function tryGetChainReference(id?: ChainCaip2Id) {
return tryParseCaip2Id(id)?.reference;
}

Expand Down
4 changes: 2 additions & 2 deletions src/features/caip/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function parseCaip19Id(id: TokenCaip19Id) {
}
}

export function tryParseCaip19Id(id: TokenCaip19Id) {
export function tryParseCaip19Id(id?: TokenCaip19Id) {
if (!id) return undefined;
try {
return parseCaip19Id(id);
Expand All @@ -65,7 +65,7 @@ export function getChainIdFromToken(id: TokenCaip19Id): ChainCaip2Id {
return parseCaip19Id(id).chainCaip2Id;
}

export function tryGetChainIdFromToken(id: TokenCaip19Id): ChainCaip2Id | undefined {
export function tryGetChainIdFromToken(id?: TokenCaip19Id): ChainCaip2Id | undefined {
return tryParseCaip19Id(id)?.chainCaip2Id;
}

Expand Down
3 changes: 2 additions & 1 deletion src/features/chains/ChainSelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Image from 'next/image';
import { useState } from 'react';

import { ChainLogo } from '../../components/icons/ChainLogo';
import { config } from '../../consts/config';
import ChevronIcon from '../../images/icons/chevron-down.svg';
import { TransferFormValues } from '../transfer/types';

Expand All @@ -24,9 +25,9 @@ export function ChainSelectField({ name, label, chainCaip2Ids, onChange, disable
const handleChange = (newChainId: ChainCaip2Id) => {
helpers.setValue(newChainId);
// Reset other fields on chain change
setFieldValue('tokenCaip19Id', '');
setFieldValue('recipientAddress', '');
setFieldValue('amount', '');
if (!config.enableAutoTokenSelection) setFieldValue('tokenCaip19Id', '');
if (onChange) onChange(newChainId);
};

Expand Down
14 changes: 5 additions & 9 deletions src/features/chains/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ChainMap,
ChainMetadata,
ChainMetadataSchema,
ChainName,
chainMetadata,
chainMetadataToWagmiChain,
} from '@hyperlane-xyz/sdk';
Expand Down Expand Up @@ -129,13 +130,8 @@ export function getCosmosKitConfig(): { chains: CosmosChain[]; assets: AssetList
return { chains, assets };
}

// TODO this assumes a single cosmos chain per app instance.
// This is useful because the wallet hooks currently assume one connection per wallet
// but in Cosmos-land connections are per-chain.
let cosmosChainName: string;
export function getCosmosChainName() {
if (!cosmosChainName) {
cosmosChainName = getCosmosKitConfig()?.chains?.[0]?.chain_name || 'cosmoshub';
}
return cosmosChainName;
export function getCosmosChainNames(): ChainName[] {
return Object.values(getChainConfigs())
.filter((c) => c.protocol === ProtocolType.Cosmos)
.map((c) => c.name);
}
Loading

1 comment on commit ea2479e

@vercel
Copy link

@vercel vercel bot commented on ea2479e Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.