-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from node-real/feat/max-transfer/devin
feat(dcellar-web-ui): add max button to transfer module
- Loading branch information
Showing
26 changed files
with
548 additions
and
215 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
apps/dcellar-web-ui/public/images/toolbox/icon-toolbox-bg-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
apps/dcellar-web-ui/public/images/toolbox/icon-toolbox-bg-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
apps/dcellar-web-ui/public/images/toolbox/icon-toolbox-bg-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...lar-web-ui/public/js/iconfont_v0.5.min.js → ...lar-web-ui/public/js/iconfont_v0.7.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,66 @@ | ||
import { Connector } from 'wagmi'; | ||
import { signTypedDataV4 } from '@/utils/coder'; | ||
import { ethers } from 'ethers'; | ||
import { ErrorResponse, commonFault } from './error'; | ||
import { resolve } from './common'; | ||
import { BN } from '@/utils/math'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
export const signTypedDataCallback = (connector: Connector) => { | ||
return async (addr: string, message: string) => { | ||
const provider = await connector.getProvider(); | ||
return await signTypedDataV4(provider, addr, message); | ||
}; | ||
}; | ||
|
||
export const calTransferInFee = async ( | ||
params: { | ||
amount: string, | ||
crossChainContractAddress: string; | ||
tokenHubContract: string | ||
crossChainAbi: any; | ||
tokenHubAbi: any; | ||
address: string; | ||
}, | ||
signer: ethers.providers.JsonRpcSigner, | ||
provider: ethers.providers.JsonRpcProvider | ethers.providers.FallbackProvider, | ||
): Promise<ErrorResponse | [{ relayerFee: BigNumber, gasFee: BigNumber }, null]> => { | ||
const crossChainContract = new ethers.Contract( | ||
params.crossChainContractAddress, | ||
params.crossChainAbi, | ||
signer!, | ||
); | ||
const [fee, error1] = await crossChainContract.getRelayFees().then(resolve, commonFault); | ||
if (error1) return [null, error1]; | ||
const [relayFee, ackRelayFee] = fee; | ||
const relayerFee = relayFee.add(ackRelayFee); | ||
const fData = await provider.getFeeData(); | ||
const amountInFormat = ethers.utils.parseEther(String(params.amount)); | ||
const transferInAmount = amountInFormat; | ||
|
||
const totalAmount = amountInFormat.add(ackRelayFee).add(relayFee); | ||
|
||
const tokenHubContract = new ethers.Contract( | ||
params.tokenHubContract, | ||
params.tokenHubAbi, | ||
signer!, | ||
); | ||
|
||
const [estimateGas, error2] = await tokenHubContract.estimateGas.transferOut( | ||
params.address, | ||
transferInAmount, | ||
{ | ||
value: totalAmount, | ||
}, | ||
).then(resolve, commonFault); | ||
if (!estimateGas || error2) return [null, error2]; | ||
|
||
const gasFee = fData.gasPrice && estimateGas.mul(fData.gasPrice); | ||
|
||
const finalData = { | ||
gasFee: BN(gasFee ? ethers.utils.formatEther(gasFee) : '0'), | ||
relayerFee: BN(ethers.utils.formatEther(relayerFee)), | ||
}; | ||
|
||
return [finalData, null]; | ||
} |
44 changes: 44 additions & 0 deletions
44
apps/dcellar-web-ui/src/modules/toolbox/components/Common.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Center, CircleProps, Flex, FlexProps, LinkProps, Tooltip } from '@totejs/uikit'; | ||
|
||
export const Card = ({ children, ...props }: FlexProps) => { | ||
return ( | ||
<Flex | ||
p={'24px 20px'} | ||
maxW={375} | ||
gap={16} | ||
border={'1px solid readable.border'} | ||
borderRadius={4} | ||
flexDirection={'column'} | ||
_hover={{ | ||
border: '1px solid brand.brand6', | ||
cursor: 'pointer', | ||
}} | ||
{...props} | ||
> | ||
{children} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export const CircleLink = ({ children, href, title, ...props }: CircleProps & LinkProps) => { | ||
return ( | ||
<Tooltip content={title}> | ||
<Center | ||
w={24} | ||
h={24} | ||
href={href} | ||
as={'a'} | ||
target={'_blank'} | ||
border={'1px solid readable.border'} | ||
borderRadius={12} | ||
_hover={{ | ||
borderColor: 'brand.brand6', | ||
color: 'brand.brand6', | ||
}} | ||
{...props} | ||
> | ||
{children} | ||
</Center> | ||
</Tooltip> | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
apps/dcellar-web-ui/src/modules/toolbox/components/TellUsCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { Card } from './Common'; | ||
import { Box, Text, Tooltip } from '@totejs/uikit'; | ||
import { DCButton } from '@/components/common/DCButton'; | ||
import { assetPrefix } from '@/base/env'; | ||
|
||
export const TellUsCard = () => { | ||
const onNavigateExternal = (url: string) => { | ||
window.open(url, '_blank', 'noreferrer'); | ||
}; | ||
return ( | ||
<Card | ||
_hover={{}} | ||
position={'relative'} | ||
overflow={'hidden'} | ||
border={'none'} | ||
background={`url(${assetPrefix}/images/toolbox/icon-toolbox-bg-1.svg) no-repeat left 0 top 0, url(${assetPrefix}/images/toolbox/icon-toolbox-bg-2.svg) no-repeat right 0 top 10%, url(${assetPrefix}/images/toolbox/icon-toolbox-bg-3.svg) no-repeat left 10% bottom 0%`} | ||
bgColor={'#f9f9f9'} | ||
justifyContent={'center'} | ||
> | ||
<Text fontSize={18} fontWeight={600} color={'readable.normal'} textAlign={'center'}> | ||
Start Building with DCellar Now | ||
</Text> | ||
<Box textAlign={'center'}> | ||
<Text color={'readable.secondary'}> | ||
DCellar offers a full set of open source toolkits for developers to start build on | ||
Greenfield at ease. | ||
</Text> | ||
</Box> | ||
<Tooltip content="Upcoming"> | ||
<DCButton | ||
margin={'16px auto 0'} | ||
variant="brand" | ||
w={'fit-content'} | ||
onClick={() => onNavigateExternal('#')} | ||
> | ||
Explorer | ||
</DCButton> | ||
</Tooltip> | ||
</Card> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
apps/dcellar-web-ui/src/modules/toolbox/components/UploadkitCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { IconFont } from '@/components/IconFont'; | ||
import { Badge, Flex, Text } from '@totejs/uikit'; | ||
import { Card, CircleLink } from './Common'; | ||
|
||
export const UploadKitCard = () => { | ||
return ( | ||
<Card> | ||
<IconFont type="upload" w={48} /> | ||
<Flex justifyContent={'space-between'} gap={8}> | ||
<Text fontSize={16} fontWeight={600} flex={1}> | ||
Greenfield UploadKit | ||
</Text> | ||
<CircleLink title="github" href="https://github.com/node-real/greenfield-toolkit/tree/main/packages/uploadkit"> | ||
<IconFont type="line-github" w={16} /> | ||
</CircleLink> | ||
<CircleLink title="doc" href="https://node-real.github.io/greenfield-toolkit"> | ||
<IconFont type="doc" w={16} ml={2} /> | ||
</CircleLink> | ||
<CircleLink | ||
title="npm" | ||
href="https://www.npmjs.com/package/@node-real/greenfield-uploadkit" | ||
> | ||
<IconFont type="npm" w={16} /> | ||
</CircleLink> | ||
</Flex> | ||
|
||
<Badge colorScheme="primary" width={'fit-content'} borderRadius={4}> | ||
Component | ||
</Badge> | ||
<Text color={'readable.secondary'}> | ||
Greenfield Upload UIKit is offered by NodeReal, it's fully open sourced, developers can | ||
easily integrate into their WebUI dApps. | ||
</Text> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Box, Flex, Text } from '@totejs/uikit'; | ||
import { TellUsCard } from '../components/TellUsCard'; | ||
import { UploadKitCard } from '../components/UploadkitCard'; | ||
|
||
export const ToolBoxPage = () => { | ||
return ( | ||
<> | ||
<Box> | ||
<Text as="h1" fontSize={24} fontWeight={700} mb={16}> | ||
Toolbox | ||
</Text> | ||
<Flex gap={16} flexWrap={'wrap'}> | ||
<UploadKitCard/> | ||
<TellUsCard /> | ||
</Flex> | ||
</Box> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.