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

Update apps metadata, fix await in S2M #270

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
98 changes: 98 additions & 0 deletions src/components/ChainAppBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @license
* SKALE Metaport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* @file ChainAppBtn.ts
* @copyright SKALE Labs 2024-Present
*/

import { Button } from '@mui/material'
import KeyboardArrowRightRoundedIcon from '@mui/icons-material/KeyboardArrowRightRounded'

import { cls, cmn, styles } from '../core/css'
import { SkaleNetwork } from '../core/interfaces'
import { getChainAlias } from '../core/metadata'

import ChainIcon from './ChainIcon'

export default function ChainAppBtn(props: {
skaleNetwork: SkaleNetwork
appName: string
chainName: string
handle?: (schainName: string, app?: string) => void
size?: 'sm' | 'md'
prim?: boolean
}) {
const size = props.size ?? 'sm'
const iconSize = props.size === 'sm' ? 'xs' : 'sm'
const prim = props.prim ?? size === 'md'

return (
<Button
key={props.appName}
onClick={() => props.handle(props.chainName, props.appName)}
size="small"
color="inherit"
className={cls([cmn.mleft10, size === 'sm'], [cmn.mleft20, size === 'md'], cmn.mbott5)}
>
<div
className={cls(
cmn.flex,
cmn.flexcv,
cmn.mri5,
[cmn.mleft5, size === 'sm'],
[cmn.mleft10, size === 'md'],
[cmn.mbott5, size === 'sm'],
[cmn.mtop5, size === 'sm'],
[cmn.mbott10, size === 'md'],
[cmn.mtop10, size === 'md']
)}
>
<ChainIcon
className={cls(cmn.mleft20d)}
skaleNetwork={props.skaleNetwork}
chainName={props.chainName}
app={props.appName}
size={iconSize}
/>
<p
className={cls(
cmn.p,
[cmn.p3, size === 'md'],
[cmn.p4, size === 'sm'],
[cmn.pSec, !prim],
[cmn.pPrim, prim],
cmn.p600,
cmn.mleft10
)}
>
{getChainAlias(props.skaleNetwork, props.chainName, props.appName)}
</p>
<div className={cls(cmn.flex, cmn.flexg)}></div>
<KeyboardArrowRightRoundedIcon
className={cls(
cmn.pSec,
[styles.chainIconxs, size === 'sm'],
[styles.chainIcons, size === 'md'],
[cmn.mleft5, size === 'md']
)}
/>
</div>
</Button>
)
}
145 changes: 91 additions & 54 deletions src/components/ChainApps.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
/**
* @license
* SKALE Metaport
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* @file ChainApps.ts
* @copyright SKALE Labs 2024-Present
*/

import { ReactElement, useState } from 'react'
import { Button } from '@mui/material'
import KeyboardArrowRightRoundedIcon from '@mui/icons-material/KeyboardArrowRightRounded'
import AddCircleRoundedIcon from '@mui/icons-material/AddCircleRounded'
import RemoveCircleRoundedIcon from '@mui/icons-material/RemoveCircleRounded'

import { cls, cmn, styles } from '../core/css'
import { SkaleNetwork } from '../core/interfaces'
import { getChainAppsMeta, getChainAlias } from '../core/metadata'
import { getChainAppsMeta } from '../core/metadata'

import ChainIcon from './ChainIcon'
import ChainAppBtn from './ChainAppBtn'

import { sortObjectByKeys } from '../core/helper'

