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: custom network and contract table bugs #284

Merged
merged 17 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
20 changes: 10 additions & 10 deletions src/hooks/useNetworkApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useApi } from 'useink'
import { useNetworkAccountsContext } from '@/context/NetworkAccountsContext'
import { useDelay } from './useDelay'
import { ChainId } from '@/services/useink/chains'
import { useEffect, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { getChain } from '@/constants/chains'
import { ChainExtended } from '@/types'

Expand Down Expand Up @@ -32,17 +32,17 @@ export function useNetworkApi(): UseNetworkApi {

const fetchApi = useApi(networkConnected)

const fetchCustomChain = useCallback(async () => {
const chain = getChain(networkConnected)
const apiInstance = await initializeApi(chain)
setApi(apiInstance)
}, [networkConnected])

useEffect(() => {
if (networkConnected) {
if (!fetchApi) {
;(async () => {
const chain = getChain(networkConnected)
const apiInstance = await initializeApi(chain)
setApi(apiInstance)
})()
}
if (!fetchApi) {
fetchCustomChain()
}
}, [networkConnected])
}, [fetchApi, fetchCustomChain])

const firstLoadCompleted = useDelay(5000)
return {
Expand Down
1 change: 0 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { UseInkProvider } from 'useink'
import { CHAINS } from '@/constants/chains'
import { LocalDbProvider } from '@/context/LocalDbContext'
import { Inter } from 'next/font/google'
import { apiVersionService } from '@/services/backendApi/ApiVersionService'

type CustomAppProps = AppProps & {
emotionCache: EmotionCache
Expand Down
8 changes: 8 additions & 0 deletions src/utils/inputValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ export function maxLength(value: unknown, max = 20): string | void {
return `The field only accepts 20 letters`
}
}

export function validateWsUrl(value: string): string | void {
const validation = value.startsWith('wss://')

if (!validation) {
return `This is not a valid websocket url`
}
}
18 changes: 6 additions & 12 deletions src/view/components/ContractsTable/ContractsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
Box
} from '@mui/material'

import {
CopyToClipboardButton,
StyledTextField,
TokenIconSvg
} from '@/components'
import { CopyToClipboardButton, TokenIconSvg } from '@/components'
import {
isoDate,
isoToReadableDate,
Expand Down Expand Up @@ -47,6 +43,7 @@ import { ROUTES } from '@/constants'
import { useRef } from 'react'
import { useFormInput } from '@/hooks'
import { maxLength, notEmpty } from '@/utils/inputValidation'
import { MuiTextField } from '../MuiTextField'

export interface TableConfig {
onlyTable: boolean
Expand Down Expand Up @@ -133,19 +130,16 @@ function ContractTableRow({
<TokenWrapper>
{editable ? (
<>
<StyledTextField
label="Contract Name"
placeholder={contract.name}
value={formData.contractName.value}
onChange={formData.contractName.onChange}
<MuiTextField
error={Boolean(formData.contractName.error)}
helperText={
formData.contractName.error ? formData.contractName.error : ''
}
loading={formData.contractName.loading}
value={formData.contractName.value}
onChange={formData.contractName.onChange}
ref={textRef}
autoFocus
/>
></MuiTextField>

<DefaultToolTipButton
id={`save-contract-name${takeLastChars(contract.uuid)}`}
Expand Down
2 changes: 1 addition & 1 deletion src/view/components/ContractsTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React from 'react'
import {
ContractsTable,
TableConfig
Expand Down
11 changes: 7 additions & 4 deletions src/view/components/WalletConnectButton/NetworkSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import AddIcon from '@mui/icons-material/Add'
import EditIcon from '@mui/icons-material/Edit'
import ModalView from '../ModalView'
import { useFormInput } from '@/hooks'
import { notEmpty } from '@/utils/inputValidation'
import { notEmpty, validateWsUrl } from '@/utils/inputValidation'
import { StyledTextField } from '../Input'
import { RpcUrl } from '@/services/useink/chains/data/types'
import { ChainExtended } from '@/types'
Expand Down Expand Up @@ -122,8 +122,11 @@ export function NetworkSelect({
}

const formData = {
name: useFormInput<string>('test', [notEmpty]),
rpc: useFormInput<RpcUrl>('wss://rpc.shibuya.astar.network', [notEmpty])
name: useFormInput<string>('Test', [notEmpty]),
rpc: useFormInput<RpcUrl>('wss://rpc.shibuya.astar.network', [
notEmpty,
validateWsUrl
])
}

const editNetwork =
Expand Down Expand Up @@ -242,7 +245,7 @@ export function NetworkSelect({
<StyledTextField
sx={{ marginBottom: '2rem' }}
label="Network Name"
placeholder="502d1..."
placeholder="Custom name"
value={formData.name.value}
onChange={formData.name.onChange}
error={Boolean(formData.name.error)}
Expand Down
Loading