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: mf-6133 get token balance on Conflux #11524

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export const RedPacket = memo(function RedPacket({ payload }: RedPacketProps) {
</Card>
{outdated ?
null
: myProfileId ?
: myHandle ?
<OperationFooter
chainId={payloadChainId}
canClaim={canClaim}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { TokenIcon } from '@masknet/shared'
import { NetworkPluginID } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import { useChainContext, useNetworkDescriptor } from '@masknet/web3-hooks-base'
import { type RedPacketJSONPayload, FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import { FireflyRedPacketAPI, type RedPacketJSONPayload } from '@masknet/web3-providers/types'
import { formatBalance } from '@masknet/web3-shared-base'
import { ChainId, NETWORK_DESCRIPTORS } from '@masknet/web3-shared-evm'
import { Box, ListItem, Typography } from '@mui/material'
import { format, fromUnixTime } from 'date-fns'
import { memo } from 'react'
import { RedPacketTrans, useRedPacketTrans } from '../locales/index.js'
import { RedPacketActionButton } from './RedPacketActionButton.js'

const DEFAULT_BACKGROUND = NETWORK_DESCRIPTORS.find((x) => x.chainId === ChainId.Mainnet)!.backgroundGradient!
const useStyles = makeStyles<{ listItemBackground?: string; listItemBackgroundIcon?: string }>()((
theme,
{ listItemBackground, listItemBackgroundIcon },
Expand Down Expand Up @@ -40,7 +42,7 @@ const useStyles = makeStyles<{ listItemBackground?: string; listItemBackgroundIc
position: 'static !important' as any,
height: 'auto !important',
padding: theme.spacing(1.5),
background: listItemBackground ?? theme.palette.background.default,
background: listItemBackground || DEFAULT_BACKGROUND,
[smallQuery]: {
padding: theme.spacing(2, 1.5),
},
Expand Down Expand Up @@ -139,6 +141,7 @@ interface RedPacketInHistoryListProps {
history: FireflyRedPacketAPI.RedPacketSentInfo
onSelect: (payload: RedPacketJSONPayload) => void
}

export const RedPacketInHistoryList = memo(function RedPacketInHistoryList(props: RedPacketInHistoryListProps) {
const { history } = props
const {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-constants/evm/ethereum.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Celo": "0x8e28F1d64ceD52b9A09aB1AA3071Aa3c05802d1F",
"Fantom": "0xc119574d5fb333f5ac018658d4d8b5035e16bf39",
"Aurora": "0xC119574D5Fb333F5AC018658D4d8b5035E16bf39",
"Conflux": "0x93e0b87a0ad0c991dc1b5176ddcd850c9a78aabb",
"Astar": "0xf5056B96ab242C566002852d0b98ce0BcDf1af51",
"Scroll": "0xbC7d98985966f56A66B0cB5F23d865676dc2ac84",
"Metis": "0xC119574D5Fb333F5AC018658D4d8b5035E16bf39",
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-providers/src/DeBank/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ export enum DebankTransactionDirection {
* Collect from https://docs.cloud.debank.com/en/readme/api-pro-reference/chain#returns-1
*/
export type DebankChains =
| 'base'
| 'eth'
| 'arb'
| 'astar'
| 'aurora'
| 'avax'
| 'base'
| 'boba'
| 'brise'
| 'bsc'
Expand All @@ -23,6 +22,7 @@ export type DebankChains =
| 'cro'
| 'dfk'
| 'doge'
| 'eth'
| 'evmos'
| 'ftm'
| 'fuse'
Expand All @@ -44,14 +44,14 @@ export type DebankChains =
| 'pls'
| 'rsk'
| 'sbch'
| 'scrl'
| 'sdn'
| 'sgb'
| 'step'
| 'swm'
| 'tlos'
| 'wan'
| 'xdai'
| 'scrl'

export interface DictItem {
name: string
Expand Down
24 changes: 21 additions & 3 deletions packages/web3-providers/src/Web3/EVM/apis/ConnectionReadonlyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,26 @@ export class EVMConnectionReadonlyAPI

const options = this.ConnectionOptions.fill(initial)
const NATIVE_TOKEN_ADDRESS = getTokenConstant(options.chainId, 'NATIVE_TOKEN_ADDRESS')
const BALANCE_CHECKER_ADDRESS = getEthereumConstant(options.chainId, 'BALANCE_CHECKER_ADDRESS')
const entities: Array<[string, string]> = []

if (listOfAddress.some(isNativeTokenAddress)) {
entities.push([NATIVE_TOKEN_ADDRESS ?? '', await this.getBalance(options.account, options)])
}
const BALANCE_CHECKER_ADDRESS = getEthereumConstant(options.chainId, 'BALANCE_CHECKER_ADDRESS')
if (!BALANCE_CHECKER_ADDRESS) {
if (process.env.NODE_ENV === 'development') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could build it in those constant helpers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends. Not all constant variables need to be checked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. We can impl this if we need in the future.

console.error(
`BALANCE_CHECKER_ADDRESS for chain ${options.chainId} is not provided, do you forget to update packages/web3-constants/evm/ethereum.json ?`,
BALANCE_CHECKER_ADDRESS,
)
}
return Object.fromEntries(entities)
}

const listOfNonNativeAddress = listOfAddress.filter((x) => !isNativeTokenAddress(x))

if (listOfNonNativeAddress.length) {
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS ?? '', options)
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS, options)
const balances = await contract?.methods.balances([options.account], listOfNonNativeAddress).call({
// cannot check the sender's balance in the same contract
from: undefined,
Expand All @@ -551,7 +560,16 @@ export class EVMConnectionReadonlyAPI

const options = this.ConnectionOptions.fill(initial)
const BALANCE_CHECKER_ADDRESS = getEthereumConstant(options.chainId, 'BALANCE_CHECKER_ADDRESS')
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS ?? '', options)
if (!BALANCE_CHECKER_ADDRESS) {
if (process.env.NODE_ENV === 'development') {
console.error(
`BALANCE_CHECKER_ADDRESS for chain ${options.chainId} is not provided, do you forget to update packages/web3-constants/evm/ethereum.json ?`,
BALANCE_CHECKER_ADDRESS,
)
}
return {}
}
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS, options)
const result = await contract?.methods.balances([options.account], listOfAddress).call({
// cannot check the sender's balance in the same contract
from: undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/web3-shared/evm/src/constants/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export const NETWORK_DESCRIPTORS: ReadonlyArray<NetworkDescriptor<ChainId, Netwo
icon: new URL('../assets/conflux.png', import.meta.url).href,
iconColor: 'rgb(112, 212, 74)',
averageBlockDelay: 10,
backgroundGradient: 'linear-gradient(180deg, rgba(72, 168, 166, 0.15) 0%, rgba(72, 168, 166, 0.05) 100%)',
isMainnet: true,
},
{
Expand Down