-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(namadillo): disabling fields on transfer module * feat(namadillo): starting integration with keplr wallet * feat: adding chain registry package and updating types and tests * feat(namadillo): writing tests for SelectChainModal * feat(namadillo): first chain modal version * feat: adding new features to transfer module * feat: adding more tests
- Loading branch information
1 parent
1def6e0
commit a20d53b
Showing
51 changed files
with
1,402 additions
and
316 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
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 { Asset } from "@chain-registry/types"; | ||
import clsx from "clsx"; | ||
|
||
type AssetCardProps = { | ||
asset: Asset; | ||
}; | ||
|
||
export const AssetCard = ({ asset }: AssetCardProps): JSX.Element => { | ||
const image = asset.logo_URIs?.svg || asset.logo_URIs?.png; | ||
return ( | ||
<span | ||
className={clsx( | ||
"grid grid-cols-[40px_auto] gap-6 w-full px-4 py-2.5 items-center" | ||
)} | ||
> | ||
{image ? | ||
<img | ||
src={image} | ||
alt={asset.name + ` logo`} | ||
className="w-full aspect-square" | ||
/> | ||
: <img | ||
className="bg-neutral-800 rounded-full aspect-square w-full" | ||
alt="Logo not available" | ||
role="img" | ||
/> | ||
} | ||
<span className="text-left">{asset.name}</span> | ||
</span> | ||
); | ||
}; |
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,19 @@ | ||
import { Chain } from "@chain-registry/types"; | ||
import clsx from "clsx"; | ||
|
||
type ChainCardProps = { | ||
chain: Chain; | ||
}; | ||
|
||
export const ChainCard = ({ chain }: ChainCardProps): JSX.Element => { | ||
return ( | ||
<span | ||
className={clsx( | ||
"grid grid-cols-[40px_auto] gap-6 w-full px-4 py-2.5 items-center" | ||
)} | ||
> | ||
<img src={chain.logo_URIs?.svg} alt={chain.pretty_name + " logo"} /> | ||
<span className="text-left">{chain.pretty_name}</span> | ||
</span> | ||
); | ||
}; |
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,125 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { useEffect, useState } from "react"; | ||
|
||
// This can be loaded async using @chain-registry/client | ||
import { | ||
chain as celestia, | ||
assets as celestiaAssets, | ||
} from "chain-registry/mainnet/celestia"; | ||
import { | ||
chain as cosmos, | ||
assets as cosmosAssets, | ||
} from "chain-registry/mainnet/cosmoshub"; | ||
import { | ||
chain as dydx, | ||
assets as dydxAssets, | ||
} from "chain-registry/mainnet/dydx"; | ||
import { | ||
chain as osmosis, | ||
assets as osmosisAssets, | ||
} from "chain-registry/mainnet/osmosis"; | ||
import { | ||
chain as stargaze, | ||
assets as stargazeAssets, | ||
} from "chain-registry/mainnet/stargaze"; | ||
import { | ||
chain as stride, | ||
assets as strideAssets, | ||
} from "chain-registry/mainnet/stride"; | ||
|
||
// This will be replaced by namada registry in the future | ||
import namadaChain from "registry/namada.json"; | ||
|
||
import { Asset, Chain } from "@chain-registry/types"; | ||
import { Panel } from "@namada/components"; | ||
import { integrations } from "@namada/integrations"; | ||
import { selectedIBCChainAtom, selectedIBCWallet } from "atoms/integrations"; | ||
import { wallets } from "integrations"; | ||
import { useAtom } from "jotai"; | ||
import { useMemo } from "react"; | ||
import { WalletProvider } from "types"; | ||
import { TransferModule } from "./TransferModule"; | ||
|
||
export const Example = (): JSX.Element => { | ||
const [selectedWallet, setWallet] = useAtom(selectedIBCWallet); | ||
const [chainId, setChainId] = useAtom(selectedIBCChainAtom); | ||
const [selectedAsset, setSelectedAsset] = useState<Asset>(); | ||
const [isShielded, setShielded] = useState(true); | ||
|
||
const sourceChainConfig: [Chain, Asset[]][] = [ | ||
[cosmos, cosmosAssets.assets], | ||
[osmosis, osmosisAssets.assets], | ||
[celestia, celestiaAssets.assets], | ||
[dydx, dydxAssets.assets], | ||
[stride, strideAssets.assets], | ||
[stargaze, stargazeAssets.assets], | ||
]; | ||
|
||
const sourceChains: Record<string, Chain> = useMemo(() => { | ||
return sourceChainConfig.reduce((prev, current) => { | ||
return { | ||
...prev, | ||
[current[0].chain_id]: current[0], | ||
}; | ||
}, {}); | ||
}, []); | ||
|
||
const sourceAssetList: Asset[] | undefined = useMemo(() => { | ||
if (!chainId) return; | ||
const config = sourceChainConfig.find( | ||
(config) => config[0].chain_id === chainId | ||
); | ||
if (config) { | ||
return config[1]; | ||
} | ||
}, [chainId]); | ||
|
||
const selectedSourceChain = | ||
chainId && chainId in sourceChains ? sourceChains[chainId] : undefined; | ||
|
||
useEffect(() => { | ||
const config = sourceChainConfig.find( | ||
(config) => config[0].chain_id === chainId | ||
); | ||
|
||
if (config) { | ||
setSelectedAsset(config[1][0]); | ||
} | ||
}, [chainId]); | ||
|
||
return ( | ||
<Panel className="py-20"> | ||
<TransferModule | ||
isConnected={false} | ||
onSubmitTransfer={() => {}} | ||
availableWallets={Object.values(wallets)} | ||
sourceWallet={selectedWallet ? wallets[selectedWallet] : undefined} | ||
onChangeWallet={async (wallet: WalletProvider) => { | ||
try { | ||
await integrations[wallet.id].connect(); | ||
setWallet(wallet.id); | ||
if (!chainId) { | ||
setChainId(cosmos.chain_id); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}} | ||
onChangeSourceChain={(chain) => { | ||
setChainId(chain.chain_id); | ||
}} | ||
onChangeSelectedAsset={setSelectedAsset} | ||
availableSourceChains={Object.values(sourceChains)} | ||
availableAssets={sourceAssetList} | ||
selectedAsset={selectedAsset} | ||
sourceChain={selectedSourceChain} | ||
destinationChain={namadaChain as Chain} | ||
destinationWallet={wallets.namada} | ||
isShielded={isShielded} | ||
onChangeShielded={setShielded} | ||
availableAmount={new BigNumber(100) /* Change this */} | ||
transactionFee={new BigNumber(0.01)} | ||
/> | ||
</Panel> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
import { Asset } from "@chain-registry/types"; | ||
import { Stack } from "@namada/components"; | ||
import { Search } from "App/Common/Search"; | ||
import { SelectModal } from "App/Common/SelectModal"; | ||
import clsx from "clsx"; | ||
import { useMemo, useState } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { AssetCard } from "./AssetCard"; | ||
|
||
type SelectWalletModalProps = { | ||
onClose: () => void; | ||
onSelect: (asset: Asset) => void; | ||
assets: Asset[]; | ||
}; | ||
|
||
export const SelectAssetModal = ({ | ||
onClose, | ||
onSelect, | ||
assets, | ||
}: SelectWalletModalProps): JSX.Element => { | ||
const [filter, setFilter] = useState(""); | ||
|
||
const filteredAssets = useMemo(() => { | ||
return assets.filter( | ||
(asset) => | ||
asset.name.indexOf(filter) >= 0 || asset.symbol.indexOf(filter) >= 0 | ||
); | ||
}, [assets, filter]); | ||
|
||
return ( | ||
<SelectModal title="Select Asset" onClose={onClose}> | ||
<div className="mb-4"> | ||
<Search placeholder="Search chain" onChange={setFilter} /> | ||
</div> | ||
<Stack | ||
as="ul" | ||
gap={0} | ||
className="max-h-[400px] overflow-auto dark-scrollbar pb-4 mr-[-0.5rem]" | ||
> | ||
{filteredAssets.map((asset: Asset, index: number) => ( | ||
<li key={index} className="text-sm"> | ||
<button | ||
onClick={() => { | ||
onSelect(asset); | ||
onClose(); | ||
}} | ||
className={twMerge( | ||
clsx( | ||
"w-full rounded-sm border border-transparent", | ||
"hover:border-neutral-400 transition-colors duration-150" | ||
) | ||
)} | ||
> | ||
<AssetCard asset={asset} /> | ||
</button> | ||
</li> | ||
))} | ||
</Stack> | ||
</SelectModal> | ||
); | ||
}; |
Oops, something went wrong.
a20d53b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://namada-interface-dev.netlify.app as production
🚀 Deployed on https://66fadba04453ea09d3a2285a--namada-interface-dev.netlify.app