Skip to content

Commit

Permalink
chore: sync staging → main #103
Browse files Browse the repository at this point in the history
Griko Nibras authored Nov 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents f31003e + 85bced4 commit a22908f
Showing 15 changed files with 2,683 additions and 2,029 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Branches
on:
push:
branches: [main]
workflow_dispatch:

jobs:
sync-main-dev:
name: branch main -> dev
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fast-forward main -> dev
run: |
git checkout dev
git merge --ff-only main
git push --set-upstream origin dev
2 changes: 1 addition & 1 deletion chain-registry
Submodule chain-registry updated 124 files
4,177 changes: 2,270 additions & 1,907 deletions package-lock.json

Large diffs are not rendered by default.

89 changes: 45 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -12,95 +12,96 @@
"test:e2e": "playwright test --project=chromium"
},
"dependencies": {
"@cosmjs/amino": "^0.31.0",
"@cosmjs/cosmwasm-stargate": "^0.31.0",
"@cosmjs/encoding": "^0.31.0",
"@cosmjs/ledger-amino": "^0.31.0",
"@cosmjs/math": "^0.31.0",
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@cosmjs/amino": "^0.31.3",
"@cosmjs/cosmwasm-stargate": "^0.31.3",
"@cosmjs/encoding": "^0.31.3",
"@cosmjs/ledger-amino": "^0.31.3",
"@cosmjs/math": "^0.31.3",
"@cosmjs/proto-signing": "^0.31.3",
"@cosmjs/stargate": "^0.31.3",
"@cosmjs/tendermint-rpc": "^0.31.3",
"@cosmos-kit/core": "^2.0.3",
"@cosmos-kit/cosmostation-extension": "^2.0.3",
"@cosmos-kit/keplr-extension": "^2.0.3",
"@cosmos-kit/leap-extension": "^2.0.3",
"@cosmos-kit/leap-metamask-cosmos-snap": "^0.2.2",
"@cosmos-kit/okxwallet": "^2.3.8",
"@cosmos-kit/react": "^2.0.3",
"@cosmos-kit/react-lite": "^2.1.4",
"@cosmos-kit/web3auth": "^2.0.3",
"@evmos/proto": "^0.2.1",
"@evmos/provider": "^0.3.1",
"@evmos/transactions": "^0.3.2",
"@graz-sh/types": "^0.0.12",
"@headlessui/react": "^1.7.14",
"@graz-sh/types": "^0.0.13",
"@headlessui/react": "^1.7.17",
"@heroicons/react": "^2.0.18",
"@injectivelabs/sdk-ts": "^1.11.0",
"@injectivelabs/utils": "^1.11.0",
"@keplr-wallet/types": "^0.12.4",
"@injectivelabs/sdk-ts": "^1.14.4",
"@injectivelabs/utils": "^1.14.4",
"@keplr-wallet/types": "^0.12.44",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@sentry/nextjs": "^7.77.0",
"@radix-ui/react-tooltip": "^1.0.7",
"@sentry/nextjs": "^7.81.1",
"@skip-router/core": "^0.1.0-rc22",
"@tanstack/react-query": "^4.29.5",
"@types/node": "20.1.2",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"@vercel/analytics": "^1.0.1",
"@tanstack/react-query": "^5.8.4",
"@types/node": "20.9.4",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.17",
"@vercel/analytics": "^1.1.1",
"@web3modal/core": "^2.7.0",
"@web3modal/ui": "^2.7.0",
"autoprefixer": "10.4.14",
"axios": "^1.4.0",
"autoprefixer": "10.4.16",
"axios": "^1.6.2",
"classnames": "^2.3.2",
"clsx": "^2.0.0",
"cosmjs-types": "^0.7.2",
"cosmjs-types": "^0.9.0",
"date-fns": "^2.30.0",
"download": "^8.0.0",
"eslint-config-next": "13.4.1",
"eslint-config-next": "14.0.3",
"ethers": "^6.3.0",
"framer-motion": "^10.12.18",
"framer-motion": "^10.16.5",
"http-proxy": "^1.18.1",
"next": "13.4.7",
"pino-pretty": "^10.0.0",
"postcss": "8.4.23",
"next": "14.0.3",
"pino-pretty": "^10.2.3",
"postcss": "8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"tailwindcss": "3.3.5",
"usehooks-ts": "^2.9.1",
"viem": "^1.14.0",
"wagmi": "^1.4.3",
"zod": "^3.22.4",
"zustand": "^4.4.4"
"zustand": "^4.4.6"
},
"devDependencies": {
"@playwright/test": "^1.38.0",
"@tanstack/eslint-plugin-query": "^4.36.0",
"@tanstack/eslint-plugin-query": "^5.8.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/degit": "^2.8.5",
"@types/download": "^8.0.2",
"@types/http-proxy": "^1.17.11",
"@types/degit": "^2.8.6",
"@types/download": "^8.0.5",
"@types/http-proxy": "^1.17.14",
"@types/jest": "^29.5.3",
"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"degit": "npm:tiged@^2.12.5",
"eslint": "^8.49.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"globby": "^13.2.2",
"globby": "^14.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"msw": "^1.2.3",
"p-map": "^6.0.0",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"resize-observer-polyfill": "^1.5.1",
"ts-jest": "^29.1.1",
"tsx": "^3.14.0",
"typescript": "^5.0.4"
"tsx": "^4.2.1",
"typescript": "5.1.x"
}
}
158 changes: 90 additions & 68 deletions src/components/AssetInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { clsx } from "clsx";
import { ethers } from "ethers";
import { FC, Fragment, useEffect, useMemo, useState } from "react";
import { FC, Fragment, useEffect, useMemo, useRef, useState } from "react";

