1
1
import path from "path" ;
2
2
import url from "url" ;
3
3
import fs from "fs" ;
4
+ import fsPromises from "fs/promises" ;
5
+
4
6
import os from "os" ;
5
7
6
8
import queryString from "query-string" ;
@@ -46,7 +48,6 @@ const logger = new Logger(isDevMode ? 3 : 0);
46
48
let tray = null ;
47
49
let regexBTS = / 1 .2 .\d + / g;
48
50
49
-
50
51
async function _readFile ( filePath ) {
51
52
return new Promise ( ( resolve , reject ) => {
52
53
if ( ! filePath || ! filePath . includes ( ".bin" ) ) {
@@ -618,6 +619,8 @@ const createWindow = async () => {
618
619
ipcMain . handle ( "blockchainRequest" , async ( event , arg ) => {
619
620
const { methods, account, chain } = arg ;
620
621
622
+ console . log ( { methods, account, chain } ) ;
623
+
621
624
let blockchain ;
622
625
try {
623
626
blockchain = await getBlockchainAPI ( chain ) ;
@@ -864,7 +867,7 @@ const createWindow = async () => {
864
867
allowedOperations
865
868
) ;
866
869
} catch ( error ) {
867
- console . log ( error ) ;
870
+ console . log ( { error, location : "_parseDeeplink" } ) ;
868
871
}
869
872
870
873
if ( apiobj && apiobj . type === Actions . INJECTED_CALL ) {
@@ -892,50 +895,51 @@ const createWindow = async () => {
892
895
893
896
if ( methods . includes ( "localFileUpload" ) ) {
894
897
const { allowedOperations, filePath } = arg ;
898
+ try {
899
+ const data = await fsPromises . readFile ( filePath , "utf-8" ) ;
900
+
901
+ let apiobj ;
902
+ try {
903
+ apiobj = await _parseDeeplink (
904
+ data ,
905
+ "local" ,
906
+ chain ,
907
+ blockchain ,
908
+ blockchainActions ,
909
+ allowedOperations ,
910
+ null , // avoid TOTP
911
+ true // changes request parsing
912
+ ) ;
913
+ } catch ( error ) {
914
+ console . log ( error ) ;
915
+ }
895
916
896
- fs . readFile ( filePath , "utf-8" , async ( error , data ) => {
897
- if ( ! error ) {
898
- let apiobj ;
917
+ if ( apiobj && apiobj . type === Actions . INJECTED_CALL ) {
918
+ let status ;
899
919
try {
900
- apiobj = await _parseDeeplink (
901
- data ,
902
- "local" ,
903
- chain ,
920
+ status = await inject (
904
921
blockchain ,
905
- blockchainActions ,
906
- allowedOperations ,
907
- null , // avoid TOTP
908
- true // changes request parsing
922
+ apiobj ,
923
+ mainWindow . webContents
909
924
) ;
910
925
} catch ( error ) {
911
- console . log ( error ) ;
926
+ console . log ( { error : error || "No status" } ) ;
912
927
}
913
928
914
- if ( apiobj && apiobj . type === Actions . INJECTED_CALL ) {
915
- let status ;
916
- try {
917
- status = await inject (
918
- blockchain ,
919
- apiobj ,
920
- mainWindow . webContents
921
- ) ;
922
- } catch ( error ) {
923
- console . log ( { error : error || "No status" } ) ;
924
- }
929
+ console . log ( { status } ) ;
925
930
926
- if (
927
- status &&
928
- status . result &&
929
- ! status . result . isError &&
930
- ! status . result . canceled
931
- ) {
932
- responses [ "localFileUpload" ] = status . result ;
933
- }
931
+ if (
932
+ status &&
933
+ status . result &&
934
+ ! status . result . isError &&
935
+ ! status . result . canceled
936
+ ) {
937
+ responses [ "localFileUpload" ] = status . result ;
934
938
}
935
- } else {
936
- console . log ( { error } ) ;
937
939
}
938
- } ) ;
940
+ } catch ( error ) {
941
+ console . log ( { error } ) ;
942
+ }
939
943
}
940
944
941
945
if ( methods . includes ( "processQR" ) ) {
@@ -1079,7 +1083,7 @@ const createWindow = async () => {
1079
1083
}
1080
1084
}
1081
1085
}
1082
-
1086
+
1083
1087
if ( methods . includes ( "decryptBackup" ) ) {
1084
1088
const { filePath, pass } = arg ;
1085
1089
@@ -1099,7 +1103,7 @@ const createWindow = async () => {
1099
1103
} catch ( error ) {
1100
1104
console . log ( { error } ) ;
1101
1105
}
1102
-
1106
+
1103
1107
if ( unlocked ) {
1104
1108
let retrievedAccounts ;
1105
1109
try {
@@ -1110,12 +1114,12 @@ const createWindow = async () => {
1110
1114
} catch ( error ) {
1111
1115
console . log ( { error } ) ;
1112
1116
}
1113
-
1117
+
1114
1118
if ( retrievedAccounts ) {
1115
1119
responses [ "decryptBackup" ] = retrievedAccounts ;
1116
1120
}
1117
1121
}
1118
-
1122
+
1119
1123
wh = null ;
1120
1124
}
1121
1125
}
0 commit comments