@@ -636,6 +636,8 @@ function validateServer() {
636
636
console . log ( err ) ;
637
637
setError ( err ) ;
638
638
}
639
+
640
+ setUrlParam ( 'network' , event . target . value ) ;
639
641
} ,
640
642
false ,
641
643
) ;
@@ -670,6 +672,8 @@ function validatePact() {
670
672
console . log ( err ) ;
671
673
setError ( err ) ;
672
674
}
675
+
676
+ setUrlParam ( 'requestKey' , event . target . value ) ;
673
677
} ,
674
678
false ,
675
679
) ;
@@ -739,6 +743,9 @@ function isAccountEligibleForGasPayment() {
739
743
window . addEventListener (
740
744
'load' ,
741
745
async function ( ) {
746
+ fillNetworkIdFromQueryString ( ) ;
747
+ fillRequestKeyFromQueryString ( ) ;
748
+
742
749
State . server = State . server ? State . server : 'api.chainweb.com' ;
743
750
State . networkId = State . networkId ? State . networkId : 'mainnet01' ;
744
751
State . requestKey = State . requestKey ? State . requestKey : '' ;
@@ -1033,3 +1040,38 @@ function makeRawRequestInit(stringBody) {
1033
1040
body : stringBody ,
1034
1041
} ;
1035
1042
}
1043
+
1044
+ function fillNetworkIdFromQueryString ( ) {
1045
+ const network = getParameterByName ( 'network' ) ;
1046
+ if ( network ) {
1047
+ document . getElementById ( 'server' ) . value = network ;
1048
+ State . server = network ;
1049
+ }
1050
+ }
1051
+
1052
+ function fillRequestKeyFromQueryString ( ) {
1053
+ const requestKey = getParameterByName ( 'requestKey' ) ;
1054
+ if ( requestKey ) {
1055
+ document . getElementById ( 'pact-id' ) . value = requestKey ;
1056
+ State . requestKey = requestKey ;
1057
+ }
1058
+ }
1059
+
1060
+ function getParameterByName ( name , url = window . location . href ) {
1061
+ name = name . replace ( / [ \[ \] ] / g, '\\$&' ) ;
1062
+ const regex = new RegExp ( `[?&]${ name } (=([^&#]*)|&|#|$)` ) ;
1063
+ const results = regex . exec ( url ) ;
1064
+ if ( ! results ) return null ;
1065
+ if ( ! results [ 2 ] ) return '' ;
1066
+ return decodeURIComponent ( results [ 2 ] . replace ( / \+ / g, ' ' ) ) ;
1067
+ }
1068
+
1069
+ function setUrlParam ( key , value ) {
1070
+ const urlParams = new URLSearchParams ( window . location . search ) ;
1071
+ urlParams . set ( key , value ) ;
1072
+ window . history . replaceState (
1073
+ { } ,
1074
+ '' ,
1075
+ `${ window . location . pathname } ?${ urlParams } ` ,
1076
+ ) ;
1077
+ }
0 commit comments