import { Chain } from "@/api/queries";
import { AssetWithMetadata, useAssets } from "@/context/assets";
@@ -11,6 +12,7 @@ import { getFee, useBalancesByChain } from "@/utils/utils";

import AssetSelect from "./AssetSelect";
import ChainSelect from "./ChainSelect";
import { UsdDiff, UsdValue, useUsdDiffReset } from "./UsdValue";

interface Props {
amount: string;
@@ -51,11 +53,7 @@ const AssetInput: FC<Props> = ({

const { address } = useAccount(chain?.chainID ?? "cosmoshub-4");

const { data: balances, isInitialLoading } = useBalancesByChain(
address,
chain,
showBalance,
);
const { data: balances } = useBalancesByChain(address, chain, showBalance);

const selectedAssetBalance = useMemo(() => {
if (!asset || !balances) {
@@ -83,12 +81,17 @@ const AssetInput: FC<Props> = ({

const { slippage } = useSettingsStore();

// hotfix side effect to prevent negative amounts
const reset = useUsdDiffReset();
useEffect(() => {
if (parseFloat(amount) < 0) {
onAmountChange?.("0.0");
}
}, [amount, onAmountChange]);
const parsed = parseFloat(amount);

// hotfix side effect to prevent negative amounts
if (parsed < 0) onAmountChange?.("0.0");
if (parsed == 0) reset();
}, [amount, onAmountChange, reset]);

const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => inputRef.current?.focus(), []);

return (
<Fragment>
@@ -114,25 +117,18 @@ const AssetInput: FC<Props> = ({
<div>
{!onAmountChange && (
<p
className={`w-full text-3xl font-medium h-10 ${
amount === "0.0" ? "text-neutral-300" : "text-black"
}`}
className={clsx(
"w-full text-3xl font-medium h-10",
amount === "0.0" ? "text-neutral-300" : "text-black",
)}
data-testid="amount"
>
{amount}
</p>
)}
{showSlippage && !onAmountChange && amount !== "0.0" && (
<button
className="text-neutral-400 text-sm hover:underline"
onClick={() => disclosure.open("settingsDialog")}
>
Max Slippage: {slippage}%
</button>
)}
{onAmountChange && (
<input
className="w-full text-3xl font-medium focus:outline-none placeholder:text-neutral-300 h-10"
className="w-full text-3xl font-medium focus:outline-none placeholder:text-neutral-300 h-10 tabular-nums"
type="text"
placeholder="0.0"
value={amount}
@@ -159,58 +155,84 @@ const AssetInput: FC<Props> = ({
onAmountChange?.("");
}
}}
ref={inputRef}
/>
)}
</div>
{showBalance && address && (
<div className="flex items-center justify-between">
{isInitialLoading && (
<div className="w-[100px] h-[20.5px] bg-neutral-100 animate-pulse" />
<div className="flex items-center space-x-2 tabular-nums h-8">
{asset && parseFloat(amount) > 0 && (
<div className="text-neutral-400 text-sm">
<UsdValue
chainId={asset.originChainID}
denom={asset.originDenom}
value={amount}
context={onAmountChange ? "src" : "dest"}
/>
</div>
)}
{!isInitialLoading && selectedAssetBalance && (
<Fragment>
<p className="text-sm font-medium text-neutral-400">
AVAILABLE:{" "}
<span className="text-neutral-700">
{selectedAssetBalance} {asset?.symbol}
</span>
</p>
<div>
<button
className="font-extrabold text-xs bg-neutral-400 text-white px-3 py-1 rounded-md transition-transform enabled:hover:scale-110 enabled:hover:rotate-2 disabled:cursor-not-allowed"
disabled={maxButtonDisabled}
onClick={() => {
if (!selectedAssetBalance || !chain || !asset) {
return;
}

const feeDenom = getFeeDenom(chain.chainID);

let amount = selectedAssetBalance;

// if selected asset is the fee denom, subtract the fee
if (feeDenom && feeDenom.denom === asset.denom) {
const fee = getFee(chain.chainID);

const feeInt = parseFloat(
ethers.formatUnits(fee.toString(), asset.decimals),
).toFixed(asset.decimals);

amount = (
parseFloat(selectedAssetBalance) - parseFloat(feeInt)
).toFixed(asset.decimals);
}

onAmountChange?.(amount);
}}
{!onAmountChange && (
<UsdDiff.Value>
{({ isLoading, percentage }) => (
<div
className={clsx(
"text-sm",
isLoading && "hidden",
percentage > 0 ? "text-green-500" : "text-red-500",
)}
>
MAX
</button>
({percentage.toFixed(2)}%)
</div>
)}
</UsdDiff.Value>
)}
<div className="flex-grow" />
{showBalance && address && selectedAssetBalance && (
<div className="text-neutral-400 text-sm flex items-center space-x-2">
<div className="max-w-[16ch] truncate">
Balance: {selectedAssetBalance}
</div>
</Fragment>
<button
className={clsx(
"px-2 py-1 rounded-md uppercase font-semibold text-xs bg-[#FF486E] text-white",
"transition-transform enabled:hover:scale-110 enabled:hover:rotate-2 disabled:cursor-not-allowed",
)}
disabled={maxButtonDisabled}
onClick={() => {
if (!selectedAssetBalance || !chain || !asset) return;

const feeDenom = getFeeDenom(chain.chainID);

let amount = selectedAssetBalance;

// if selected asset is the fee denom, subtract the fee
if (feeDenom && feeDenom.denom === asset.denom) {
const fee = getFee(chain.chainID);

const feeInt = parseFloat(
ethers.formatUnits(fee.toString(), asset.decimals),
).toFixed(asset.decimals);

amount = (
parseFloat(selectedAssetBalance) - parseFloat(feeInt)
).toFixed(asset.decimals);
}

onAmountChange?.(amount);
}}
>
Max
</button>
</div>
)}
{showSlippage && !onAmountChange && amount !== "0.0" && (
<button
className="text-neutral-400 text-sm hover:underline"
onClick={() => disclosure.open("settingsDialog")}
>
Max Slippage: {slippage}%
</button>
)}
</div>
)}
</div>
</div>
<Toast
open={isError}
Loading

1 comment on commit a22908f

@vercel
Copy link

@vercel vercel bot commented on a22908f Nov 22, 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.