Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Nov 5, 2024
1 parent 151ea50 commit 53d6634
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 542 deletions.
3 changes: 0 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
124 changes: 0 additions & 124 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,135 +32,11 @@ interface CreateTreeParams {
api: ApiType
}

// const handleCallDisplay = ({
// call,
// decimals,
// unit,
// api,
// key
// }: {
// call: Transaction<any, any, any, any>['decodedCall']
// decimals: number
// unit: string
// key: string
// api: ApiPromise
// }) => {
// const name = `${call.type}.${call.value.type}`
// return (
// <>
// <li key={key}>{name}</li>
// {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 (
// <li key={key}>
// {key}: {balance}
// </li>
// )
// }

// 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 <PreStyled>{JSONprint(decodedCall.value.value)}</PreStyled>
// return (
// <ul className="params">
// {Object.entries(decodedCall).map(([type, value], index) => {
// // const _typeName = typeName || getTypeName(index, name, api)

// // if (_typeName === 'Vec<RuntimeCall>') {
// // return handleBatchDisplay({ value, decimals, unit, api, key: `${key}-batch` })
// // }

// // if (_typeName === 'RuntimeCall') {
// // return handleCallDisplay({ call: value, decimals, unit, api, key: `${key}-call` })
// // }

// // // generically show nice value for Balance type
// // if (isTypeBalanceWithBalanceCall(_typeName, name)) {
// // return handleBalanceDisplay({ value, decimals, unit, key })
// // }

// // const destAddress = value?.Id || value
// // if (isTypeAccount(_typeName) && typeof destAddress === 'string') {
// // return (
// // <li key={key}>
// // {key}: {<MultisigCompactDisplay address={destAddress} />}
// // </li>
// // )
// // }

// return (
// <li key={`${type}-root-${index}`}>
// {`${value}.${value.type}`}
// {/*{createUlTree({
// name,
// args: value,
// decimals,
// unit,
// api
// })} */}
// <pre>{JSONprint(value)}</pre>
// </li>
// )
// })}
// </ul>
// )
}

const filterProxyProxy = (agg: Props['aggregatedData']): Props['aggregatedData'] => {
Expand Down
107 changes: 0 additions & 107 deletions packages/ui/src/contexts/AccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolkadotSigner | undefined>()
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) => {
Expand All @@ -87,82 +73,6 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {
setSelected(account)
}, [])

// const getaccountList = useCallback(
// async (isEthereum: boolean): Promise<void> => {
// 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)
Expand All @@ -173,35 +83,18 @@ 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 (
<AccountContext.Provider
value={{
selectedAccount,
ownAccountList: ownAccountList || [],
ownAddressList,
selectAccount,
// isAccountLoading,
// isExtensionError,
getAccountByAddress,
isConnectionDialogOpen,
setIsConnectionDialogOpen,
// selectedSigner,
allowConnectionToExtension,
isAllowedToConnectToExtension
// isLocalStorageSetupDone
}}
>
{children}
Expand Down
6 changes: 0 additions & 6 deletions packages/ui/src/contexts/PeopleChainApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ export interface ChainInfoHuman {
tokenSymbol: string
}

// interface RawChainInfoHuman {
// ss58Format: string
// tokenDecimals: string[]
// tokenSymbol: string[]
// }

const PplApiContext = createContext<IApiContext | undefined>(undefined)

const PplApiContextProvider = ({ children }: ApiContextProps) => {
Expand Down
10 changes: 0 additions & 10 deletions packages/ui/src/hooks/useDisplayLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,15 +29,6 @@ export const useDisplayLoader = () => {
)
}

// if (isAccountLoading) {
// return (
// <LoadingBox
// message="Loading your accounts..."
// testId="accounts-connection"
// />
// )
// }

if (isLoadingMultisigs) {
return (
<LoadingBox
Expand Down
Loading

0 comments on commit 53d6634

Please sign in to comment.