mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-04-30 00:18:07 +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,41 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Result } from './types.js';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Output } from '@pezkuwi/react-components';
|
||||
import valueToText from '@pezkuwi/react-params/valueToText';
|
||||
|
||||
interface Props {
|
||||
results: Result[];
|
||||
}
|
||||
|
||||
function Results ({ results }: Props): React.ReactElement<Props> | null {
|
||||
if (!results.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// DEEBUG
|
||||
// console.error(results[results.length - 1].result?.toHex());
|
||||
|
||||
return (
|
||||
<section className='runtime--Results'>
|
||||
{results.map(({ def: { method, section, type }, error, id, result }): React.ReactNode => (
|
||||
<Output
|
||||
isError={!!error}
|
||||
key={id}
|
||||
label={`${id}: ${section}.${method}: ${type}`}
|
||||
value={
|
||||
error
|
||||
? error.message
|
||||
: <pre>{valueToText('', result)}</pre>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Results);
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ParamDef, RawParam } from '@pezkuwi/react-params/types';
|
||||
import type { DefinitionCallNamed } from '@pezkuwi/types/types';
|
||||
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
|
||||
import { Button, InputCalls } from '@pezkuwi/react-components';
|
||||
import Params from '@pezkuwi/react-params';
|
||||
import { getTypeDef } from '@pezkuwi/types/create';
|
||||
|
||||
import { useTranslation } from '../translate.js';
|
||||
|
||||
interface Props {
|
||||
onSubmit: (call: DefinitionCallNamed, values: RawParam[]) => void;
|
||||
}
|
||||
|
||||
interface State {
|
||||
isValid: boolean;
|
||||
method: DefinitionCallNamed | null;
|
||||
values: RawParam[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares the Runtime APIs that do not require extrinsic length to be prefixed when converting them to a u8 array.
|
||||
* REF: https://github.com/pezkuwi-js/apps/blob/master/packages/react-params/src/Param/BaseBytes.tsx#L99
|
||||
*/
|
||||
const WITHOUT_LENGTH = ['transactionPaymentApi'];
|
||||
|
||||
function Selection ({ onSubmit }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [{ isValid, method, values }, setState] = useState<State>({
|
||||
isValid: false,
|
||||
method: null,
|
||||
values: []
|
||||
});
|
||||
|
||||
const params = useMemo(
|
||||
() => method
|
||||
? method.params.map(({ name, type }): ParamDef => ({
|
||||
name,
|
||||
type: getTypeDef(type)
|
||||
}))
|
||||
: [],
|
||||
[method]
|
||||
);
|
||||
|
||||
const _nextState = useCallback(
|
||||
(newState: Partial<State>) => setState((prevState: State): State => {
|
||||
const { method = prevState.method, values = prevState.values } = newState;
|
||||
const isValid = values.reduce((isValid, value) => isValid && value.isValid === true, !!method && method.params.length <= values.length);
|
||||
|
||||
return {
|
||||
isValid,
|
||||
method,
|
||||
values
|
||||
};
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
const _onChangeMethod = useCallback(
|
||||
(method: DefinitionCallNamed) => _nextState({ method, values: [] }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
const _onChangeValues = useCallback(
|
||||
(values: RawParam[]) => _nextState({ values }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
const _onSubmit = useCallback(
|
||||
(): void => {
|
||||
method && onSubmit(method, values);
|
||||
},
|
||||
[onSubmit, method, values]
|
||||
);
|
||||
|
||||
return (
|
||||
<section className='runtime--Selection'>
|
||||
<InputCalls
|
||||
label={t('call the selected endpoint')}
|
||||
onChange={_onChangeMethod}
|
||||
/>
|
||||
{method && (
|
||||
<Params
|
||||
key={`${method.section}.${method.method}:params` /* force re-render on change */}
|
||||
onChange={_onChangeValues}
|
||||
params={params}
|
||||
withLength={!WITHOUT_LENGTH.includes(method.section)}
|
||||
/>
|
||||
)}
|
||||
<Button.Group>
|
||||
<Button
|
||||
icon='sign-in-alt'
|
||||
isDisabled={!isValid || !method}
|
||||
label={t('Submit Runtime call')}
|
||||
onClick={_onSubmit}
|
||||
/>
|
||||
</Button.Group>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Selection);
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { RawParam } from '@pezkuwi/react-params/types';
|
||||
import type { DefinitionCallNamed } from '@pezkuwi/types/types';
|
||||
import type { Result } from './types.js';
|
||||
|
||||
import React, { useCallback, useState } from 'react';
|
||||
|
||||
import { useApi } from '@pezkuwi/react-hooks';
|
||||
|
||||
import Results from './Results.js';
|
||||
import Selection from './Selection.js';
|
||||
|
||||
let id = 0;
|
||||
|
||||
function RuntimeApp (): React.ReactElement {
|
||||
const { api } = useApi();
|
||||
const [results, setResults] = useState<Result[]>([]);
|
||||
|
||||
const addResult = useCallback(
|
||||
(result: Result) => setResults((prev) => [result].concat(...prev)),
|
||||
[]
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(def: DefinitionCallNamed, values: RawParam[]): void => {
|
||||
api.call[def.section][def.method](...values.map(({ value }) => value))
|
||||
.then((result) => addResult({ def, id: ++id, result }))
|
||||
.catch((e): void => {
|
||||
addResult({ def, error: e as Error, id: ++id });
|
||||
console.error(e);
|
||||
});
|
||||
},
|
||||
[api, addResult]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Selection onSubmit={onSubmit} />
|
||||
<Results results={results} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(RuntimeApp);
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Codec, DefinitionCallNamed } from '@pezkuwi/types/types';
|
||||
|
||||
export interface Result {
|
||||
id: number;
|
||||
error?: Error;
|
||||
def: DefinitionCallNamed;
|
||||
result?: Codec;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime 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 Runtime from './Runtime/index.js';
|
||||
import { useTranslation } from './translate.js';
|
||||
|
||||
function RuntimeApp ({ basePath }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const itemsRef = useRef([
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'runtime',
|
||||
text: t('Calls')
|
||||
}
|
||||
]);
|
||||
|
||||
return (
|
||||
<main className='runtime--App'>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={itemsRef.current}
|
||||
/>
|
||||
<Routes>
|
||||
<Route path={basePath}>
|
||||
<Route
|
||||
element={
|
||||
<Runtime />
|
||||
}
|
||||
index
|
||||
/>
|
||||
</Route>
|
||||
</Routes>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(RuntimeApp);
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2025 @pezkuwi/app-runtime 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-runtime');
|
||||
}
|
||||
Reference in New Issue
Block a user