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

[Epic] Custom contracts #199

Merged
merged 30 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f7e364
Adding contracts route
henrypalacios Sep 28, 2023
f013ae6
Add Custom Contracts and Contracts section (#195)
alongoni Sep 28, 2023
5201e21
Merge branch 'develop' into epic-custom-contracts
henrypalacios Oct 5, 2023
27607ff
Merge branch 'develop' into epic-custom-contracts
henrypalacios Oct 5, 2023
9f48dfa
Add Contract Table / Share Modal (#217)
bogos Oct 6, 2023
c68e35f
Merge branch 'develop' into epic-custom-contracts
henrypalacios Oct 9, 2023
f270fba
Merge branch 'develop' into epic-custom-contracts
henrypalacios Oct 10, 2023
7568542
Add last contracts (#229)
alongoni Oct 11, 2023
5683f4b
Merge branch 'develop' into epic-custom-contracts
alongoni Oct 13, 2023
0d305e4
fix missing type error
alongoni Oct 13, 2023
7a71c11
Add import form section (#201)
alongoni Oct 18, 2023
f912739
Feature/ Contrat table edit name and delete contract (#232)
bogos Oct 19, 2023
1751e3b
Fix infinite contract table loop (#244)
bogos Oct 23, 2023
ec9dd54
Contracts UI + Layout fixes (#238)
alongoni Oct 25, 2023
8979c19
Contract details view layout (#231)
alongoni Oct 25, 2023
06c54b2
add disabled styles
alongoni Oct 25, 2023
1f7155b
Merge branch 'epic-custom-contracts' into form-elements-styles
alongoni Oct 25, 2023
d7fdbb6
Revert "Contract details view layout (#231)"
henrypalacios Oct 25, 2023
df28515
Fix minnor bugs in contracts page table (#246)
bogos Oct 26, 2023
c69e76a
import custom deployment (#245)
henrypalacios Oct 26, 2023
36af99e
fix minnor custom contracts bugs
bogos Oct 27, 2023
6af0ef7
Merge branch 'epic-custom-contracts' of github.com:protofire/polkadot…
bogos Oct 27, 2023
461f4da
fix contract table rerender bug
bogos Oct 27, 2023
8ebefe3
Fix minnor bugs (#255)
bogos Oct 31, 2023
9b139ca
Form styles and layout fixes (#247)
alongoni Oct 31, 2023
fd430e5
Fix yarn .lock
henrypalacios Oct 31, 2023
9a2e2fa
load custom contract (#248)
henrypalacios Nov 1, 2023
621c25a
Tables UI Improvements + New Documentation (#256)
alongoni Nov 3, 2023
fed68b1
connection validations (#257)
henrypalacios Nov 3, 2023
b125da2
interaction methods (#265)
henrypalacios Nov 9, 2023
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_DOMAIN=""
NEXT_PUBLIC_DOMAIN="http://web:3000/"
NEXT_PUBLIC_BACKEND_API="http://compiler-be:8000/"

NEXT_PUBLIC_PROVIDER_DEFAULT_SOCKET="wss://rococo-contracts-rpc.polkadot.io"
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ const nextConfig = {
publicRuntimeConfig: {
version,
},
env: {
NEXT_PUBLIC_DOMAIN: process.env.VERCEL_URL,
},
async rewrites() {
return [{ source: '/api/:path*', destination: backendApi }]
}
},
}

module.exports = nextConfig
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"react-code-blocks": "^0.0.9-0",
"react-device-detect": "^2.2.2",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-element-to-jsx-string": "^15.0.0",
"react-syntax-highlighter": "^15.5.0",
"semver": "^7.3.8",
Expand Down
Binary file added public/assets/custom-contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/assets/docs1.png
Binary file not shown.
Binary file removed public/assets/docs10.png
Binary file not shown.
Binary file removed public/assets/docs11.png
Binary file not shown.
Binary file removed public/assets/docs12.png
Binary file not shown.
Binary file removed public/assets/docs13.png
Binary file not shown.
Binary file removed public/assets/docs14.png
Binary file not shown.
Binary file removed public/assets/docs15.png
Binary file not shown.
Binary file removed public/assets/docs2.png
Binary file not shown.
Binary file removed public/assets/docs3.png
Binary file not shown.
Binary file removed public/assets/docs4.png
Binary file not shown.
Binary file removed public/assets/docs5.png
Binary file not shown.
Binary file removed public/assets/docs6.png
Binary file not shown.
Binary file removed public/assets/docs7.png
Binary file not shown.
Binary file removed public/assets/docs9.png
Binary file not shown.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/thirteen.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RococoContractsTestnet,
ShibuyaTestnet,
ShidenKusama
} from '@/infrastructure/useink/chains'
} from '@/services/useink/chains'
import { ArrayOneOrMore, ChainExtended } from '@/types'
import { CHAINS_IMG_PATH } from './images'

Expand Down
48 changes: 32 additions & 16 deletions src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chain } from '@/infrastructure/useink/chains'
import { Chain } from '@/services/useink/chains'

export const IS_PRODUCTION = process.env.NODE_ENV === ('production' as string)
export const IS_DEVELOPMENT = process.env.NODE_ENV === ('development' as string)
Expand Down Expand Up @@ -27,7 +27,11 @@ const backendRouterApi = {
method: 'POST'
},
listDeployment: {
pathName: 'deployments?user_address=',
pathName: 'deployments',
method: 'GET'
},
findDeployment: {
pathName: 'deployment',
method: 'GET'
},
createCompileContract: {
Expand All @@ -37,6 +41,14 @@ const backendRouterApi = {
searchCompileContract: {
pathName: 'contract?code_id=',
method: 'GET'
},
updateDeployment: {
pathName: 'deployments',
method: 'PATCH'
},
version: {
pathName: 'version',
method: 'GET'
}
}

Expand All @@ -51,19 +63,23 @@ export interface BackendApiConfig {
routes: RouteApi
}

/** URL of the API will be rewritten in next.config */
const apiBaseUrlPath = '/api'

export const BACKEND_API: BackendApiConfig = {
basePath: apiBaseUrlPath,
routes: Object.keys(backendRouterApi).reduce((acc, key) => {
const currentRoute = backendRouterApi[key as BackendRoutesApi]
return {
...acc,
[key]: {
method: currentRoute.method,
url: `${apiBaseUrlPath}/${currentRoute.pathName}`
export function getBackendApiConfig(basePath: string): BackendApiConfig {
return {
basePath,
routes: Object.keys(backendRouterApi).reduce((acc, key) => {
const currentRoute = backendRouterApi[key as BackendRoutesApi]
return {
...acc,
[key]: {
method: currentRoute.method,
url: `${basePath}/${currentRoute.pathName}`
}
}
}
}, {} as RouteApi)
}, {} as RouteApi)
}
}

/** URL of the API will be rewritten in next.config */
export const apiBaseUrlPath = `/api`

export const BACKEND_API = getBackendApiConfig(apiBaseUrlPath)
8 changes: 5 additions & 3 deletions src/constants/images.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenType } from '@/domain'
import { ContractType } from '@/domain/repositories/DeploymentRepository'

export const LOGO_POLKADOT = '/assets/polka_logo_horizontal.svg'
export const CW_POLKADOT = '/assets/CW_logo.svg'
Expand All @@ -7,9 +7,11 @@ export const GIF_COMPILING = '/assets/compiling.gif'
export const SVG_SUCCESSFULLY = '/assets/successfully.svg'
export const SVG_AWESOME = '/assets/auto_awesome.svg'
export const CHAINS_IMG_PATH = `/assets/chains/`
export const CUSTOM_CONTRACT = '/assets/custom-contract.png'

export const TOKEN_PATHS: Record<TokenType, string> = {
export const TOKEN_PATHS: Record<ContractType, string> = {
psp22: '/assets/token.png',
psp34: '/assets/nft.png',
psp37: '/assets/multitoken.png'
psp37: '/assets/multitoken.png',
custom: '/assets/multitoken.png' // TODO: Add missing img
}
20 changes: 11 additions & 9 deletions src/constants/menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
LocalLibrary,
SvgIconComponent,
HomeRounded
SettingsSuggestRounded,
DataArrayRounded
} from '@mui/icons-material'
import { ROUTES } from '@/constants/routes'

Expand All @@ -15,25 +16,26 @@ export type NavLink = {
}

const icons = {
HomeRounded,
LocalLibrary
SettingsSuggestRounded,
LocalLibrary,
DataArrayRounded
}

export const MENU_ITEMS: NavLink[] = [
{
id: 'home',
title: 'Home',
title: 'Builder',
type: 'item',
url: ROUTES.HOME,
icon: icons.HomeRounded,
icon: icons.SettingsSuggestRounded,
target: true
},
{
id: 'docs',
title: 'Docs',
id: 'contracts',
title: 'Contracts',
type: 'item',
url: ROUTES.DOCS,
icon: icons.LocalLibrary,
url: ROUTES.CONTRACTS,
icon: icons.DataArrayRounded,
target: true
}
]
7 changes: 6 additions & 1 deletion src/constants/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export const ROUTES = {
HOME: '/',
WIZARD: '/wizard',
DOCS: '/docs'
CONTRACTS: '/contracts',
CUSTOM: '/custom-contract',
CONTRACTDETAIL: '/contract-detail',
DOCUMENTATION: 'https://contractwizard-docs.vercel.app/',
TELEGRAM: 'https://t.me/+u5M4K7vKfbQxZjMx',
GITHUB: 'https://github.com/protofire/polkadot-contract-wizard"'
} as const
10 changes: 8 additions & 2 deletions src/constants/titleTokenType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenType } from '@/domain'
import { TOKEN_PATHS } from '@/constants/images'
import { ContractType } from '@/domain/repositories/DeploymentRepository'

export interface TitleMapProps {
title: string
Expand All @@ -8,7 +8,7 @@ export interface TitleMapProps {
imgProps: { width: number; height: number }
}

export const TITLE_MAP_TOKEN: Record<TokenType, TitleMapProps> = {
export const TITLE_MAP_TOKEN: Record<ContractType, TitleMapProps> = {
psp22: {
title: 'TOKEN | PSP22',
subtitle: 'Standard smart contract for a fungible token',
Expand All @@ -26,5 +26,11 @@ export const TITLE_MAP_TOKEN: Record<TokenType, TitleMapProps> = {
subtitle: 'Standard smart contract for a Multi Token',
imgPath: TOKEN_PATHS.psp37,
imgProps: { width: 45, height: 39 }
},
custom: {
title: 'CUSTOM',
subtitle: 'Standard smart contract for a custom Token',
imgPath: TOKEN_PATHS.custom,
imgProps: { width: 45, height: 39 }
}
}
2 changes: 1 addition & 1 deletion src/constants/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletLogoProps } from '@/infrastructure/useink/walletTypes'
import { WalletLogoProps } from '@/services/useink/walletTypes'

export type WalletImg = { [name: string]: WalletLogoProps }
export type WalletKeys = keyof typeof WALLET_IMG_DETAILS
Expand Down
15 changes: 15 additions & 0 deletions src/context/ApiVersionContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createContext, useContext } from 'react'

interface ApiVersionContextProps {
version: string | null
}

const ApiVersionContext = createContext<ApiVersionContextProps>({
version: null
})

export const useApiVersion = () => {
return useContext(ApiVersionContext)
}

export default ApiVersionContext
48 changes: 34 additions & 14 deletions src/context/LocalDbContext.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,66 @@
import { INetworkRepository } from '@/domain/repositories/INetworkRepository'
import { LocalStorageNetworkRepository } from '@/infrastructure/LocalStorageNetworkRepository'
import { LocalStorageNetworkRepository } from '@/services/LocalStorageNetworkRepository'
import {
ApiDeploymentRepository,
IApiDeploymentRepository
} from '@/infrastructure/backendApi/ApiDeploymentRepository'
import React, { createContext, PropsWithChildren, useContext } from 'react'
} from '@/services/backendApi/ApiDeploymentRepository'
import React, {
createContext,
PropsWithChildren,
useContext,
useEffect,
useState
} from 'react'
import { BACKEND_API } from '../constants'
import { MyDatabase } from '@/infrastructure/localDB'
import { UserContractsRepository } from '@/infrastructure/localDB/UserContractsRepository'
import { MyDatabase } from '@/services/localDB'
import { UserContractsRepository } from '@/services/localDB/UserContractsRepository'
import { IUserContractsRepository } from '@/domain/repositories/IUserContractsRepository'
import {
ApiCompileContractRepository,
IApiCompileContractRepository
} from '@/infrastructure/backendApi/ApiCompileContractRepository'
} from '@/services/backendApi/ApiCompileContractRepository'
import { apiVersionService } from '@/services/backendApi/ApiVersionService'

interface DbContext {
networkRepository: INetworkRepository
deploymentsRepository: IApiDeploymentRepository
apiDeploymentsRepository: IApiDeploymentRepository
userContractsRepository: IUserContractsRepository
compileContractRepository: IApiCompileContractRepository
apiCompileContractRepository: IApiCompileContractRepository
backendApiVersion: string
}

const apiDeploymentsRepository = new ApiDeploymentRepository(BACKEND_API)
const apiCompileContractRepository = new ApiCompileContractRepository(
BACKEND_API
)
const networkRepository = new LocalStorageNetworkRepository()
const deploymentsRepository = new ApiDeploymentRepository(BACKEND_API)
const compileContractRepository = new ApiCompileContractRepository(BACKEND_API)
const userContractsRepository = new UserContractsRepository(new MyDatabase())

const DbContext = createContext<DbContext>({
networkRepository,
deploymentsRepository,
apiDeploymentsRepository,
userContractsRepository,
compileContractRepository
apiCompileContractRepository,
backendApiVersion: ''
})

export const LocalDbProvider: React.FC<PropsWithChildren> = ({ children }) => {
const [backendApiVersion, setBackendApiVersion] = useState('')

useEffect(() => {
void apiVersionService
.getApiVersion()
.then(version => setBackendApiVersion(version))
}, [])

return (
<DbContext.Provider
value={{
networkRepository,
deploymentsRepository,
apiDeploymentsRepository,
userContractsRepository,
compileContractRepository
apiCompileContractRepository,
backendApiVersion
}}
>
{children}
Expand Down
6 changes: 3 additions & 3 deletions src/context/NetworkAccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import jsonrpc from '@polkadot/types/interfaces/jsonrpc'
import { WalletState, useAllWallets, useWallet } from 'useink'
import { WalletKeys } from '@/constants/wallets'

import { ChainProperties } from '@/infrastructure/NetworkAccountRepository'
import { Wallet, WalletAccount } from '@/infrastructure/useink/walletTypes'
import { ChainProperties } from '@/services/NetworkAccountRepository'
import { Wallet, WalletAccount } from '@/services/useink/walletTypes'
import { DEFAULT_CHAIN } from '../constants'
import { useLocalDbContext } from './LocalDbContext'
import { ChainId } from '@/infrastructure/useink/chains'
import { ChainId } from '@/services/useink/chains'
import { createNotImplementedWarning } from '@/utils/error'
import { WalletConnectionEvents } from '@/domain'

Expand Down
2 changes: 1 addition & 1 deletion src/domain/Contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenType } from '@/domain/TokenType'
import { ContractCompiledRaw } from '@/infrastructure'
import { ContractCompiledRaw } from '@/services'

export type ContractMetadata = ContractCompiledRaw

Expand Down
4 changes: 4 additions & 0 deletions src/domain/DomainEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const enum WalletConnectionEvents {
networkChanged = 'networkChanged'
}

export const enum UserContractEvents {
userContractUpdated = 'userContractUpdated'
}

export const enum AppNotificationEvents {
notificationUpdated = 'notificationUpdated'
}
Expand Down
5 changes: 5 additions & 0 deletions src/domain/FileState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface FileState {
data: Uint8Array
name: string
size: number
}
Loading
Loading