export default function ChainApps(props: {
skaleNetwork: SkaleNetwork
Expand All @@ -14,70 +41,80 @@ export default function ChainApps(props: {
size?: 'sm' | 'md'
prim?: boolean
}) {
const [show, setShow] = useState<boolean>(false)

const apps = getChainAppsMeta(props.chainName, props.skaleNetwork)
if (!apps || !Object.keys(apps) || Object.keys(apps).length === 0) return <div></div>

const size = props.size ?? 'sm'
const iconSize = props.size === 'sm' ? 'xs' : 'sm'

const prim = props.prim ?? size === 'md'
const appButtons: ReactElement[] = []

for (const appName in sortObjectByKeys(apps)) {
appButtons.push(
<ChainAppBtn
skaleNetwork={props.skaleNetwork}
chainName={props.chainName}
appName={appName}
handle={props.handle}
size={size}
prim={props.prim}
/>
)
}

return (
<div className={cls(styles.sk__chainApps, cmn.mri10, cmn.flex, cmn.flexcv)}>
<div className={cls(cmn.mtop10, cmn.mbott10)}>
{Object.keys(apps).map((key, _) => (
<Button
key={key}
onClick={() => props.handle(props.chainName, key)}
size="small"
color="inherit"
className={cls([cmn.mleft10, size === 'sm'], [cmn.mleft20, size === 'md'], cmn.mbott5)}
{show ? appButtons : appButtons.length === 4 ? appButtons : appButtons.slice(0, 3)}
{appButtons.length > 3 && <Button
onClick={() => {
setShow(!show)
}}
size="small"
className={cls([cmn.mleft10, size === 'sm'], [cmn.mleft20, size === 'md'], cmn.mbott5)}
>
<div
className={cls(
cmn.flex,
cmn.flexcv,
cmn.mri10,
[cmn.mleft5, size === 'sm'],
[cmn.mleft10, size === 'md'],
[cmn.mbott5, size === 'sm'],
[cmn.mtop5, size === 'sm'],
[cmn.mbott10, size === 'md'],
[cmn.mtop10, size === 'md']
)}
>
<div
{show ? (
<RemoveCircleRoundedIcon className={cls(cmn.pPrim,
[styles.chainIconxs, size === 'sm'],
[styles.chainIconsm, size === 'md']
)} />
) : (
<AddCircleRoundedIcon className={cls(cmn.pPrim,
[styles.chainIconxs, size === 'sm'],
[styles.chainIconsm, size === 'md']
)} />
)}

<p
className={cls(
cmn.flex,
cmn.flexcv,
cmn.mri5,
[cmn.mleft5, size === 'sm'],
[cmn.mleft10, size === 'md'],
[cmn.mbott5, size === 'sm'],
[cmn.mtop5, size === 'sm'],
[cmn.mbott10, size === 'md'],
[cmn.mtop10, size === 'md']
cmn.p,
[cmn.p3, size === 'md'],
[cmn.p4, size === 'sm'],
cmn.pPrim,
cmn.p600,
cmn.mleft10
)}
>
<ChainIcon
className={cls(cmn.mleft20d)}
skaleNetwork={props.skaleNetwork}
chainName={props.chainName}
app={key}
size={iconSize}
/>
<p
className={cls(
cmn.p,
[cmn.p3, size === 'md'],
[cmn.p4, size === 'sm'],
[cmn.pSec, !prim],
[cmn.pPrim, prim],
cmn.p600,
cmn.mleft10
)}
>
{getChainAlias(props.skaleNetwork, props.chainName, key)}
</p>
<div className={cls(cmn.flex, cmn.flexg)}></div>
<KeyboardArrowRightRoundedIcon
className={cls(
[cmn.pSec, !prim],
[cmn.pPrim, prim],
[styles.chainIconxs, size === 'sm'],
[styles.chainIcons, size === 'md']
)}
/>
</div>
</Button>
))}
Show {show ? 'less' : 'more'} apps
</p>
</div>
</Button>}


</div>
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions src/core/actions/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class TransferERC20M2S extends Action {
log('TransferERC20M2S:execute - tx completed %O', tx)
await this.sChain2.waitERC20BalanceChange(this.destToken, this.address, balanceOnDestination)
this.updateState('received')
log('TransferERC20M2S:execute - tokens received to destination chain')
log('TransferERC20M2S:execute - tokens received on destination chain')
}

async preAction() {
Expand Down Expand Up @@ -339,9 +339,9 @@ export class TransferERC20S2M extends Action {
const block = await sChain.provider.getBlock(tx.blockNumber)
this.updateState('transferDone', tx.hash, block.timestamp)
log('TransferERC20S2M:execute - tx completed %O', tx)
this.mainnet.waitERC20BalanceChange(this.destToken, this.address, balanceOnDestination)
await this.mainnet.waitERC20BalanceChange(this.destToken, this.address, balanceOnDestination)
this.updateState('received')
log('TransferERC20S2M:execute - tokens received to destination chain')
log('TransferERC20S2M:execute - tokens received on destination chain')
}

async preAction() {
Expand Down
11 changes: 11 additions & 0 deletions src/core/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ export function getRandom(list: Array<any>) {
export async function sleep(ms: number): Promise<any> {
return await new Promise((resolve) => setTimeout(resolve, ms))
}

export function sortObjectByKeys(obj: { [key: string]: any }): { [key: string]: any } {
const sortedKeys = Object.keys(obj).sort()
const sortedObject: { [key: string]: any } = {}

for (const key of sortedKeys) {
sortedObject[key] = obj[key]
}

return sortedObject
}
6 changes: 5 additions & 1 deletion src/styles/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ button {

.inputAmount {

img {
border-radius: 50%;
}

:global .MuiInput-root::after {
border-bottom: none !important;
}
Expand Down Expand Up @@ -396,7 +400,7 @@ button {
}
}

.smallTable{
.smallTable {
code {
font-size: 0.7rem;
display: block;
Expand Down
Loading