1
1
import { useSelector } from 'react-redux' ;
2
2
import {
3
- TransactionMeta ,
3
+ type TransactionMeta ,
4
4
TransactionType ,
5
5
} from '@metamask/transaction-controller' ;
6
- import { Hex } from '@metamask/utils' ;
7
- import { NetworkConfiguration } from '@metamask/network-controller' ;
8
- import { Numeric } from '../../../shared/modules/Numeric' ;
9
- import { getNetworkConfigurationsByChainId } from '../../../shared/modules/selectors/networks' ;
10
- import { BridgeHistoryItem } from '../../../shared/types/bridge-status' ;
6
+ import type { NetworkConfiguration } from '@metamask/network-controller' ;
7
+ import type { Hex } from '@metamask/utils' ;
8
+ import type { BridgeHistoryItem } from '../../../shared/types/bridge-status' ;
11
9
import {
12
10
CHAIN_ID_TO_CURRENCY_SYMBOL_MAP ,
13
11
NETWORK_TO_NAME_MAP ,
14
12
} from '../../../shared/constants/network' ;
15
13
import { CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../shared/constants/common' ;
14
+ import { getMultichainNetworkConfigurationsByChainId } from '../../selectors' ;
15
+ import { formatChainIdToHexOrCaip } from '../../../shared/modules/bridge-utils/caip-formatters' ;
16
16
17
17
const getSourceAndDestChainIds = ( {
18
18
bridgeHistoryItem,
19
19
} : UseBridgeChainInfoProps ) => {
20
- const hexSrcChainId = bridgeHistoryItem
21
- ? ( new Numeric (
22
- bridgeHistoryItem . quote . srcChainId ,
23
- 10 ,
24
- ) . toPrefixedHexString ( ) as Hex )
25
- : undefined ;
26
- const hexDestChainId = bridgeHistoryItem
27
- ? ( new Numeric (
28
- bridgeHistoryItem . quote . destChainId ,
29
- 10 ,
30
- ) . toPrefixedHexString ( ) as Hex )
31
- : undefined ;
32
-
33
20
return {
34
- hexSrcChainId,
35
- hexDestChainId,
21
+ srcChainId : bridgeHistoryItem
22
+ ? formatChainIdToHexOrCaip ( bridgeHistoryItem . quote . srcChainId )
23
+ : undefined ,
24
+ destChainId : bridgeHistoryItem
25
+ ? formatChainIdToHexOrCaip ( bridgeHistoryItem . quote . destChainId )
26
+ : undefined ,
36
27
} ;
37
28
} ;
38
29
@@ -45,9 +36,8 @@ export default function useBridgeChainInfo({
45
36
bridgeHistoryItem,
46
37
srcTxMeta,
47
38
} : UseBridgeChainInfoProps ) {
48
- const networkConfigurationsByChainId = useSelector (
49
- getNetworkConfigurationsByChainId ,
50
- ) ;
39
+ const [ networkConfigurationsByChainId ] =
40
+ useSelector ( getMultichainNetworkConfigurationsByChainId ) ?? [ ] ;
51
41
52
42
if ( srcTxMeta ?. type !== TransactionType . bridge ) {
53
43
return {
@@ -56,51 +46,55 @@ export default function useBridgeChainInfo({
56
46
} ;
57
47
}
58
48
59
- const { hexSrcChainId , hexDestChainId } = getSourceAndDestChainIds ( {
49
+ const { srcChainId , destChainId } = getSourceAndDestChainIds ( {
60
50
bridgeHistoryItem,
61
51
} ) ;
62
52
63
- if ( ! hexSrcChainId || ! hexDestChainId ) {
53
+ if ( ! srcChainId || ! destChainId ) {
64
54
return {
65
55
srcNetwork : undefined ,
66
56
destNetwork : undefined ,
67
57
} ;
68
58
}
69
59
70
60
// Source chain info
71
- const srcNetwork = networkConfigurationsByChainId [ hexSrcChainId ]
72
- ? networkConfigurationsByChainId [ hexSrcChainId ]
61
+ const srcNetwork = networkConfigurationsByChainId [
62
+ srcChainId as keyof typeof networkConfigurationsByChainId
63
+ ]
64
+ ? networkConfigurationsByChainId [
65
+ srcChainId as keyof typeof networkConfigurationsByChainId
66
+ ]
73
67
: undefined ;
74
- const fallbackSrcNetwork : NetworkConfiguration = {
75
- chainId : hexSrcChainId ,
76
- name : NETWORK_TO_NAME_MAP [
77
- hexSrcChainId as keyof typeof NETWORK_TO_NAME_MAP
78
- ] ,
68
+ const fallbackSrcNetwork = {
69
+ chainId : srcChainId ,
70
+ name : NETWORK_TO_NAME_MAP [ srcChainId as keyof typeof NETWORK_TO_NAME_MAP ] ,
79
71
nativeCurrency :
80
72
CHAIN_ID_TO_CURRENCY_SYMBOL_MAP [
81
- hexSrcChainId as keyof typeof CHAIN_ID_TO_CURRENCY_SYMBOL_MAP
73
+ srcChainId as keyof typeof CHAIN_ID_TO_CURRENCY_SYMBOL_MAP
82
74
] ,
83
75
defaultBlockExplorerUrlIndex : 0 ,
84
- blockExplorerUrls : [ CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP [ hexSrcChainId ] ] ,
76
+ blockExplorerUrls : [ CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP [ srcChainId ] ] ,
85
77
defaultRpcEndpointIndex : 0 ,
86
78
rpcEndpoints : [ ] ,
87
79
} ;
88
80
89
81
// Dest chain info
90
- const destNetwork = networkConfigurationsByChainId [ hexDestChainId ]
91
- ? networkConfigurationsByChainId [ hexDestChainId ]
82
+ const destNetwork = networkConfigurationsByChainId [
83
+ destChainId as keyof typeof networkConfigurationsByChainId
84
+ ]
85
+ ? networkConfigurationsByChainId [
86
+ destChainId as keyof typeof networkConfigurationsByChainId
87
+ ]
92
88
: undefined ;
93
89
const fallbackDestNetwork : NetworkConfiguration = {
94
- chainId : hexDestChainId ,
95
- name : NETWORK_TO_NAME_MAP [
96
- hexDestChainId as keyof typeof NETWORK_TO_NAME_MAP
97
- ] ,
90
+ chainId : destChainId as Hex ,
91
+ name : NETWORK_TO_NAME_MAP [ destChainId as keyof typeof NETWORK_TO_NAME_MAP ] ,
98
92
nativeCurrency :
99
93
CHAIN_ID_TO_CURRENCY_SYMBOL_MAP [
100
- hexDestChainId as keyof typeof CHAIN_ID_TO_CURRENCY_SYMBOL_MAP
94
+ destChainId as keyof typeof CHAIN_ID_TO_CURRENCY_SYMBOL_MAP
101
95
] ,
102
96
defaultBlockExplorerUrlIndex : 0 ,
103
- blockExplorerUrls : [ CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP [ hexDestChainId ] ] ,
97
+ blockExplorerUrls : [ CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP [ destChainId ] ] ,
104
98
defaultRpcEndpointIndex : 0 ,
105
99
rpcEndpoints : [ ] ,
106
100
} ;
0 commit comments