mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-08-02 19:25:41 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-contracts authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ActionStatus } from '@pezkuwi/react-components/Status/types';
|
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import { AddressRow, Button, Input, Modal } from '@pezkuwi/react-components';
|
|
import { useApi, useNonEmptyString } from '@pezkuwi/react-hooks';
|
|
import { keyring } from '@pezkuwi/ui-keyring';
|
|
|
|
import { ABI, InputName } from '../shared/index.js';
|
|
import { useTranslation } from '../translate.js';
|
|
import useAbi from '../useAbi.js';
|
|
import ValidateAddr from './ValidateAddr.js';
|
|
|
|
interface Props {
|
|
onClose: () => void;
|
|
}
|
|
|
|
function Add ({ onClose }: Props): React.ReactElement {
|
|
const { t } = useTranslation();
|
|
const { api } = useApi();
|
|
const [address, setAddress] = useState<string | null>(null);
|
|
const [isAddressValid, setIsAddressValid] = useState(false);
|
|
const [name, isNameValid, setName] = useNonEmptyString('New Contract');
|
|
const { abi, contractAbi, errorText, isAbiError, isAbiSupplied, isAbiValid, onChangeAbi, onRemoveAbi } = useAbi([null, null], null, true);
|
|
|
|
const _onAdd = useCallback(
|
|
(): void => {
|
|
const status: Partial<ActionStatus> = { action: 'create' };
|
|
|
|
if (!address || !abi || !name) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const json = {
|
|
contract: {
|
|
abi,
|
|
genesisHash: api.genesisHash.toHex()
|
|
},
|
|
name,
|
|
tags: []
|
|
};
|
|
|
|
keyring.saveContract(address, json);
|
|
|
|
status.account = address;
|
|
status.status = address ? 'success' : 'error';
|
|
status.message = 'contract added';
|
|
|
|
onClose();
|
|
} catch (error) {
|
|
console.error(error);
|
|
|
|
status.status = 'error';
|
|
status.message = (error as Error).message;
|
|
}
|
|
},
|
|
[abi, address, api, name, onClose]
|
|
);
|
|
|
|
const isValid = isAddressValid && isNameValid && isAbiValid;
|
|
|
|
return (
|
|
<Modal
|
|
header={t('Add an existing contract')}
|
|
onClose={onClose}
|
|
>
|
|
<Modal.Content>
|
|
<AddressRow
|
|
defaultName={name}
|
|
isValid
|
|
value={address || null}
|
|
>
|
|
<Input
|
|
autoFocus
|
|
isError={!isAddressValid}
|
|
label={t('contract address')}
|
|
onChange={setAddress}
|
|
value={address || ''}
|
|
/>
|
|
<ValidateAddr
|
|
address={address}
|
|
onChange={setIsAddressValid}
|
|
/>
|
|
<InputName
|
|
isContract
|
|
isError={!isNameValid}
|
|
onChange={setName}
|
|
value={name || undefined}
|
|
/>
|
|
<ABI
|
|
contractAbi={contractAbi}
|
|
errorText={errorText}
|
|
isError={isAbiError || !isAbiValid}
|
|
isSupplied={isAbiSupplied}
|
|
isValid={isAbiValid}
|
|
onChange={onChangeAbi}
|
|
onRemove={onRemoveAbi}
|
|
/>
|
|
</AddressRow>
|
|
</Modal.Content>
|
|
<Modal.Actions>
|
|
<Button
|
|
icon='save'
|
|
isDisabled={!isValid}
|
|
label={t('Save')}
|
|
onClick={_onAdd}
|
|
/>
|
|
</Modal.Actions>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
export default React.memo(Add);
|