Files
pwap/pezkuwi-sdk-ui/packages/react-signer/src/PayWithAsset.tsx
T
pezkuwichain 971df8edba Rebrand: Remove 3rd party chains, update domains to PezkuwiChain
- 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
2026-01-09 03:08:11 +03:00

85 lines
2.7 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/react-signer authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DropdownItemProps } from 'semantic-ui-react';
import type { ExtendedSignerOptions } from './types.js';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Dropdown, Modal } from '@pezkuwi/react-components';
import { useApi, usePayWithAsset } from '@pezkuwi/react-hooks';
import { getFeeAssetLocation } from '@pezkuwi/react-hooks/utils/getFeeAssetLocation';
import { BN } from '@pezkuwi/util';
import { useTranslation } from './translate.js';
interface Props {
onChangeFeeAsset: React.Dispatch<React.SetStateAction<ExtendedSignerOptions>>
}
const PayWithAsset = ({ onChangeFeeAsset }: Props) => {
const { t } = useTranslation();
const { api } = useApi();
const [selectedAssetValue, setSelectedAssetValue] = useState('-1');
const { assetOptions, isDisabled, onChange, selectedFeeAsset } = usePayWithAsset();
const nativeAsset = useMemo(
() => api.registry.chainTokens[0],
[api]
);
const onSearch = useCallback(
(options: DropdownItemProps[], value: string): DropdownItemProps[] =>
options.filter((options) => {
const { text: optText, value: optValue } = options as { text: string, value: number };
return parseInt(value) === optValue || optText.includes(value);
}),
[]
);
const onSelect = useCallback((value: string) => {
onChange(value === nativeAsset ? new BN(-1) : new BN(value), () => setSelectedAssetValue(value));
}, [nativeAsset, onChange]);
useEffect((): void => {
const info = assetOptions.find(({ value }) => value === selectedAssetValue);
// if no info found (usually happens on first load), select the first one automatically
if (!info) {
setSelectedAssetValue(assetOptions.at(0)?.value ?? nativeAsset);
}
}, [assetOptions, selectedAssetValue, nativeAsset]);
useEffect(() => {
onChangeFeeAsset((e) =>
({
...e,
assetId: getFeeAssetLocation(api, selectedFeeAsset),
feeAsset: selectedFeeAsset
})
);
}, [api, onChangeFeeAsset, selectedFeeAsset]);
useEffect(() => {
// Reselect native asset on component unmount
return () => onSelect(nativeAsset);
}, [nativeAsset, onSelect]);
return (
<Modal.Columns hint={t('By selecting this option, the transaction fee will be automatically deducted from the specified asset, ensuring a seamless and efficient payment process.')}>
<Dropdown
isDisabled={isDisabled}
label={t('asset to pay the fee')}
onChange={onSelect}
onSearch={onSearch}
options={assetOptions}
value={selectedAssetValue}
/>
</Modal.Columns>
);
};
export default React.memo(PayWithAsset);