Skip to content

Commit

Permalink
proper namespaces || coderabbit reviews || various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Nov 6, 2024
1 parent 9e8f38e commit c6693de
Show file tree
Hide file tree
Showing 55 changed files with 458 additions and 252 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion components/admins/components/stakingParams.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ParamsSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { ParamsSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { UpdateStakingParamsModal } from '../modals/updateStakingParamsModal';

interface StakingParamsProps {
Expand Down
13 changes: 9 additions & 4 deletions components/admins/components/validatorList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useMemo } from 'react';
import { ValidatorDetailsModal } from '../modals/validatorModal';
import { WarningModal } from '../modals/warningModal';
import { ValidatorSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { ValidatorSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import ProfileAvatar from '@/utils/identicon';
import Image from 'next/image';
import { TruncatedAddressWithCopy } from '@/components/react/addressCopy';
Expand All @@ -22,7 +22,6 @@ export default function ValidatorList({
admin,
activeValidators,
pendingValidators,
isLoading,
}: ValidatorListProps) {
const [active, setActive] = useState(true);
const [searchTerm, setSearchTerm] = useState('');
Expand Down Expand Up @@ -122,9 +121,13 @@ export default function ValidatorList({
{active ? 'No active validators found' : 'No pending validators'}
</div>
) : (
<table className="table w-full border-separate border-spacing-y-3">
<table
className="table w-full border-separate border-spacing-y-3"
role="grid"
aria-label="Validators list"
>
<thead>
<tr className="text-sm font-medium text-[#808080]">
<tr className="text-sm font-medium text-[#808080]" role="row">
<th className="bg-transparent text-left sticky top-0 bg-base-100 z-10">
Moniker
</th>
Expand All @@ -145,6 +148,8 @@ export default function ValidatorList({
key={validator.operator_address}
className="bg-[#FFFFFFCC] dark:bg-[#FFFFFF0F] hover:bg-[#FFFFFF66] dark:hover:bg-[#FFFFFF1A] text-black dark:text-white rounded-lg cursor-pointer"
onClick={() => handleRowClick(validator)}
role="row"
aria-label={`Validator ${validator.description.moniker}`}
>
<td className="rounded-l-[12px] py-4">
<div className="flex items-center space-x-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { screen, fireEvent, cleanup } from '@testing-library/react';
import { UpdateStakingParamsModal } from '@/components/admins/modals/updateStakingParamsModal';
import matchers from '@testing-library/jest-dom/matchers';
import { renderWithChainProvider } from '@/tests/render';
import { DurationSDKType } from '@chalabi/manifestjs/src/codegen/google/protobuf/duration';
import { DurationSDKType } from '@liftedinit/manifestjs/src/codegen/google/protobuf/duration';

expect.extend(matchers);

Expand Down
8 changes: 4 additions & 4 deletions components/admins/modals/updateStakingParamsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { chainName } from '@/config';
import { useFeeEstimation, useTx } from '@/hooks';
import { strangelove_ventures, cosmos, manifest } from '@chalabi/manifestjs';
import { ParamsSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { MsgUpdateStakingParams } from '@chalabi/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { Any } from '@chalabi/manifestjs/dist/codegen/google/protobuf/any';
import { strangelove_ventures, cosmos } from '@liftedinit/manifestjs';
import { ParamsSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { MsgUpdateStakingParams } from '@liftedinit/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { Any } from '@liftedinit/manifestjs/dist/codegen/google/protobuf/any';
import React, { useState, useEffect } from 'react';

interface UpdateStakingParamsModalProps {
Expand Down
8 changes: 4 additions & 4 deletions components/admins/modals/validatorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { BsThreeDots } from 'react-icons/bs';
import { DescriptionModal } from './descriptionModal';
import { chainName } from '@/config';
import { useTx, useFeeEstimation } from '@/hooks';
import { strangelove_ventures } from '@chalabi/manifestjs';
import { strangelove_ventures } from '@liftedinit/manifestjs';
import { useChain } from '@cosmos-kit/react';
import { cosmos } from '@chalabi/manifestjs';
import { Any } from '@chalabi/manifestjs/dist/codegen/google/protobuf/any';
import { MsgSetPower } from '@chalabi/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { cosmos } from '@liftedinit/manifestjs';
import { Any } from '@liftedinit/manifestjs/dist/codegen/google/protobuf/any';
import { MsgSetPower } from '@liftedinit/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { Formik, Form, Field, ErrorMessage, FieldProps } from 'formik';
import * as Yup from 'yup';
import { calculateIsUnsafe } from '@/utils/maths';
Expand Down
6 changes: 3 additions & 3 deletions components/admins/modals/warningModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { chainName } from '@/config';
import { useFeeEstimation, useTx } from '@/hooks';
import { cosmos, strangelove_ventures } from '@chalabi/manifestjs';
import { Any } from '@chalabi/manifestjs/dist/codegen/google/protobuf/any';
import { MsgRemoveValidator } from '@chalabi/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { cosmos, strangelove_ventures } from '@liftedinit/manifestjs';
import { Any } from '@liftedinit/manifestjs/dist/codegen/google/protobuf/any';
import { MsgRemoveValidator } from '@liftedinit/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx';
import { useChain } from '@cosmos-kit/react';
import React, { useState } from 'react';
import { PiWarning } from 'react-icons/pi';
Expand Down
2 changes: 1 addition & 1 deletion components/bank/components/sendBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SendForm from '../forms/sendForm';
import IbcSendForm from '../forms/ibcSendForm';
import { PiCaretDownBold } from 'react-icons/pi';
import Image from 'next/image';
import { CoinSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/base/v1beta1/coin';
import { CoinSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/base/v1beta1/coin';
import { CombinedBalanceInfo } from '@/utils/types';

export interface IbcChain {
Expand Down
49 changes: 33 additions & 16 deletions components/bank/forms/ibcSendForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useMemo } from 'react';
import { chainName } from '@/config';
import { useFeeEstimation, useTx } from '@/hooks';
import { ibc } from '@chalabi/manifestjs';
import { ibc } from '@liftedinit/manifestjs';
import { getIbcInfo } from '@/utils';
import { PiCaretDownBold } from 'react-icons/pi';
import { MdContacts } from 'react-icons/md';
Expand All @@ -16,7 +16,9 @@ import { shiftDigits, truncateString } from '@/utils';
import { SearchIcon } from '@/components/icons';
import { MFX_TOKEN_DATA } from '@/utils/constants'; // Import MFX_TOKEN_DATA
import { TailwindModal } from '@/components/react/modal';
import { formatTokenDisplayName } from '@/utils';

//TODO: use formatTokenDisplayName instead of repeating format
export default function IbcSendForm({
address,
destinationChain,
Expand Down Expand Up @@ -51,10 +53,14 @@ export default function IbcSendForm({
const [isContactsOpen, setIsContactsOpen] = useState(false);

// Adjusted filter logic to handle undefined metadata
const filteredBalances = balances?.filter(token => {
const displayName = token.metadata?.display ?? token.denom;
return displayName.toLowerCase().includes(searchTerm.toLowerCase());
});
const filteredBalances = useMemo(
() =>
balances?.filter(token => {
const displayName = token.metadata?.display ?? token.denom;
return displayName.toLowerCase().includes(searchTerm.toLowerCase());
}),
[balances, searchTerm]
);

// Set initialSelectedToken to 'mfx' if available
const initialSelectedToken =
Expand All @@ -78,20 +84,14 @@ export default function IbcSendForm({
const balance = parseFloat(selectedToken.amount) / Math.pow(10, exponent);
return value <= balance;
})
.test('leave-for-fees', '', function (value) {
.test('leave-for-fees', 'Insufficient balance for fees', function (value) {
const { selectedToken } = this.parent;
if (!selectedToken || !value || selectedToken.denom !== 'umfx') return true;

const exponent = selectedToken.metadata?.denom_units[1]?.exponent ?? 6;
const balance = parseFloat(selectedToken.amount) / Math.pow(10, exponent);

if (value > balance - 0.09) {
setFeeWarning('Remember to leave tokens for fees!');
} else {
setFeeWarning('');
}

return true;
return value <= balance - 0.09;
}),
selectedToken: Yup.object().required('Please select a token'),
memo: Yup.string().max(255, 'Memo must be less than 255 characters'),
Expand Down Expand Up @@ -181,6 +181,10 @@ export default function IbcSendForm({
<label
tabIndex={0}
aria-label="chain-selector"
role="combobox"
aria-expanded="false"
aria-controls="chain-dropdown"
aria-haspopup="listbox"
style={{ borderRadius: '12px' }}
className="btn btn-md btn-dropdown w-full justify-between border border-[#00000033] dark:border-[#FFFFFF33] bg-[#E0E0FF0A] dark:bg-[#E0E0FF0A]"
>
Expand All @@ -205,12 +209,20 @@ export default function IbcSendForm({

<ul
tabIndex={0}
role="listbox"
className="dropdown-content z-[100] menu p-2 shadow bg-base-300 rounded-lg w-full mt-1 dark:text-[#FFFFFF] text-[#161616]"
>
{ibcChains.map(chain => (
<li key={chain.id}>
<li key={chain.id} role="option" aria-selected={selectedChain === chain.id}>
<a
onClick={() => setSelectedChain(chain.id)}
onKeyDown={e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setSelectedChain(chain.id);
}
}}
tabIndex={0}
className="flex items-center"
aria-label={chain.name}
>
Expand All @@ -237,11 +249,16 @@ export default function IbcSendForm({
<div className="relative">
<input
type="text"
inputMode="decimal"
pattern="[0-9]*[.]?[0-9]*"
name="amount"
placeholder="0.00"
value={values.amount}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setFieldValue('amount', e.target.value);
const value = e.target.value;
if (value === '' || /^\d*\.?\d*$/.test(value)) {
setFieldValue('amount', e.target.value);
}
}}
style={{ borderRadius: '12px' }}
className="input input-md border border-[#00000033] dark:border-[#FFFFFF33] bg-[#E0E0FF0A] dark:bg-[#E0E0FF0A] w-full pr-24 dark:text-[#FFFFFF] text-[#161616]"
Expand Down
13 changes: 10 additions & 3 deletions components/bank/forms/sendForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { chainName } from '@/config';
import { useFeeEstimation, useTx } from '@/hooks';
import { cosmos } from '@chalabi/manifestjs';
import { cosmos } from '@liftedinit/manifestjs';
import { PiCaretDownBold } from 'react-icons/pi';
import { shiftDigits, truncateString } from '@/utils';
import { CombinedBalanceInfo } from '@/utils/types';
Expand Down Expand Up @@ -68,13 +68,16 @@ export default function SendForm({
const exponent = selectedToken.metadata?.denom_units[1]?.exponent ?? 6;
const balance = parseFloat(selectedToken.amount) / Math.pow(10, exponent);

if (value > balance - 0.09) {
const MIN_FEE_BUFFER = 0.09;
const hasInsufficientBuffer = value > balance - MIN_FEE_BUFFER;

if (hasInsufficientBuffer) {
setFeeWarning('Remember to leave tokens for fees!');
} else {
setFeeWarning('');
}

return true;
return !hasInsufficientBuffer;
}),
selectedToken: Yup.object().required('Please select a token'),
memo: Yup.string().max(255, 'Memo must be less than 255 characters'),
Expand Down Expand Up @@ -150,6 +153,8 @@ export default function SendForm({
<input
className="input input-md border border-[#00000033] dark:border-[#FFFFFF33] bg-[#E0E0FF0A] dark:bg-[#E0E0FF0A] w-full pr-24 dark:text-[#FFFFFF] text-[#161616]"
name="amount"
inputMode="decimal"
pattern="[0-9]*[.]?[0-9]*"
placeholder="0.00"
style={{ borderRadius: '12px' }}
value={values.amount}
Expand Down Expand Up @@ -191,6 +196,8 @@ export default function SendForm({
</label>
<ul
tabIndex={0}
role="listbox"
aria-label="Token selection"
className="dropdown-content z-20 p-2 shadow bg-base-300 rounded-lg w-full mt-1 max-h-72 min-w-44 overflow-y-auto dark:text-[#FFFFFF] text-[#161616]"
>
<li className=" bg-base-300 z-30 hover:bg-transparent h-full mb-2">
Expand Down
2 changes: 1 addition & 1 deletion components/bank/modals/txInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function InfoItem({
<div className="flex items-center">
<TruncatedAddressWithCopy address={value} slice={8} />
<a
href={`https://testnet.manifest.explorers.guru/${label === 'TRANSACTION HASH' ? 'transaction' : 'account'}/${label.includes('TRANSACTION') ? value.toUpperCase() : value}`}
href={`${process.env.NEXT_PUBLIC_TESTNET_EXPLORER_URL}/${label === 'TRANSACTION HASH' ? 'transaction' : 'account'}/${label.includes('TRANSACTION') ? value.toUpperCase() : value}`}
target="_blank"
rel="noopener noreferrer"
className="ml-2 text-primary hover:text-primary/50"
Expand Down
4 changes: 2 additions & 2 deletions components/factory/components/DenomInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TruncatedAddressWithCopy } from '@/components/react/addressCopy';
import { shiftDigits } from '@/utils';
import { MetadataSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank';
import { MetadataSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank';
import { DenomInfoModal } from '../modals';
import { UpdateDenomMetadataModal } from '../modals';
import { CoinSDKType } from '@chalabi/manifestjs/dist/codegen/cosmos/base/v1beta1/coin';
import { CoinSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/base/v1beta1/coin';

export default function DenomInfo({
denom,
Expand Down
47 changes: 25 additions & 22 deletions components/factory/components/MyDenoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default function MyDenoms({
onClose={handleCloseModal}
/>
<MintModal
admin={poaAdmin ?? ''}
admin={poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'}
isPoaAdminLoading={isPoaAdminLoading}
denom={selectedDenom}
address={address}
Expand Down Expand Up @@ -258,7 +258,7 @@ export default function MyDenoms({
onClose={handleCloseModal}
/>
<MultiBurnModal
admin={address}
admin={poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj'}
address={address}
denom={selectedDenom}
exponent={selectedDenom?.denom_units[1]?.exponent ?? 0}
Expand All @@ -283,6 +283,23 @@ function TokenRow({
onBurn: (e: React.MouseEvent) => void;
onUpdate: (e: React.MouseEvent) => void;
}) {
// Add safety checks for the values
const exponent = denom?.denom_units?.[1]?.exponent ?? 0;
const totalSupply = denom?.totalSupply ?? '0';
const balance = denom?.balance ?? '0';

// Format numbers safely
const formatAmount = (amount: string) => {
try {
return Number(shiftDigits(amount, -exponent)).toLocaleString(undefined, {
maximumFractionDigits: exponent,
});
} catch (error) {
console.warn('Error formatting amount:', error);
return '0';
}
};

return (
<tr
className="hover:bg-[#FFFFFF66] dark:hover:bg-[#FFFFFF1A] dark:bg-[#FFFFFF0F] bg-[#FFFFFF] text-black dark:text-white rounded-lg cursor-pointer"
Expand All @@ -297,31 +314,17 @@ function TokenRow({
<td className="w-1/4 sm:table-cell hidden">{truncateString(denom.symbol, 20)}</td>
<td className="w-2/4 sm:w-1/4">
<div className="flex flex-col sm:flex-row sm:items-center">
<span className="sm:mr-2">
{Number(shiftDigits(denom.totalSupply, -denom.denom_units[1]?.exponent)).toLocaleString(
undefined,
{
maximumFractionDigits: denom.denom_units[1]?.exponent ?? 6,
}
)}
</span>
<span className=" font-extralight ">
{truncateString(denom.display, 10).toUpperCase()}
<span className="sm:mr-2">{formatAmount(totalSupply)}</span>
<span className="font-extralight">
{truncateString(denom?.display ?? '', 10).toUpperCase()}
</span>
</div>
</td>
<td className="w-2/4 sm:w-1/4">
<div className="flex flex-col sm:flex-row sm:items-center">
<span className="sm:mr-2">
{Number(shiftDigits(denom.balance, -denom.denom_units[1]?.exponent)).toLocaleString(
undefined,
{
maximumFractionDigits: denom.denom_units[1]?.exponent ?? 6,
}
)}
</span>
<span className="font-extralight ">
{truncateString(denom.display, 10).toUpperCase()}
<span className="sm:mr-2">{formatAmount(balance)}</span>
<span className="font-extralight">
{truncateString(denom?.display ?? '', 10).toUpperCase()}
</span>
</div>
</td>
Expand Down
Loading

0 comments on commit c6693de

Please sign in to comment.