Files
pwap/pezkuwi-sdk-ui/packages/page-contracts/src/Contracts/ValidateAddr.tsx
T
Claude c71ddb6e0d Add Pezkuwi SDK UI - Polkadot.js Apps clone
- Clone Polkadot.js Apps repository
- Update package.json with Pezkuwi branding
- Add Pezkuwi endpoint to production chains (wss://pezkuwichain.app:9944)
- Create comprehensive README for SDK UI
- Set up project structure with all packages

Next steps:
- Apply Kurdistan colors (Kesk, Sor, Zer, Spi + Black) to UI theme
- Replace logos with Pezkuwi branding
- Test build and deployment
2025-11-14 00:55:17 +00:00

59 lines
1.6 KiB
TypeScript

// Copyright 2017-2025 @polkadot/app-contracts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@polkadot/types';
import type { ContractInfo } from '@polkadot/types/interfaces';
import React, { useEffect, useState } from 'react';
import { InfoForInput } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { keyring } from '@polkadot/ui-keyring';
import { useTranslation } from '../translate.js';
interface Props {
address?: string | null;
onChange: (isValid: boolean) => void;
}
function ValidateAddr ({ address, onChange }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const contractInfo = useCall<Option<ContractInfo>>(api.query.contracts.contractInfoOf, [address]);
const [isAddress, setIsAddress] = useState(false);
const [isStored, setIsStored] = useState(false);
useEffect((): void => {
try {
keyring.decodeAddress(address || '');
setIsAddress(true);
} catch {
setIsAddress(false);
}
}, [address]);
useEffect((): void => {
setIsStored(!!contractInfo?.isSome);
}, [contractInfo]);
useEffect((): void => {
onChange(isAddress && isStored);
}, [isAddress, isStored, onChange]);
if (isStored || !isAddress) {
return null;
}
return (
<InfoForInput type='error'>
{isAddress
? t('Unable to find deployed contract code at the specified address')
: t('The value is not in a valid address format')
}
</InfoForInput>
);
}
export default React.memo(ValidateAddr);