Skip to content

Commit

Permalink
fix(app): wrap encode address error
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleydon committed Apr 20, 2024
1 parent 27800c5 commit f61dab2
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 483 deletions.
5 changes: 2 additions & 3 deletions apps/app/components/BasePool/ClaimReward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
DialogTitle,
TextField,
} from '@mui/material'
import {validateAddress} from '@phala/lib'
import {transformSs58Format, validateAddress} from '@phala/lib'
import {polkadotAccountAtom} from '@phala/store'
import type {SubmittableExtrinsic} from '@polkadot/api/types'
import {decodeAddress, encodeAddress} from '@polkadot/keyring'
import type {ISubmittableResult} from '@polkadot/types/types'
import Decimal from 'decimal.js'
import {useAtom} from 'jotai'
Expand Down Expand Up @@ -61,7 +60,7 @@ const ClaimReward: FC<{
try {
if (
account?.address !== undefined &&
encodeAddress(decodeAddress(address), 30) === account.address
transformSs58Format(address, 30) === account.address
) {
calls.push(
api.tx.phalaWrappedBalances.unwrap(totalReward.times(1e12).toHex()),
Expand Down
1 change: 1 addition & 0 deletions apps/app/components/BasePool/ExtraProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ExtraProperties: FC<{basePool: BasePoolCommonFragment; sx?: SxProps}> = ({
['Commission', toPercentage(basePool.commission), 'commission'],
stakePool != null && [
'Workers',
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
<>
{`${stakePool.idleWorkerCount} Idle`}
<Box component="span" color="text.secondary">
Expand Down
1 change: 1 addition & 0 deletions apps/app/components/BasePool/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ const BasePoolList: FC<{
spacing={2}
>
{page.basePoolsConnection.edges.map((edge) =>
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
variant === 'farm' ? (
<FarmCard
key={edge.node.id}
Expand Down
4 changes: 2 additions & 2 deletions apps/app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const nextConfig = {
},
experimental: {
swcPlugins: [
['@swc-jotai/debug-label', {}],
['@swc-jotai/react-refresh', {}],
// ['@swc-jotai/debug-label', {}],
// ['@swc-jotai/react-refresh', {}],
],
},
}
Expand Down
36 changes: 18 additions & 18 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,46 @@
"@fortawesome/free-regular-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
"@mui/material": "^5.15.14",
"@mui/icons-material": "^5.15.15",
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "^5.15.15",
"@mui/material-nextjs": "^5.15.11",
"@mui/x-data-grid": "^7.1.0",
"@mui/x-data-grid": "^7.3.0",
"@phala/lib": "workspace:*",
"@phala/store": "workspace:*",
"@polkadot/api": "^10.12.6",
"@polkadot/extension-inject": "^0.46.9",
"@polkadot/api": "^10.13.1",
"@polkadot/extension-inject": "^0.47.1",
"@polkadot/keyring": "^12.6.2",
"@polkadot/react-identicon": "^3.6.5",
"@polkadot/types": "^10.12.6",
"@polkadot/react-identicon": "^3.6.6",
"@polkadot/types": "^10.13.1",
"@polkadot/util": "^12.6.2",
"@sentry/nextjs": "^7.109.0",
"@sentry/nextjs": "^7.111.0",
"@talismn/connect-wallets": "^1.2.5",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-devtools": "^5.28.14",
"@tanstack/react-query": "^5.29.2",
"@tanstack/react-query-devtools": "^5.29.2",
"ajv": "^8.12.0",
"date-fns": "^3.6.0",
"decimal.js": "^10.4.3",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"graphql-tag": "^2.12.6",
"jotai": "^2.7.2",
"jotai-devtools": "^0.8.0",
"jotai": "^2.8.0",
"jotai-devtools": "^0.9.0",
"lodash-es": "^4.17.21",
"mutative": "^1.0.3",
"next": "^14.1.4",
"mutative": "^1.0.5",
"next": "^14.2.2",
"notistack": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-intersection-observer": "^9.8.1",
"react-intersection-observer": "^9.8.2",
"react-markdown": "^9.0.1",
"react-snap-carousel": "^0.4.0",
"recharts": "^2.12.3",
"recharts": "^2.12.5",
"sharp": "^0.33.3",
"swr": "^2.2.5"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.1.4",
"@next/bundle-analyzer": "^14.2.2",
"@svgr/webpack": "^8.1.0",
"@swc-jotai/debug-label": "^0.1.0",
"@swc-jotai/react-refresh": "^0.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {isWalletConnectAtom} from '@/store/common'
import {evmAccountAtom} from '@/store/ethers'
import HighlightOff from '@mui/icons-material/HighlightOff'
import {Box, type BoxProps, IconButton, Link, TextField} from '@mui/material'
import {trimAddress} from '@phala/lib'
import {transformSs58Format, trimAddress} from '@phala/lib'
import {polkadotAccountAtom} from '@phala/store'
import {encodeAddress} from '@polkadot/util-crypto'
import {useAtom} from 'jotai'
import {RESET} from 'jotai/utils'
import {
Expand Down Expand Up @@ -80,7 +79,7 @@ const DestinationAccountInput: FC<BoxProps> = (props) => {
const {name, address} = polkadotAccount

return `${name ?? ''} (${trimAddress(
encodeAddress(address, toChain.ss58Format),
transformSs58Format(address, toChain.ss58Format),
)})`
}
return destinationAccount
Expand Down
5 changes: 2 additions & 3 deletions apps/subbridge/components/BridgeConfirmationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import {
} from '@mui/material'
import type {TransitionProps} from '@mui/material/transitions'
import type {BoxProps} from '@mui/system'
import {sleep} from '@phala/lib'
import {encodeAddress} from '@polkadot/util-crypto'
import {sleep, transformSs58Format} from '@phala/lib'
import Decimal from 'decimal.js'
import {useAtom, useAtomValue} from 'jotai'
import {RESET} from 'jotai/utils'
Expand Down Expand Up @@ -107,7 +106,7 @@ const Detail: FC<
const displayAccount = useMemo(() => {
if (chain.kind === 'substrate' && account.length > 0) {
const {ss58Format} = chain
return encodeAddress(account, ss58Format)
return transformSs58Format(account, ss58Format)
}

return account
Expand Down
4 changes: 2 additions & 2 deletions apps/subbridge/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const nextConfig = {
},
experimental: {
swcPlugins: [
['@swc-jotai/debug-label', {}],
['@swc-jotai/react-refresh', {}],
// ['@swc-jotai/debug-label', {}],
// ['@swc-jotai/react-refresh', {}],
],
},
}
Expand Down
16 changes: 8 additions & 8 deletions apps/subbridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
"@emotion/styled": "^11.11.5",
"@metamask/detect-provider": "^2.0.0",
"@metamask/providers": "^16.0.0",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
"@mui/material": "^5.15.14",
"@mui/icons-material": "^5.15.15",
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "^5.15.15",
"@mui/material-nextjs": "^5.15.11",
"@next/bundle-analyzer": "^14.1.4",
"@phala/lib": "workspace:*",
"@phala/store": "workspace:*",
"@phala/ui": "workspace:*",
"@polkadot/api": "^10.12.6",
"@polkadot/api": "^10.13.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@talismn/connect-components": "^1.1.8",
"@talismn/connect-ui": "^1.1.3",
"@talismn/connect-wallets": "^1.2.5",
"decimal.js": "^10.4.3",
"ethers": "^5.7.2",
"jotai": "^2.7.2",
"jotai-devtools": "^0.8.0",
"next": "^14.1.4",
"jotai": "^2.8.0",
"jotai-devtools": "^0.9.0",
"next": "^14.2.2",
"next-images": "^1.8.5",
"notistack": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"swr": "^2.2.5"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.2",
"@svgr/webpack": "^8.1.0",
"@swc-jotai/debug-label": "^0.1.0",
"@swc-jotai/react-refresh": "^0.1.0"
Expand Down
Binary file modified bun.lockb
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"preinstall": "lefthook install"
},
"devDependencies": {
"@biomejs/biome": "1.6.3",
"@biomejs/biome": "1.7.0",
"@total-typescript/ts-reset": "^0.5.1",
"@types/node": "^20.12.3",
"lefthook": "^1.6.8",
"tsx": "^4.7.1",
"@types/node": "^20.12.7",
"lefthook": "^1.6.10",
"tsx": "^4.7.2",
"turbo": "^1.13.2",
"typescript": "^5.4.3"
"typescript": "^5.4.5"
},
"dependencies": {
"date-fns": "^3.6.0"
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/src/transformSs58Format.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {decodeAddress, encodeAddress} from '@polkadot/keyring'

const transformSs58Format = (address: string, ss58Format: number): string => {
return encodeAddress(decodeAddress(address), ss58Format)
try {
return encodeAddress(decodeAddress(address), ss58Format)
} catch (err) {
return ''
}
}

export default transformSs58Format
6 changes: 5 additions & 1 deletion packages/lib/src/useConnectPolkadotWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {WalletAccount} from '@talismn/connect-wallets'
import {useAtom} from 'jotai'
import {useEffect} from 'react'
import transformSs58Format from './transformSs58Format'
import {validateAddress} from './validateAddress'

export const useConnectPolkadotWallet = (
dappName: string,
Expand Down Expand Up @@ -57,7 +58,10 @@ export const useConnectPolkadotWallet = (
const updateAccounts = async (): Promise<void> => {
if (wallet != null) {
// Some wallets don't implement subscribeAccounts correctly, so call getAccounts anyway
const accounts = await wallet.getAccounts()
const walletAccounts = await wallet.getAccounts()
const accounts = walletAccounts.filter((account) =>
validateAddress(account.address),
)
saveAccounts(accounts)
if (!unmounted) {
unsub = (await wallet.subscribeAccounts(saveAccounts)) as () => void
Expand Down
5 changes: 2 additions & 3 deletions packages/lib/src/validateAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {hexToU8a, isHex} from '@polkadot/util'

// https://polkadot.js.org/docs/util-crypto/examples/validate-address
export const validateAddress = (address: string): boolean => {
// forbid public key
if (address.startsWith('0x')) return false
try {
// forbid public key
if (address.startsWith('0x')) return false

encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address))

return true
Expand Down
2 changes: 2 additions & 0 deletions packages/polkadot-types/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ declare module '@polkadot/api-base/types/errors' {
GenesisBlockHashRejected: AugmentedError<ApiType>;
InvalidBenchReport: AugmentedError<ApiType>;
InvalidConsensusVersion: AugmentedError<ApiType>;
InvalidDCAPQuote: AugmentedError<ApiType>;
InvalidEndpointSigningTime: AugmentedError<ApiType>;
InvalidGatekeeper: AugmentedError<ApiType>;
InvalidIASSigningCert: AugmentedError<ApiType>;
Expand Down Expand Up @@ -1047,6 +1048,7 @@ declare module '@polkadot/api-base/types/errors' {
UnknownCluster: AugmentedError<ApiType>;
UnknownContract: AugmentedError<ApiType>;
UnknownQuoteBodyFormat: AugmentedError<ApiType>;
UnsupportedAttestationType: AugmentedError<ApiType>;
WorkerNotFound: AugmentedError<ApiType>;
/**
* Generic error
Expand Down
4 changes: 2 additions & 2 deletions packages/polkadot-types/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ declare module '@polkadot/api-base/types/submittable' {
/**
* See [`Pallet::set_reimbursements`].
**/
setReimbursements: AugmentedSubmittable<(input: Vec<ITuple<[AccountId32, u64, u128]>> | ([AccountId32 | string | Uint8Array, u64 | AnyNumber | Uint8Array, u128 | AnyNumber | Uint8Array])[]) => SubmittableExtrinsic<ApiType>, [Vec<ITuple<[AccountId32, u64, u128]>>]>;
setReimbursements: AugmentedSubmittable<(input: Vec<ITuple<[AccountId32, u64, u128]>> | ([AccountId32 | string | Uint8Array, u64 | AnyNumber | Uint8Array, u128 | AnyNumber | Uint8Array])[], add: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>, [Vec<ITuple<[AccountId32, u64, u128]>>, bool]>;
/**
* Generic tx
**/
Expand Down Expand Up @@ -846,7 +846,7 @@ declare module '@polkadot/api-base/types/submittable' {
/**
* See [`Pallet::register_worker_v2`].
**/
registerWorkerV2: AugmentedSubmittable<(pruntimeInfo: PhalaTypesWorkerRegistrationInfoV2 | { version?: any; machineId?: any; pubkey?: any; ecdhPubkey?: any; genesisBlockHash?: any; features?: any; operator?: any; paraId?: any; maxConsensusVersion?: any } | string | Uint8Array, attestation: Option<PhalaTypesAttestationReport> | null | Uint8Array | PhalaTypesAttestationReport | { SgxIas: any } | string) => SubmittableExtrinsic<ApiType>, [PhalaTypesWorkerRegistrationInfoV2, Option<PhalaTypesAttestationReport>]>;
registerWorkerV2: AugmentedSubmittable<(pruntimeInfo: PhalaTypesWorkerRegistrationInfoV2 | { version?: any; machineId?: any; pubkey?: any; ecdhPubkey?: any; genesisBlockHash?: any; features?: any; operator?: any; paraId?: any; maxConsensusVersion?: any } | string | Uint8Array, attestation: Option<PhalaTypesAttestationReport> | null | Uint8Array | PhalaTypesAttestationReport | { SgxIas: any } | { SgxDcap: any } | string) => SubmittableExtrinsic<ApiType>, [PhalaTypesWorkerRegistrationInfoV2, Option<PhalaTypesAttestationReport>]>;
/**
* See [`Pallet::remove_pruntime`].
**/
Expand Down
Loading

0 comments on commit f61dab2

Please sign in to comment.