@@ -54,37 +54,44 @@ export const Loader = ({ setIsDialogOpen }: { setIsDialogOpen?: (val: boolean) =
54
54
55
55
if ( searchParams . get ( "program" ) ) {
56
56
const program = searchParams . get ( "program" ) ;
57
- const parsedBlob = bytes . BytesBlob . parseBlob ( program ?? "" ) ;
58
- const parsedBlobArray = Array . prototype . slice . call ( parsedBlob . raw ) ;
59
57
60
- if ( searchParams . get ( "flavour" ) === "jam" ) {
61
- try {
62
- const { code, /*memory,*/ registers } = decodeStandardProgram ( parsedBlob . raw , new Uint8Array ( ) ) ;
58
+ try {
59
+ // Add 0x prefix if it's not there - we're assuming it's the hex program either way
60
+ const hexProgram = program ?. startsWith ( "0x" ) ? program : `0x${ program } ` ;
61
+ const parsedBlob = bytes . BytesBlob . parseBlob ( hexProgram ?? "" ) ;
62
+ const parsedBlobArray = Array . prototype . slice . call ( parsedBlob . raw ) ;
63
+
64
+ if ( searchParams . get ( "flavour" ) === "jam" ) {
65
+ try {
66
+ const { code, /*memory,*/ registers } = decodeStandardProgram ( parsedBlob . raw , new Uint8Array ( ) ) ;
63
67
64
- handleLoad ( {
65
- program : Array . from ( code ) ,
68
+ handleLoad ( {
69
+ program : Array . from ( code ) ,
70
+ name : "custom" ,
71
+ initial : {
72
+ regs : Array . from ( registers ) as RegistersArray ,
73
+ pc : 0 ,
74
+ pageMap : [ ] ,
75
+ // TODO: map memory properly
76
+ // memory: [...memory],
77
+ gas : 10000n ,
78
+ } ,
79
+ } ) ;
80
+ } catch ( e ) {
81
+ console . warn ( "Could not load the program from URL" , e ) ;
82
+ }
83
+ } else {
84
+ handleLoad ( undefined , {
85
+ program : parsedBlobArray ,
66
86
name : "custom" ,
67
- initial : {
68
- regs : Array . from ( registers ) as RegistersArray ,
69
- pc : 0 ,
70
- pageMap : [ ] ,
71
- // TODO: map memory properly
72
- // memory: [...memory],
73
- gas : 10000n ,
74
- } ,
87
+ initial : initialState ,
75
88
} ) ;
76
- } catch ( e ) {
77
- console . warn ( "Could not load the program from URL" ) ;
78
89
}
79
- } else {
80
- handleLoad ( undefined , {
81
- program : parsedBlobArray ,
82
- name : "custom" ,
83
- initial : initialState ,
84
- } ) ;
85
- }
86
90
87
- window . history . replaceState ( { } , document . title , "/" ) ;
91
+ window . history . replaceState ( { } , document . title , "/" ) ;
92
+ } catch ( e ) {
93
+ console . warn ( "Could not parse the program from URL" , e ) ;
94
+ }
88
95
}
89
96
// eslint-disable-next-line react-hooks/exhaustive-deps
90
97
} , [ ] ) ;
0 commit comments