From 53d6634cae03c774ba49405ebcdd7679d46748a5 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Tue, 5 Nov 2024 19:17:45 +0000 Subject: [PATCH] clean up --- packages/ui/package.json | 3 - packages/ui/src/components/CallInfo.tsx | 124 ------------------ packages/ui/src/contexts/AccountsContext.tsx | 107 --------------- .../ui/src/contexts/PeopleChainApiContext.tsx | 6 - packages/ui/src/hooks/useDisplayLoader.tsx | 10 -- packages/ui/src/hooks/useSigningCallback.tsx | 60 --------- packages/ui/src/pages/Creation/index.tsx | 6 - packages/ui/src/utils/decode.ts | 118 ----------------- packages/ui/src/utils/extinsicErrorChecks.ts | 103 --------------- yarn.lock | 7 +- 10 files changed, 2 insertions(+), 542 deletions(-) delete mode 100644 packages/ui/src/utils/decode.ts delete mode 100644 packages/ui/src/utils/extinsicErrorChecks.ts diff --git a/packages/ui/package.json b/packages/ui/package.json index 47a87c2d..b304f67e 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -13,9 +13,7 @@ "@polkadot-api/tx-utils": "^0.0.4", "@polkadot-labs/hdkd": "^0.0.8", "@polkadot-labs/hdkd-helpers": "^0.0.8", - "@polkadot/api": "^13.1.1", "@polkadot/react-identicon": "^3.10.1", - "@polkadot/types": "^13.1.1", "@polkadot/util-crypto": "^13.1.1", "@reactive-dot/core": "^0.19.0", "@reactive-dot/react": "^0.19.0", @@ -33,7 +31,6 @@ "react-icons": "^5.1.0", "react-router-dom": "^6.22.3", "reactflow": "^11.11.1", - "rxjs": "^7.8.1", "typescript": "5.4.5", "vite": "^5.4.7" }, diff --git a/packages/ui/src/components/CallInfo.tsx b/packages/ui/src/components/CallInfo.tsx index 3cd94102..44b493e9 100644 --- a/packages/ui/src/components/CallInfo.tsx +++ b/packages/ui/src/components/CallInfo.tsx @@ -32,135 +32,11 @@ interface CreateTreeParams { api: ApiType } -// const handleCallDisplay = ({ -// call, -// decimals, -// unit, -// api, -// key -// }: { -// call: Transaction['decodedCall'] -// decimals: number -// unit: string -// key: string -// api: ApiPromise -// }) => { -// const name = `${call.type}.${call.value.type}` -// return ( -// <> -//
  • {name}
  • -// {createUlTree({ -// name: name, -// args: call.value.value, -// decimals, -// unit, -// api -// })} -// -// ) -// } - -// const handleBatchDisplay = ({ -// value, -// decimals, -// unit, -// api, -// key -// }: { -// value: any[] -// decimals: number -// unit: string -// key: string -// api: ApiPromise -// }) => -// value.map((call: any, index: number) => -// handleCallDisplay({ call, decimals, unit, api, key: `${key}-${index}` }) -// ) - -// const handleBalanceDisplay = ({ -// value, -// decimals, -// unit, -// key -// }: { -// value: any -// decimals: number -// unit: string -// key: string -// }) => { -// const balance = formatBigIntBalance(value.replace(/,/g, ''), decimals, { -// withThousandDelimiter: true, -// tokenSymbol: unit, -// numberAfterComma: 4 -// }) - -// return ( -//
  • -// {key}: {balance} -//
  • -// ) -// } - -// const handleValueDisplay = ({ value, typeName }: { value: any; typeName: string | undefined }) => -// typeName === 'bool' ? (value ? 'true' : 'false') : value - -// const getTypeName = (index: number, name: string, api: ApiPromise) => { -// const [pallet, method] = name.split('.') -// const metaArgs = !!pallet && !!method && api.tx[pallet][method]?.meta?.args - -// return ( -// (!!metaArgs && metaArgs[index] && (metaArgs[index].toHuman().typeName as string)) || undefined -// ) -// } - const createUlTree = ({ name, decodedCall }: CreateTreeParams) => { if (!decodedCall) return if (!name) return return {JSONprint(decodedCall.value.value)} - // return ( - // - // ) } const filterProxyProxy = (agg: Props['aggregatedData']): Props['aggregatedData'] => { diff --git a/packages/ui/src/contexts/AccountsContext.tsx b/packages/ui/src/contexts/AccountsContext.tsx index 7226d1b4..4d4e934e 100644 --- a/packages/ui/src/contexts/AccountsContext.tsx +++ b/packages/ui/src/contexts/AccountsContext.tsx @@ -50,25 +50,11 @@ const AccountContextProvider = ({ children }: AccountContextProps) => { ownAccountList?.[0] ) const [isConnectionDialogOpen, setIsConnectionDialogOpen] = useState(false) - // const [isAccountLoading, setIsAccountLoading] = useState(false) - // const [isExtensionError, setIsExtensionError] = useState(false) - // const [selectedSigner, setSelectedSigner] = useState() const [isAllowedToConnectToExtension, setIsAllowedToConnectToExtension] = useState(false) const ownAddressList = useMemo( () => (ownAccountList || []).map((a) => a.address), [ownAccountList] ) - // const [accountGotRequested, setAccountGotRequested] = useState(false) - // const [isLocalStorageSetupDone, setIsLocalStorageSetupDone] = useState(false) - // update the current account list with the right network prefix - // this will run for every network change - // useEffect(() => { - // if (chainInfo) { - // setOwnAccountList((prev) => { - // return encodeAccounts(prev, chainInfo.ss58Format) as InjectedAccountWithMeta[] - // }) - // } - // }, [chainInfo]) const getAccountByAddress = useCallback( (address: string) => { @@ -87,82 +73,6 @@ const AccountContextProvider = ({ children }: AccountContextProps) => { setSelected(account) }, []) - // const getaccountList = useCallback( - // async (isEthereum: boolean): Promise => { - // web3Enable(DAPP_NAME) - // .then((ext) => { - // if (ext.length === 0) { - // setIsExtensionError(true) - // } - // }) - // .catch((e) => { - // console.log('ooops web3Enable failed') - // console.error(e) - // setIsExtensionError(true) - // }) - // .finally(() => { - // setIsAccountLoading(false) - // }) - - // web3AccountsSubscribe( - // (accountList) => { - // if (accountList.length === 0) { - // setIsExtensionError(true) - // return - // } - - // let listToPersist = accountList - // //lower case ethereum addresses - // if (isEthereum) { - // listToPersist = accountList.map((account) => ({ - // ...account, - // address: account.address.toLowerCase() - // })) - // } - - // setOwnAccountList([...listToPersist]) - - // if (listToPersist.length > 0) { - // const previousAccountAddress = localStorage.getItem(LOCALSTORAGE_SELECTED_ACCOUNT_KEY) - // const account = previousAccountAddress && getAccountByAddress(previousAccountAddress) - - // selectAccount(account || listToPersist[0]) - // } - // }, - // { - // ss58Format: chainInfo?.ss58Format, - // accountType: isEthereum ? ['ethereum'] : undefined - // } - // ).catch((error) => { - // setIsExtensionError(true) - // console.error('web3AccountSubscribe error', error) - // }) - // }, - // [chainInfo?.ss58Format, getAccountByAddress, selectAccount] - // ) - - // useEffect(() => { - // if (isExtensionError || ownAccountList.length > 0 || isAccountLoading || !chainInfo) return - - // if (!accountGotRequested && isAllowedToConnectToExtension) { - // setAccountGotRequested(true) - // setIsAccountLoading(true) - // // delay the request by 500ms - // // race condition see https://github.com/polkadot-js/extension/issues/938 - // setTimeout(() => { - // getaccountList(chainInfo.isEthereum) - // }, 500) - // } - // }, [ - // ownAccountList, - // getaccountList, - // isAccountLoading, - // isAllowedToConnectToExtension, - // chainInfo, - // isExtensionError, - // accountGotRequested - // ]) - useEffect(() => { if (!isAllowedToConnectToExtension) { const previouslyAllowed = localStorage.getItem(LOCALSTORAGE_ALLOWED_CONNECTION_KEY) @@ -173,19 +83,6 @@ const AccountContextProvider = ({ children }: AccountContextProps) => { } }, [isAllowedToConnectToExtension]) - // useEffect(() => { - // if (!selectedAccount) return - - // // to be able to retrieve the signer interface from this account - // // we can use web3FromSource which will return an InjectedExtension type - - // web3FromSource(selectedAccount.meta.source) - // .then((injector) => { - // setSelectedSigner(injector.signer as PolkadotSigner) - // }) - // .catch(console.error) - // }) - return ( { ownAccountList: ownAccountList || [], ownAddressList, selectAccount, - // isAccountLoading, - // isExtensionError, getAccountByAddress, isConnectionDialogOpen, setIsConnectionDialogOpen, - // selectedSigner, allowConnectionToExtension, isAllowedToConnectToExtension - // isLocalStorageSetupDone }} > {children} diff --git a/packages/ui/src/contexts/PeopleChainApiContext.tsx b/packages/ui/src/contexts/PeopleChainApiContext.tsx index f1cfb769..a1167610 100644 --- a/packages/ui/src/contexts/PeopleChainApiContext.tsx +++ b/packages/ui/src/contexts/PeopleChainApiContext.tsx @@ -24,12 +24,6 @@ export interface ChainInfoHuman { tokenSymbol: string } -// interface RawChainInfoHuman { -// ss58Format: string -// tokenDecimals: string[] -// tokenSymbol: string[] -// } - const PplApiContext = createContext(undefined) const PplApiContextProvider = ({ children }: ApiContextProps) => { diff --git a/packages/ui/src/hooks/useDisplayLoader.tsx b/packages/ui/src/hooks/useDisplayLoader.tsx index 9f9a39f9..c995033e 100644 --- a/packages/ui/src/hooks/useDisplayLoader.tsx +++ b/packages/ui/src/hooks/useDisplayLoader.tsx @@ -9,7 +9,6 @@ export const useDisplayLoader = () => { const { isLoading: isLoadingMultisigs } = useMultiProxy() const { api } = useApi() const { selectedNetworkInfo } = useNetwork() - // const { isAccountLoading, isLocalStorageSetupDone } = useAccounts() const { isInitialized: isWatchAddressInitialized } = useWatchedAddresses() if (!isWatchAddressInitialized) { @@ -30,15 +29,6 @@ export const useDisplayLoader = () => { ) } - // if (isAccountLoading) { - // return ( - // - // ) - // } - if (isLoadingMultisigs) { return ( { console.log(JSONprint(event)) @@ -108,38 +80,6 @@ export const useSigningCallback = ({ onSubmitting, onSuccess, onFinalized, onErr if (event.type === 'finalized') { console.log('finalized:', event) onFinalized && onFinalized() - - // event.events.forEach(({type, value}) => { - // const { data, method, section } = event - - // console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString()) - - // const incomplete = getIncompleteMessage({ event } as EventRecord) - - // // check if multisig or proxy or batch has an error - // if (incomplete) { - // errorInfo = incomplete - // } - - // if the extrinsic fails alltogether - // if (!errorInfo && api.events.system.ExtrinsicFailed.is(event)) { - // // extract the data for this event - // const dispatchError = data[0] - - // // decode the error - // if ((dispatchError as any).isModule) { - // // for module errors, we have the section indexed, lookup - // // (For specific known errors, we can also do a check against the - // // api.errors...is(dispatchError.asModule) guard) - // const decoded = api.registry.findMetaError((dispatchError as any).asModule) - - // errorInfo = `${decoded.docs} - ${decoded.section}.${decoded.name}` - // } else { - // // Other, CannotLookup, BadOrigin, no extra info - // errorInfo = dispatchError.toString() - // } - // } - // }) } }, error: (error: Error) => { diff --git a/packages/ui/src/pages/Creation/index.tsx b/packages/ui/src/pages/Creation/index.tsx index bf82854a..a75e01e7 100644 --- a/packages/ui/src/pages/Creation/index.tsx +++ b/packages/ui/src/pages/Creation/index.tsx @@ -296,12 +296,6 @@ const MultisigCreation = ({ className }: Props) => { multiAddress && addName(name, multiAddress) setIsSubmitted(true) - // const remarkTx = await api.txFromCallData( - // Binary.fromHex( - // '0x1701020004d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000004c637265617465642077697468204d756c7469780000', - // ), - // ); - remarkCall .signSubmitAndWatch(selectedAccount.polkadotSigner, { at: 'best' }) .subscribe(signCallBack) diff --git a/packages/ui/src/utils/decode.ts b/packages/ui/src/utils/decode.ts deleted file mode 100644 index 54e32c3a..00000000 --- a/packages/ui/src/utils/decode.ts +++ /dev/null @@ -1,118 +0,0 @@ -// // Copyright 2017-2022 Parity Technologies (UK) Ltd. -// // This file is part of Substrate API Sidecar. -// // -// // Substrate API Sidecar is free software: you can redistribute it and/or modify -// // it under the terms of the GNU General Public License as published by -// // the Free Software Foundation, either version 3 of the License, or -// // (at your option) any later version. -// // -// // This program is distributed in the hope that it will be useful, -// // but WITHOUT ANY WARRANTY; without even the implied warranty of -// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// // GNU General Public License for more details. -// // -// // You should have received a copy of the GNU General Public License -// // along with this program. If not, see . - -// export interface ISanitizedCall { -// [key: string]: unknown -// method: string | IFrameMethod -// callIndex?: Uint8Array | string -// args: ISanitizedArgs -// hash: `0x${string}` -// } - -// export interface ISanitizedArgs { -// call?: ISanitizedCall -// calls?: ISanitizedCall[] -// [key: string]: unknown -// } - -// export interface IFrameMethod { -// pallet: string -// method: string -// } - -// export function isFrameMethod(thing: unknown): thing is IFrameMethod { -// return ( -// typeof (thing as IFrameMethod).pallet === 'string' && -// typeof (thing as IFrameMethod).method === 'string' -// ) -// } - -// /** -// * Helper function for `parseGenericCall`. -// * -// * @param argsArray array of `Codec` values -// * @param registry type registry of the block the call belongs to -// */ -// export function parseArrayGenericCalls( -// argsArray: Codec[], -// registry: Registry -// ): (Codec | ISanitizedCall)[] { -// return argsArray.map((argument) => { -// if (argument instanceof GenericCall) { -// return parseGenericCall(argument as GenericCall, registry) -// } - -// return argument -// }) -// } - -// /** -// * Recursively parse a `GenericCall` in order to label its arguments with -// * their param names and give a human friendly method name (opposed to just a -// * call index). Parses `GenericCall`s that are nested as arguments. -// * -// * @param genericCall `GenericCall` -// * @param registry type registry of the block the call belongs to -// */ -// export function parseGenericCall(genericCall: GenericCall, registry: Registry): ISanitizedCall { -// const newArgs: any = {} - -// // Pull out the struct of arguments to this call -// const callArgs = genericCall.get('args') as Struct - -// // Make sure callArgs exists and we can access its keys -// if (callArgs && callArgs.defKeys) { -// // paramName is a string -// for (const paramName of callArgs.defKeys) { -// const argument = callArgs.get(paramName) - -// if (Array.isArray(argument)) { -// newArgs[paramName] = parseArrayGenericCalls(argument, registry) -// } else if (argument instanceof GenericCall) { -// // console.log("callData", argument.toHex()) -// // console.log('argument.toHuman', argument.toHuman()) -// newArgs['callData'] = argument.toHex() -// newArgs[paramName] = parseGenericCall(argument as GenericCall, registry) -// } else if ( -// argument && -// paramName === 'call' && -// ['Bytes', 'WrapperKeepOpaque', 'WrapperOpaque'].includes(argument?.toRawType()) -// ) { -// // multiSig.asMulti.args.call is either an OpaqueCall (Vec), -// // WrapperKeepOpaque, or WrapperOpaque that we -// // serialize to a polkadot-js Call and parse so it is not a hex blob. -// try { -// const call = registry.createType('Call', argument.toHex()) -// newArgs['callData'] = call.toHex() -// newArgs[paramName] = parseGenericCall(call, registry) -// } catch { -// newArgs[paramName] = argument -// } -// } else { -// newArgs[paramName] = argument -// } -// } -// } - -// return { -// method: { -// pallet: genericCall.section, -// method: genericCall.method -// }, -// args: newArgs, -// hash: genericCall.hash.toHex() -// } -// } diff --git a/packages/ui/src/utils/extinsicErrorChecks.ts b/packages/ui/src/utils/extinsicErrorChecks.ts deleted file mode 100644 index 4a9e3ec7..00000000 --- a/packages/ui/src/utils/extinsicErrorChecks.ts +++ /dev/null @@ -1,103 +0,0 @@ -// // Copyright 2017-2023 @polkadot/react-components authors & contributors -// // SPDX-License-Identifier: Apache-2.0 - -// // from https://github.com/polkadot-js/apps/blob/97aeb41a593165f9a9b218c1ceecb52172473de3/packages/react-components/src/Status/checks.ts - -// type EventCheck = (event: Event) => string | null - -// const INCOMPLETE = 'incomplete execution' - -// function extractError(result: DispatchResult): string | null { -// if (!result) { -// return INCOMPLETE -// } else if (result.isErr) { -// return `error: ${getDispatchError(result.asErr)}` -// } - -// return null -// } - -// function batchInterrupted({ data: [index, error] }: Event): string | null { -// return `error call #${index.toString()}: ${getDispatchError(error as DispatchError)}` -// } - -// function dispatchResult({ data: [result] }: Event): string | null { -// return extractError(result as DispatchResult) -// } - -// function dispatchResultCouncil({ data: [, result] }: Event): string | null { -// return extractError(result as DispatchResult) -// } - -// // [approving, timepoint, multisig, callHash, result] -// function dispatchResultMulti({ data: [, , , , result] }: Event): string | null { -// return extractError(result as DispatchResult) -// } - -// function xcmAttempted({ data: [outcome] }: Event): string | null { -// if (!outcome) { -// return INCOMPLETE -// } else if ((outcome as any).isIncomplete) { -// const [, error] = (outcome as any).asIncomplete - -// return `error: ${error.type}` -// } - -// return null -// } - -// const collective: Record = { -// Executed: dispatchResultCouncil -// } - -// const xcmPallet: Record = { -// Attempted: xcmAttempted -// } - -// const CHECKS: Record> = { -// allianceMotion: collective, -// council: collective, -// membership: collective, -// multisig: { -// MultisigExecuted: dispatchResultMulti -// }, -// polkadotXcm: xcmPallet, -// proxy: { -// ProxyExecuted: dispatchResult -// }, -// sudo: { -// Sudid: dispatchResult, -// SudoAsDone: dispatchResult -// }, -// technicalCommittee: collective, -// utility: { -// BatchInterrupted: batchInterrupted, -// DispatchedAs: dispatchResult -// }, -// xcmPallet -// } - -// export function getDispatchError(dispatchError: DispatchError): string { -// let message: string = dispatchError.type - -// if (dispatchError.isModule) { -// try { -// const mod = dispatchError.asModule -// const error = dispatchError.registry.findMetaError(mod) - -// message = `${error.section} ${error.name}` -// } catch { -// // swallow -// } -// } else if (dispatchError.isToken) { -// message = `${dispatchError.type} ${dispatchError.asToken.type}` -// } - -// return message -// } - -// export function getIncompleteMessage({ event }: EventRecord): string | null { -// const { method, section } = event - -// return !!CHECKS[section] && !!CHECKS[section][method] && CHECKS[section][method](event) -// } diff --git a/yarn.lock b/yarn.lock index 53961c72..d622047e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3609,7 +3609,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/api@npm:13.1.1, @polkadot/api@npm:^13.1.1": +"@polkadot/api@npm:13.1.1": version: 13.1.1 resolution: "@polkadot/api@npm:13.1.1" dependencies: @@ -4010,7 +4010,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/types@npm:13.1.1, @polkadot/types@npm:^13.1.1": +"@polkadot/types@npm:13.1.1": version: 13.1.1 resolution: "@polkadot/types@npm:13.1.1" dependencies: @@ -10965,10 +10965,8 @@ __metadata: "@polkadot-api/tx-utils": ^0.0.4 "@polkadot-labs/hdkd": ^0.0.8 "@polkadot-labs/hdkd-helpers": ^0.0.8 - "@polkadot/api": ^13.1.1 "@polkadot/react-identicon": ^3.10.1 "@polkadot/typegen": ^13.1.1 - "@polkadot/types": ^13.1.1 "@polkadot/util-crypto": ^13.1.1 "@reactive-dot/core": ^0.19.0 "@reactive-dot/react": ^0.19.0 @@ -10999,7 +10997,6 @@ __metadata: react-icons: ^5.1.0 react-router-dom: ^6.22.3 reactflow: ^11.11.1 - rxjs: ^7.8.1 ts-node: ^10.9.2 typescript: 5.4.5 vite: ^5.4.7