@@ -3,6 +3,7 @@ import Box from '@mui/material/Box';
33import Button from '@mui/material/Button' ;
44import Dialog from '@mui/material/Dialog' ;
55import DialogContent from '@mui/material/DialogContent' ;
6+ import DialogContentText from '@mui/material/DialogContentText' ;
67import {
78 FormControl ,
89 MenuItem ,
@@ -11,6 +12,7 @@ import {
1112 DialogTitle ,
1213 IconButton ,
1314 Divider ,
15+ Link ,
1416} from '@mui/material' ;
1517import { Typography } from '@mui/material' ;
1618import TokenCard from './TokenCard' ;
@@ -20,6 +22,7 @@ import { networksLogos } from '../constants';
2022import networks from '../networks.json' ;
2123import { styled } from '@mui/material/styles' ;
2224import { bridgeToken } from '../api' ;
25+ import { shortenAddress } from '../utils' ;
2326
2427/**
2528 * @param {string } fromId Chain Id of current item
@@ -42,7 +45,7 @@ const getAvaibleChains = (chainId) => {
4245 : [ ] ;
4346} ;
4447
45- function BridgeModal ( { isOpen, toggle, currentItem, chainId, switchNetwork } ) {
48+ function BridgeModal ( { isOpen, toggle, currentItem, chainId, switchNetwork, userAddress } ) {
4649 const descriptionElementRef = React . useRef ( null ) ;
4750 const [ currentChain , setCurrentChain ] = React . useState ( '' ) ;
4851 const [ pending , setPending ] = React . useState ( false ) ;
@@ -72,7 +75,7 @@ function BridgeModal({ isOpen, toggle, currentItem, chainId, switchNetwork }) {
7275
7376 const bridgePrice = getBridgePrice ( currentItem . chainId , currentChain ) ;
7477 const isSameNetwork = currentItem . chainId === Number ( chainId ) ;
75- const bridge = async ( ) => {
78+ const bridge = userAddress === currentItem . owner ? async ( ) => {
7679 if ( isSameNetwork ) {
7780 // toggle()
7881 await bridgeToken (
@@ -90,15 +93,15 @@ function BridgeModal({ isOpen, toggle, currentItem, chainId, switchNetwork }) {
9093 }
9194
9295 switchNetwork ( currentItem . chainId ) ;
93- } ;
96+ } : undefined ;
9497
9598 return (
9699 < BridgeModal . Layout isOpen = { isOpen } toggle = { toggle } >
97100 < Box padding = '40px' >
98101 < TokenCard { ...currentItem } />
99102 </ Box >
100103 < Divider variant = 'middle' orientation = 'vertical' flexItem />
101- < DialogContent
104+ < DialogContentText
102105 id = 'scroll-dialog-description'
103106 ref = { descriptionElementRef }
104107 tabIndex = { - 1 }
@@ -119,16 +122,66 @@ function BridgeModal({ isOpen, toggle, currentItem, chainId, switchNetwork }) {
119122 currectChainId = { currentChain }
120123 setChain = { ( e ) => setCurrentChain ( e . target . value ) }
121124 />
122- < Typography
123- align = 'left'
124- fontWeight = '400'
125- fontSize = '12px'
126- lineHeight = '140%'
127- color = 'rgba(27, 28, 30, 1)'
125+ { txStatus
126+ ? < TxStatus txStatus = { txStatus } txLink = { txLink } txError = { error } fromChainId = { currentItem . chainId } />
127+ : < Info bridgePrice = { bridgePrice } /> }
128+ < MuiButton
129+ onClick = { bridge }
130+ variant = 'contained'
131+ fullWidth
132+ size = 'large'
133+ disabled = { ! bridgePrice || pending || loading || userAddress !== currentItem . owner }
128134 >
129- The stages of bridging will be shown here.
130- </ Typography >
131- < BridgePrice bridgePrice = { bridgePrice } />
135+ { isSameNetwork ? 'bridge' : 'Switch network' }
136+ </ MuiButton >
137+ </ BridgeModal . Body >
138+ </ DialogContentText >
139+ </ BridgeModal . Layout >
140+ ) ;
141+ }
142+
143+
144+ const TxStatus = ( { txStatus, txLink, txError, fromChainId } ) => {
145+ return (
146+ < Box display = 'flex' flexDirection = 'column' mt = '5px' >
147+ < Typography variant = 'subtitle1' fontWeight = { 500 } >
148+ Status:{ ` ` }
149+ < Typography
150+ component = 'span'
151+ color = { txStatus . type === 'success' ? '#28a745' : txStatus . type === 'pending' ? '#ffc107' : '#dc3545' }
152+ fontWeight = { 700 }
153+ >
154+ { txStatus . text }
155+ </ Typography >
156+
157+ </ Typography >
158+ < Typography variant = 'body1' >
159+ Transaction hash:{ ' ' }
160+ < Link
161+ href = { `${ networks [ fromChainId ] . blockExplorer } /tx/${ txLink } ` }
162+ target = '_blank'
163+ fontSize = { '14px' }
164+ >
165+ { shortenAddress ( txLink ) }
166+ </ Link >
167+ </ Typography >
168+ </ Box >
169+ )
170+ }
171+
172+ const Info = ( { bridgePrice} ) => {
173+ return (
174+ < >
175+ < Typography
176+ align = 'left'
177+ fontWeight = '400'
178+ fontSize = '12px'
179+ lineHeight = '140%'
180+ color = 'rgba(27, 28, 30, 1)'
181+ >
182+ The stages of bridging will be shown here.
183+ </ Typography >
184+ < BridgePrice bridgePrice = { bridgePrice } />
132185 < Typography
133186 align = 'left'
134187 fontWeight = '400'
@@ -140,42 +193,8 @@ function BridgeModal({ isOpen, toggle, currentItem, chainId, switchNetwork }) {
140193 { bridgePrice + ' ' }
141194 or the transaction will be rolled back
142195 </ Typography >
143- < MuiButton
144- onClick = { bridge }
145- variant = 'contained'
146- fullWidth
147- size = 'large'
148- disabled = { ! bridgePrice || pending || loading }
149- >
150- { isSameNetwork ? 'bridge' : 'Switch network' }
151- </ MuiButton >
152-
153- { txStatus && (
154- < Box display = 'flex' flexDirection = 'column' >
155- < Typography > { pending } </ Typography >
156- < Typography > { txStatus } </ Typography >
157- < Typography >
158- < a
159- href = {
160- networks [ currentItem . chainId ] . blockExplorer +
161- '/tx/' +
162- txLink
163- }
164- target = '_blank'
165- rel = 'noreferrer'
166- >
167- link
168- </ a >
169- </ Typography >
170- < Typography > { confirmed } </ Typography >
171- < Typography > { loading } </ Typography >
172- { error && < Typography > { `Some error occured` } </ Typography > }
173- </ Box >
174- ) }
175- </ BridgeModal . Body >
176- </ DialogContent >
177- </ BridgeModal . Layout >
178- ) ;
196+ </ >
197+ )
179198}
180199
181200BridgeModal . Layout = ( { children, isOpen, toggle } ) => {
0 commit comments