Skip to content

Commit 58d57f1

Browse files
fix: mf-6133 get token balance on Conflux (#11524) (#11526)
Co-authored-by: Wukong Sun <[email protected]>
1 parent ecda511 commit 58d57f1

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

Diff for: packages/plugins/RedPacket/src/SiteAdaptor/RedPacketInHistoryList.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type RedPacketJSONPayloadFromChain,
99
} from '@masknet/web3-providers/types'
1010
import { formatBalance, minus, type FungibleToken } from '@masknet/web3-shared-base'
11-
import { type ChainId, type SchemaType } from '@masknet/web3-shared-evm'
11+
import { ChainId, type SchemaType, NETWORK_DESCRIPTORS } from '@masknet/web3-shared-evm'
1212
import { Box, ListItem, Typography, useMediaQuery, type Theme } from '@mui/material'
1313
import { intervalToDuration, nextDay } from 'date-fns'
1414
import { memo, useCallback, useMemo } from 'react'
@@ -19,6 +19,7 @@ import { useCreateRedPacketReceipt } from './hooks/useCreateRedPacketReceipt.js'
1919
import { useRefundCallback } from './hooks/useRefundCallback.js'
2020
import { dateTimeFormat } from './utils/formatDate.js'
2121

22+
const DEFAULT_BACKGROUND = NETWORK_DESCRIPTORS.find((x) => x.chainId === ChainId.Mainnet)!.backgroundGradient!
2223
const useStyles = makeStyles<{ listItemBackground?: string; listItemBackgroundIcon?: string }>()((
2324
theme,
2425
{ listItemBackground, listItemBackgroundIcon },
@@ -49,7 +50,7 @@ const useStyles = makeStyles<{ listItemBackground?: string; listItemBackgroundIc
4950
position: 'static !important' as any,
5051
height: 'auto !important',
5152
padding: theme.spacing(1.5),
52-
background: listItemBackground ?? theme.palette.background.default,
53+
background: listItemBackground || DEFAULT_BACKGROUND,
5354
[smallQuery]: {
5455
padding: theme.spacing(2, 1.5),
5556
},
@@ -179,6 +180,7 @@ interface RedPacketInHistoryListProps {
179180
history: RedPacketJSONPayload | RedPacketJSONPayloadFromChain
180181
onSelect: (payload: RedPacketJSONPayload) => void
181182
}
183+
182184
export const RedPacketInHistoryList = memo(function RedPacketInHistoryList(props: RedPacketInHistoryListProps) {
183185
const { history, onSelect } = props
184186
const t = useRedPacketTrans()

Diff for: packages/web3-constants/evm/ethereum.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Celo": "0x8e28F1d64ceD52b9A09aB1AA3071Aa3c05802d1F",
1919
"Fantom": "0xc119574d5fb333f5ac018658d4d8b5035e16bf39",
2020
"Aurora": "0xC119574D5Fb333F5AC018658D4d8b5035E16bf39",
21+
"Conflux": "0x93e0b87a0ad0c991dc1b5176ddcd850c9a78aabb",
2122
"Astar": "0xf5056B96ab242C566002852d0b98ce0BcDf1af51",
2223
"Scroll": "0xbC7d98985966f56A66B0cB5F23d865676dc2ac84",
2324
"Metis": "0xC119574D5Fb333F5AC018658D4d8b5035E16bf39",

Diff for: packages/web3-providers/src/DeBank/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ export enum DebankTransactionDirection {
77
* Collect from https://docs.cloud.debank.com/en/readme/api-pro-reference/chain#returns-1
88
*/
99
export type DebankChains =
10-
| 'base'
11-
| 'eth'
1210
| 'arb'
1311
| 'astar'
1412
| 'aurora'
1513
| 'avax'
14+
| 'base'
1615
| 'boba'
1716
| 'brise'
1817
| 'bsc'
@@ -23,6 +22,7 @@ export type DebankChains =
2322
| 'cro'
2423
| 'dfk'
2524
| 'doge'
25+
| 'eth'
2626
| 'evmos'
2727
| 'ftm'
2828
| 'fuse'
@@ -44,14 +44,14 @@ export type DebankChains =
4444
| 'pls'
4545
| 'rsk'
4646
| 'sbch'
47+
| 'scrl'
4748
| 'sdn'
4849
| 'sgb'
4950
| 'step'
5051
| 'swm'
5152
| 'tlos'
5253
| 'wan'
5354
| 'xdai'
54-
| 'scrl'
5555

5656
export interface DictItem {
5757
name: string

Diff for: packages/web3-providers/src/Web3/EVM/apis/ConnectionReadonlyAPI.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,26 @@ export class EVMConnectionReadonlyAPI
531531

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

537536
if (listOfAddress.some(isNativeTokenAddress)) {
538537
entities.push([NATIVE_TOKEN_ADDRESS ?? '', await this.getBalance(options.account, options)])
539538
}
539+
const BALANCE_CHECKER_ADDRESS = getEthereumConstant(options.chainId, 'BALANCE_CHECKER_ADDRESS')
540+
if (!BALANCE_CHECKER_ADDRESS) {
541+
if (process.env.NODE_ENV === 'development') {
542+
console.error(
543+
`BALANCE_CHECKER_ADDRESS for chain ${options.chainId} is not provided, do you forget to update packages/web3-constants/evm/ethereum.json ?`,
544+
BALANCE_CHECKER_ADDRESS,
545+
)
546+
}
547+
return Object.fromEntries(entities)
548+
}
540549

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

543552
if (listOfNonNativeAddress.length) {
544-
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS ?? '', options)
553+
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS, options)
545554
const balances = await contract?.methods.balances([options.account], listOfNonNativeAddress).call({
546555
// cannot check the sender's balance in the same contract
547556
from: undefined,
@@ -563,7 +572,16 @@ export class EVMConnectionReadonlyAPI
563572

564573
const options = this.ConnectionOptions.fill(initial)
565574
const BALANCE_CHECKER_ADDRESS = getEthereumConstant(options.chainId, 'BALANCE_CHECKER_ADDRESS')
566-
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS ?? '', options)
575+
if (!BALANCE_CHECKER_ADDRESS) {
576+
if (process.env.NODE_ENV === 'development') {
577+
console.error(
578+
`BALANCE_CHECKER_ADDRESS for chain ${options.chainId} is not provided, do you forget to update packages/web3-constants/evm/ethereum.json ?`,
579+
BALANCE_CHECKER_ADDRESS,
580+
)
581+
}
582+
return {}
583+
}
584+
const contract = this.Contract.getBalanceCheckerContract(BALANCE_CHECKER_ADDRESS, options)
567585
const result = await contract?.methods.balances([options.account], listOfAddress).call({
568586
// cannot check the sender's balance in the same contract
569587
from: undefined,

Diff for: packages/web3-shared/evm/src/constants/descriptors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export const NETWORK_DESCRIPTORS: ReadonlyArray<NetworkDescriptor<ChainId, Netwo
244244
icon: new URL('../assets/conflux.png', import.meta.url).href,
245245
iconColor: 'rgb(112, 212, 74)',
246246
averageBlockDelay: 10,
247+
backgroundGradient: 'linear-gradient(180deg, rgba(72, 168, 166, 0.15) 0%, rgba(72, 168, 166, 0.05) 100%)',
247248
isMainnet: true,
248249
},
249250
{

0 commit comments

Comments
 (0)