mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-06-12 15:51:14 +00:00
feat: initial Pezkuwi Apps rebrand from polkadot-apps
Rebranded terminology: - Polkadot → Pezkuwi - Kusama → Dicle - Westend → Zagros - Rococo → PezkuwiChain - Substrate → Bizinikiwi - parachain → teyrchain Custom logos with Kurdistan brand colors (#e6007a → #86e62a): - bizinikiwi-hexagon.svg - sora-bizinikiwi.svg - hezscanner.svg - heztreasury.svg - pezkuwiscan.svg - pezkuwistats.svg - pezkuwiassembly.svg - pezkuwiholic.svg
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '@pezkuwi/util';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { InputAddress, Labelled, styled } from '@pezkuwi/react-components';
|
||||
import { Nonce } from '@pezkuwi/react-query';
|
||||
import { BN_ZERO } from '@pezkuwi/util';
|
||||
|
||||
import { useTranslation } from '../translate.js';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
defaultValue?: string | null;
|
||||
isError?: boolean;
|
||||
onChange: (accountId: string | undefined | null, accountNonce: BN) => void;
|
||||
}
|
||||
|
||||
function Account ({ className = '', defaultValue, isError, onChange }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [accountId, setAccountId] = useState<string | null | undefined>(defaultValue);
|
||||
const [accountNonce, setAccountNonce] = useState(BN_ZERO);
|
||||
|
||||
useEffect((): void => {
|
||||
onChange(accountId, accountNonce);
|
||||
}, [accountId, accountNonce, onChange]);
|
||||
|
||||
return (
|
||||
<StyledDiv className={`${className} ui--row`}>
|
||||
<div className='large'>
|
||||
<InputAddress
|
||||
defaultValue={defaultValue}
|
||||
isError={isError}
|
||||
label={t('sign data from account')}
|
||||
onChange={setAccountId}
|
||||
placeholder='0x...'
|
||||
type='account'
|
||||
/>
|
||||
</div>
|
||||
{accountId && (
|
||||
<Labelled
|
||||
className='small'
|
||||
label={t('with an index of')}
|
||||
>
|
||||
<Nonce
|
||||
callOnResult={setAccountNonce}
|
||||
className='ui disabled dropdown selection'
|
||||
params={accountId}
|
||||
/>
|
||||
</Labelled>
|
||||
)}
|
||||
</StyledDiv>
|
||||
);
|
||||
}
|
||||
|
||||
const StyledDiv = styled.div`
|
||||
box-sizing: border-box;
|
||||
padding-left: 2em;
|
||||
`;
|
||||
|
||||
export default React.memo(Account);
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { QueueTx } from '@pezkuwi/react-components/Status/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Output, styled } from '@pezkuwi/react-components';
|
||||
import valueToText from '@pezkuwi/react-params/valueToText';
|
||||
import { isUndefined } from '@pezkuwi/util';
|
||||
|
||||
interface Props {
|
||||
queue: QueueTx[];
|
||||
}
|
||||
|
||||
function Results ({ queue = [] }: Props): React.ReactElement<Props> | null {
|
||||
const filtered = queue
|
||||
.filter(({ error, result }) => !isUndefined(error) || !isUndefined(result))
|
||||
.reverse();
|
||||
|
||||
if (!filtered.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<StyledSection className='rpc--Results'>
|
||||
{filtered.map(({ error, id, result, rpc: { method, section, type } }): React.ReactNode => (
|
||||
<Output
|
||||
isError={!!error}
|
||||
key={id}
|
||||
label={`${id}: ${section}.${method}: ${type}`}
|
||||
value={
|
||||
error
|
||||
? error.message
|
||||
: <pre>{valueToText('', result as null)}</pre>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</StyledSection>
|
||||
);
|
||||
}
|
||||
|
||||
const StyledSection = styled.section`
|
||||
.ui--Output > label {
|
||||
text-transform: none;
|
||||
}
|
||||
`;
|
||||
|
||||
export default React.memo(Results);
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { QueueTxRpcAdd } from '@pezkuwi/react-components/Status/types';
|
||||
import type { ParamDef, RawParam } from '@pezkuwi/react-params/types';
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
|
||||
import { Button, InputRpc } from '@pezkuwi/react-components';
|
||||
import Params from '@pezkuwi/react-params';
|
||||
import { getTypeDef } from '@pezkuwi/types/create';
|
||||
import jsonrpc from '@pezkuwi/types/interfaces/jsonrpc';
|
||||
import { isNull } from '@pezkuwi/util';
|
||||
|
||||
import { useTranslation } from '../translate.js';
|
||||
|
||||
interface Props {
|
||||
queueRpc: QueueTxRpcAdd;
|
||||
}
|
||||
|
||||
interface State {
|
||||
isValid: boolean;
|
||||
rpc: DefinitionRpcExt;
|
||||
values: RawParam[];
|
||||
}
|
||||
|
||||
const defaultMethod = jsonrpc.author.submitExtrinsic;
|
||||
|
||||
function Selection ({ queueRpc }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [{ isValid, rpc, values }, setState] = useState<State>({
|
||||
isValid: false,
|
||||
rpc: defaultMethod,
|
||||
values: []
|
||||
});
|
||||
|
||||
const params = useMemo(
|
||||
() => rpc.params.map(({ isOptional, name, type }): ParamDef => ({
|
||||
name,
|
||||
type: getTypeDef(isOptional ? `Option<${type}>` : type)
|
||||
})),
|
||||
[rpc]
|
||||
);
|
||||
|
||||
const _nextState = useCallback(
|
||||
(newState: Partial<State>) => setState((prevState: State): State => {
|
||||
const { rpc = prevState.rpc, values = prevState.values } = newState;
|
||||
const reqCount = rpc.params.reduce((count, { isOptional }) => count + (isOptional ? 0 : 1), 0);
|
||||
const isValid = values.reduce((isValid, value) => isValid && value.isValid === true, reqCount <= values.length);
|
||||
|
||||
return {
|
||||
isValid,
|
||||
rpc,
|
||||
values
|
||||
};
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
const _onChangeMethod = useCallback(
|
||||
(rpc: DefinitionRpcExt) => _nextState({ rpc, values: [] }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
const _onChangeValues = useCallback(
|
||||
(values: RawParam[]) => _nextState({ values }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
const _onSubmit = useCallback(
|
||||
(): void => queueRpc({
|
||||
rpc,
|
||||
values: values
|
||||
.filter(({ value }, idx) => !rpc.params[idx].isOptional || !isNull(value))
|
||||
.map(({ value }): any => value)
|
||||
}),
|
||||
[queueRpc, rpc, values]
|
||||
);
|
||||
|
||||
return (
|
||||
<section className='rpc--Selection'>
|
||||
<InputRpc
|
||||
defaultValue={defaultMethod}
|
||||
label={t('call the selected endpoint')}
|
||||
onChange={_onChangeMethod}
|
||||
/>
|
||||
<Params
|
||||
key={`${rpc.section}.${rpc.method}:params` /* force re-render on change */}
|
||||
onChange={_onChangeValues}
|
||||
params={params}
|
||||
/>
|
||||
<Button.Group>
|
||||
<Button
|
||||
icon='sign-in-alt'
|
||||
isDisabled={!isValid}
|
||||
label={t('Submit RPC call')}
|
||||
onClick={_onSubmit}
|
||||
/>
|
||||
</Button.Group>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Selection);
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { useQueue } from '@pezkuwi/react-hooks';
|
||||
|
||||
import Results from './Results.js';
|
||||
import Selection from './Selection.js';
|
||||
|
||||
function RpcApp (): React.ReactElement {
|
||||
const { queueRpc, txqueue } = useQueue();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Selection queueRpc={queueRpc} />
|
||||
<Results queue={txqueue} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(RpcApp);
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AppProps as Props } from '@pezkuwi/react-components/types';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import { Route, Routes } from 'react-router';
|
||||
|
||||
import { Tabs } from '@pezkuwi/react-components';
|
||||
|
||||
import Rpc from './Rpc/index.js';
|
||||
import { useTranslation } from './translate.js';
|
||||
|
||||
function RpcApp ({ basePath }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const itemsRef = useRef([
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'rpc',
|
||||
text: t('Submission')
|
||||
}
|
||||
]);
|
||||
|
||||
return (
|
||||
<main className='rpc--App'>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={itemsRef.current}
|
||||
/>
|
||||
<Routes>
|
||||
<Route path={basePath}>
|
||||
<Route
|
||||
element={
|
||||
<Rpc />
|
||||
}
|
||||
index
|
||||
/>
|
||||
</Route>
|
||||
</Routes>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(RpcApp);
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-rpc authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { useTranslation as useTranslationBase } from 'react-i18next';
|
||||
|
||||
export function useTranslation (): { t: (key: string, options?: { replace: Record<string, unknown> }) => string } {
|
||||
return useTranslationBase('app-rpc');
|
||||
}
|
||||
Reference in New Issue
Block a user