Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lint disable #6238

Merged
merged 6 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/backup-format/src/utils/hex2buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ export function hex2buffer(hexString: string, padded?: boolean) {
hexString = '0' + hexString
}
let res = new Uint8Array(hexString.length / 2)
// eslint-disable-next-line no-plusplus
for (let i = 0; i < hexString.length; i++) {
// eslint-disable-next-line no-plusplus
const c = hexString.slice(i, ++i + 1)
for (let i = 0; i < hexString.length; i += 2) {
const c = hexString.slice(i, i + 2)
res[(i - 1) / 2] = Number.parseInt(c, 16)
}
// BN padding
Expand All @@ -25,9 +23,8 @@ export function hex2buffer(hexString: string, padded?: boolean) {
function concat(...buf: (Uint8Array | number[])[]) {
const res = new Uint8Array(buf.map((item) => item.length).reduce((prev, cur) => prev + cur))
let offset = 0
buf.forEach((item, index) => {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < item.length; i++) {
buf.forEach((item) => {
for (let i = 0; i < item.length; i += 1) {
res[offset + i] = item[i]
}
offset += item.length
Expand Down
34 changes: 19 additions & 15 deletions packages/dashboard/src/pages/SignUp/steps/PersonaRecovery.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useCallback, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useCustomSnackbar } from '@masknet/theme'
import { DashboardRoutes } from '@masknet/shared-base'
import { DashboardRoutes, ECKeyIdentifier } from '@masknet/shared-base'
import { useDashboardI18N } from '../../../locales'
import { SignUpRoutePath } from '../routePath'
import { Services } from '../../../API'
import { PersonaNameUI } from './PersonaNameUI'
import { useCreatePersonaByPrivateKey, useCreatePersonaV2 } from '../../../hooks/useCreatePersonaV2'
import { PersonaContext } from '../../Personas/hooks/usePersonaContext'
import { useAsync } from 'react-use'
import { delay } from '@dimensiondev/kit'
import { useAsync } from 'react-use'

export const PersonaRecovery = () => {
const t = useDashboardI18N()
Expand All @@ -19,35 +19,39 @@ export const PersonaRecovery = () => {
const createPersonaByPrivateKey = useCreatePersonaByPrivateKey()
const { showSnackbar } = useCustomSnackbar()
const { changeCurrentPersona } = PersonaContext.useContainer()
const { state } = useLocation() as { state: { mnemonic: string[]; privateKey: string } }
const state = useLocation().state as { mnemonic?: string[]; privateKey?: string }

const [error, setError] = useState('')

useAsync(async () => {
if (
// eslint-disable-next-line @typescript-eslint/await-thenable
(!state?.mnemonic || (await !Services.Identity.validateMnemonic(state?.mnemonic.join(' ')))) &&
!state?.privateKey
) {
navigate(DashboardRoutes.SignUp, { replace: true })
}
}, [state?.mnemonic, state?.privateKey])
if (state.mnemonic && (await Services.Identity.validateMnemonic(state.mnemonic.join(' ')))) return
if (state.privateKey) return
navigate(DashboardRoutes.SignUp, { replace: true })
}, [state.mnemonic, state.privateKey])

const onNext = useCallback(
async (personaName: string) => {
setError('')
try {
const identifier = state?.mnemonic
? await createPersona(state?.mnemonic.join(' '), personaName)
: await createPersonaByPrivateKey(state?.privateKey, personaName)
let identifier: ECKeyIdentifier
if (state.mnemonic) {
identifier = await createPersona(state?.mnemonic.join(' '), personaName)
} else if (state.privateKey) {
identifier = await createPersonaByPrivateKey(state.privateKey, personaName)
} else {
setError('no available identifier')
return
}

await changeCurrentPersona(identifier)
showSnackbar(t.create_account_persona_successfully(), { variant: 'success' })

await delay(300)
navigate(`${DashboardRoutes.SignUp}/${SignUpRoutePath.ConnectSocialMedia}`)
} catch (error) {
setError((error as Error).message)
if (error instanceof Error) {
setError(error.message)
}
}
},
[state?.mnemonic, state?.privateKey],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ namespace Version38Or39 {
let binary = ''
const bytes = new Uint8Array(buffer)
const len = bytes.byteLength
// eslint-disable-next-line no-plusplus
for (let i = 0; i < len; i++) {
for (let i = 0; i < len; i += 1) {
binary += String.fromCharCode(bytes[i])
}
return window.btoa(binary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ async function onMessage(message: {
}

export async function createProvider() {
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (provider && provider.chainId !== null) return provider
if (provider?.chainId) return provider
provider = createMetaMaskProvider()

// wait for building the connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ export function ExchangeTokenPanel(props: ExchangeTokenPanelProps) {
isSell,
dataIndex,
exchangeToken?.address,
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
excludeTokensAddress.sort().join(),
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
selectedTokensAddress.sort().join(),
excludeTokensAddress.sort((a, b) => a.localeCompare('en-US', b)).join(),
selectedTokensAddress.sort((a, b) => a.localeCompare('en-US', b)).join(),
])
// #endregion

Expand Down
3 changes: 1 addition & 2 deletions packages/mask/src/plugins/ITO/SNSAdaptor/SwapDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ export function SwapDialog(props: SwapDialogProps) {
pickToken,
exchangeTokens
.map((x) => x.address)
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
.sort()
.sort((a, b) => a.localeCompare('en-US', b))
.join(),
])
// #endregion
Expand Down
20 changes: 10 additions & 10 deletions packages/mask/src/plugins/ITO/SNSAdaptor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ export function ITO_MetadataReader(meta: TypedMessage['meta']): Result<JSON_Payl
* The greatest common divisor
*/
export function gcd(a: BigNumber, b: BigNumber) {
let a_ = a.abs()
let b_ = b.abs()
if (b_.isGreaterThan(a_)) {
const temp = b_
b_ = a_
a_ = temp
a = a.abs()
b = b.abs()
if (b.isGreaterThan(a)) {
const temp = b
b = a
a = temp
}
// eslint-disable-next-line no-constant-condition
while (true) {
if (b_.isZero()) return a_
a_ = a_.mod(b_)
if (a_.isZero()) return b_
b_ = b_.mod(a_)
if (b.isZero()) return a
a = a.mod(b)
if (a.isZero()) return b
b = b.mod(a)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export function useCurrentDataProvider(availableDataProviders: DataProvider[]) {
setDataProvider(
availableDataProviders.includes(currentDataProvider) ? currentDataProvider : availableDataProviders[0],
)
}, [
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
availableDataProviders.sort().join(),
currentDataProvider,
])
}, [availableDataProviders.sort((a, b) => a - b).join(), currentDataProvider])
return dataProvider
}
3 changes: 1 addition & 2 deletions packages/shared/src/UI/components/ERC20TokenList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export const ERC20TokenList = memo<ERC20TokenListProps>((props) => {
assetsLoading,
assets
.map((x) => x.token.address)
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
.sort()
.sort((a, b) => a.localeCompare('en-US', b))
.join(),
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export function useERC20TokensDetailedFromTokenLists(
const { fetchERC20TokensFromTokenLists } = useWeb3Context()
const { value: tokensFromList = EMPTY_LIST, ...asyncResult } = useAsyncRetry(
async () => (!lists || lists.length === 0 ? [] : fetchERC20TokensFromTokenLists(lists, chainId)),
// eslint-disable-next-line @dimensiondev/array/no-implicit-sort
[chainId, lists?.sort().join()],
[chainId, lists?.sort((a, b) => a.localeCompare('en-US', b)).join()],
)
// #endregion
// #region fuse
Expand Down