11import { Collapse , Paper } from '@mui/material' ;
2- import { createTheme , ThemeProvider } from '@mui/material/styles' ;
2+ import { createTheme , ThemeProvider , useTheme } from '@mui/material/styles' ;
33import useMediaQuery from '@mui/material/useMediaQuery' ;
44import {
55 BaseEntityEvent ,
@@ -26,6 +26,7 @@ import { BitcoinStatusBar } from './Data/BitcoinStatusBar';
2626import { ContractModel , Data } from './Data/ContractManager' ;
2727import { ModelManager } from './Data/ModelManager' ;
2828import { SimulationController } from './Data/Simulation' ;
29+ import { selectSimIsShowing , toggle_showing } from './Data/SimulationSlice' ;
2930import { TransactionModel } from './Data/Transaction' ;
3031import { UTXOModel } from './Data/UTXO' ;
3132import './Glyphs.css' ;
@@ -150,13 +151,7 @@ function AppInner(props: {
150151} ) {
151152 const bitcoin_node_bar = useSelector ( selectStatusBar ) ;
152153 const { engine, model, load_new_contract } = props ;
153- const entity_id : EntityType = useSelector ( selectEntityToView ) ;
154-
155- const show = useSelector ( selectShouldViewEntity ) ;
156- const details = entity_id [ 0 ] !== 'NULL' && show ;
157154
158- const [ timing_simulator_enabled , set_timing_simulator_enabled ] =
159- React . useState ( false ) ;
160155 // engine is the processor for graphs, we need to load all our custom factories here
161156
162157 const [ contract_data , counter ] = useSelector ( selectContract ) ;
@@ -173,26 +168,6 @@ function AppInner(props: {
173168
174169 const is_showing = useSelector ( selectShowing ) ;
175170
176- React . useEffect ( ( ) => {
177- if ( entity_id [ 0 ] === 'TXN' )
178- jump_to_entity (
179- model ,
180- engine ,
181- TXIDAndWTXIDMap . get_by_txid_s (
182- current_contract . txid_map ,
183- entity_id [ 1 ]
184- ) ?? null
185- ) ;
186- else if ( entity_id [ 0 ] === 'UTXO' )
187- jump_to_entity (
188- model ,
189- engine ,
190- TXIDAndWTXIDMap . get_by_txid_s (
191- current_contract . txid_map ,
192- entity_id [ 1 ] . hash
193- ) ?. utxo_models [ entity_id [ 1 ] . nIn ] ?? null
194- ) ;
195- } , [ entity_id ] ) ;
196171 const relayout = ( ) => {
197172 dag . redistribute ( props . model ) ;
198173 engine . repaintCanvas ( ) ;
@@ -237,58 +212,6 @@ function AppInner(props: {
237212 } ) ,
238213 [ prefersDarkMode ]
239214 ) ;
240- let showing = null ;
241- switch ( is_showing ) {
242- case 'Settings' :
243- showing = (
244- < Paper className = "settings-container" square = { true } >
245- < Settings > </ Settings >
246- </ Paper >
247- ) ;
248- break ;
249- case 'Wallet' :
250- showing = (
251- < Paper className = "wallet-container" square = { true } >
252- < Wallet
253- bitcoin_node_manager = { bitcoin_node_manager }
254- > </ Wallet >
255- </ Paper >
256- ) ;
257- break ;
258- case 'ContractCreator' :
259- showing = < CreateContractModal /> ;
260- break ;
261- case 'ContractViewer' :
262- showing = (
263- < >
264- < div className = "main-container" >
265- < DemoCanvasWidget
266- engine = { engine }
267- model = { model }
268- background = { theme . palette . background . paper }
269- color = { theme . palette . divider }
270- >
271- < CanvasWidget engine = { engine as any } key = { 'main' } />
272- </ DemoCanvasWidget >
273- </ div >
274- < Collapse in = { details } >
275- < CurrentlyViewedEntity
276- current_contract = { current_contract }
277- />
278- </ Collapse >
279- < div className = "area-overlays" >
280- < Collapse in = { timing_simulator_enabled } >
281- < SimulationController
282- contract = { current_contract }
283- engine = { engine }
284- hide = { ( ) => set_timing_simulator_enabled ( false ) }
285- />
286- </ Collapse >
287- </ div >
288- </ >
289- ) ;
290- break ;
291- }
292215 return (
293216 < ThemeProvider theme = { theme } >
294217 < div className = "App" >
@@ -298,14 +221,16 @@ function AppInner(props: {
298221 relayout = { relayout }
299222 bitcoin_node_manager = { bitcoin_node_manager }
300223 contract = { current_contract }
301- toggle_timing_simulator = { ( ) =>
302- set_timing_simulator_enabled (
303- ! timing_simulator_enabled
304- )
305- }
306224 />
307225 </ div >
308- < div className = "area-inner" > { showing } </ div >
226+ < div className = "area-inner" >
227+ < Viewing
228+ bitcoin_node_manager = { bitcoin_node_manager }
229+ model = { model }
230+ engine = { engine }
231+ current_contract = { current_contract }
232+ />
233+ </ div >
309234 </ div >
310235 < div hidden = { ! bitcoin_node_bar } >
311236 { bitcoin_node_bar && (
@@ -323,4 +248,92 @@ function AppInner(props: {
323248 ) ;
324249}
325250
251+ function Viewing ( props : {
252+ model : DiagramModel ;
253+ engine : DiagramEngine ;
254+ current_contract : ContractModel ;
255+ bitcoin_node_manager : BitcoinNodeManager ;
256+ } ) {
257+ const is_showing = useSelector ( selectShowing ) ;
258+ switch ( is_showing ) {
259+ case 'Settings' :
260+ return (
261+ < Paper className = "settings-container" square = { true } >
262+ < Settings > </ Settings >
263+ </ Paper >
264+ ) ;
265+ case 'Wallet' :
266+ return (
267+ < Paper className = "wallet-container" square = { true } >
268+ < Wallet
269+ bitcoin_node_manager = { props . bitcoin_node_manager }
270+ > </ Wallet >
271+ </ Paper >
272+ ) ;
273+ case 'ContractCreator' :
274+ return < CreateContractModal /> ;
275+ case 'ContractViewer' :
276+ return < ContractViewer { ...props } /> ;
277+ }
278+ }
279+ function ContractViewer ( props : {
280+ model : DiagramModel ;
281+ engine : DiagramEngine ;
282+ current_contract : ContractModel ;
283+ } ) {
284+ const dispatch = useDispatch ( ) ;
285+ const entity_id : EntityType = useSelector ( selectEntityToView ) ;
286+ const show = useSelector ( selectShouldViewEntity ) ;
287+ const theme = useTheme ( ) ;
288+ const timing_simulator_enabled = useSelector ( selectSimIsShowing ) ;
289+ const details = entity_id [ 0 ] !== 'NULL' && show ;
290+ const { model, engine, current_contract } = props ;
291+ React . useEffect ( ( ) => {
292+ if ( entity_id [ 0 ] === 'TXN' )
293+ jump_to_entity (
294+ model ,
295+ engine ,
296+ TXIDAndWTXIDMap . get_by_txid_s (
297+ current_contract . txid_map ,
298+ entity_id [ 1 ]
299+ ) ?? null
300+ ) ;
301+ else if ( entity_id [ 0 ] === 'UTXO' )
302+ jump_to_entity (
303+ model ,
304+ engine ,
305+ TXIDAndWTXIDMap . get_by_txid_s (
306+ current_contract . txid_map ,
307+ entity_id [ 1 ] . hash
308+ ) ?. utxo_models [ entity_id [ 1 ] . nIn ] ?? null
309+ ) ;
310+ } , [ entity_id ] ) ;
311+
312+ return (
313+ < >
314+ < div className = "main-container" >
315+ < DemoCanvasWidget
316+ engine = { engine }
317+ model = { model }
318+ background = { theme . palette . background . paper }
319+ color = { theme . palette . divider }
320+ >
321+ < CanvasWidget engine = { engine as any } key = { 'main' } />
322+ </ DemoCanvasWidget >
323+ </ div >
324+ < Collapse in = { details } >
325+ < CurrentlyViewedEntity current_contract = { current_contract } />
326+ </ Collapse >
327+ < div className = "area-overlays" >
328+ < Collapse in = { timing_simulator_enabled } >
329+ < SimulationController
330+ contract = { current_contract }
331+ engine = { engine }
332+ hide = { ( ) => dispatch ( toggle_showing ( ) ) }
333+ />
334+ </ Collapse >
335+ </ div >
336+ </ >
337+ ) ;
338+ }
326339export default App ;
0 commit comments