Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Col, Field, Form, Icon, Input, Row } from '@subwallet/react-ui';
import SwAvatar from '@subwallet/react-ui/es/sw-avatar';
import { PlusCircle } from 'phosphor-react';
import { FieldData } from 'rc-field-form/lib/interface';
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import styled, { useTheme } from 'styled-components';

import { isEthereumAddress } from '@polkadot/util-crypto';
Expand Down Expand Up @@ -87,6 +87,9 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
const decimals = Form.useWatch('decimals', form);
const tokenName = Form.useWatch('tokenName', form);
const selectedTokenType = Form.useWatch('type', form);
const contractAddress = Form.useWatch('contractAddress', form);

const contractRef = useRef<string|undefined>(contractAddress);

const chainChecker = useChainChecker();
const chainNetworkPrefix = useGetChainPrefixBySlug(selectedChain);
Expand Down Expand Up @@ -163,7 +166,7 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
}

if (validationResult.contractError) {
reject(new Error(t('Error validating this token')));
reject(new Error(t('Invalid ID')));
}

if (!validationResult.isExist && !validationResult.contractError) {
Expand All @@ -178,26 +181,24 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
})
.catch(() => {
setLoading(false);
reject(new Error(t('Error validating this token')));
reject(new Error(t('Invalid ID')));
});
} else if (isValidBrc20) {
console.log('successfull passed brc20');
setLoading(true);
validateCustomBrc20({
ticker: inputMetadata,
originChain: selectedChain,
type: selectedTokenType
})
.then((validationResult) => {
console.log('validationResultBRC20', validationResult);
setLoading(false);

if (validationResult.isExist) {
reject(new Error(t('Existed token')));
}

if (validationResult.contractError) {
reject(new Error(t('Error validating this token')));
reject(new Error(t('Invalid ticker')));
}

if (!validationResult.isExist && !validationResult.contractError) {
Expand All @@ -212,7 +213,7 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
})
.catch(() => {
setLoading(false);
reject(new Error(t('Error validating this token')));
reject(new Error(t('Invalid ticker')));
});
} else {
reject(t('Invalid contract address'));
Expand Down Expand Up @@ -329,6 +330,13 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
chainChecker(selectedChain);
}, [chainChecker, selectedChain]);

useEffect(() => {
if (loading && (contractRef.current !== contractAddress)) {
contractRef.current = contractAddress;
form.resetFields(['tokenName', 'symbol', 'decimals', 'priceId']);
}
}, [contractAddress, form, loading]);

return (
<PageWrapper
className={`import_token ${className}`}
Expand Down Expand Up @@ -420,7 +428,7 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
name={'decimals'}
>
<Field
content={decimals === -1 ? '' : decimals}
content={decimals === -1 ? '' : `${decimals}`}
placeholder={t<string>('Decimals')}
tooltip={t('Decimals')}
tooltipPlacement={'topLeft'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
>
<div>
<Field
content={tokenInfo.decimals}
content={`${tokenInfo.decimals ?? ''}`}
placeholder={t<string>('Decimals')}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-koni-ui/src/utils/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const simpleCheckForm = (allFields: FormFieldData[], requiredFields: stri

const needCheck = checkAll || (ignorePass && requirePass);

return !needCheck ? false : typeof value === 'boolean' ? false : !value;
return !needCheck ? false : typeof value === 'boolean' ? false : (typeof value === 'number' ? false : !value);
});

return {
Expand Down