diff --git a/src/app/screens/connectors/NewWallet/index.tsx b/src/app/screens/connectors/NewWallet/index.tsx index 5344c53682..3d409b5918 100644 --- a/src/app/screens/connectors/NewWallet/index.tsx +++ b/src/app/screens/connectors/NewWallet/index.tsx @@ -95,8 +95,12 @@ export default function NewWallet() { }; try { + console.log("TRY"); + const validation = await utils.call("validateAccount", account); + console.log("validation", validation); if (validation.valid) { + console.log("validation - valid", validation.valid); const addResult = await utils.call("addAccount", account); if (addResult.accountId) { await utils.call("selectAccount", { @@ -105,17 +109,20 @@ export default function NewWallet() { navigate("/test-connection"); } } else { + console.log("validation - ELSE", validation); console.error({ validation }); toast.error( `${tCommon("errors.connection_failed")} (${validation.error})` ); } } catch (e) { + console.log("validation - CATCH", e); console.error(e); if (e instanceof Error) { toast.error(`${tCommon("errors.connection_failed")} (${e.message})`); } } finally { + console.log("validation - FINALLY"); setLoading(false); } } diff --git a/src/extension/background-script/actions/setup/validateAccount.js b/src/extension/background-script/actions/setup/validateAccount.js index 8b57c24926..74ea5365bb 100644 --- a/src/extension/background-script/actions/setup/validateAccount.js +++ b/src/extension/background-script/actions/setup/validateAccount.js @@ -1,16 +1,20 @@ import connectors from "../../connectors"; const validateAccount = async (message, sender) => { + console.log("validateAccount - mess", message); + const account = message.args; const connector = new connectors[account.connector](account.config); await connector.init(); try { + console.log("validateAccount - TRY"); const info = await connector.getInfo(); await connector.unload(); // unload the connector again, we just checked if it works but have no persistence return { data: { valid: true, info: info } }; } catch (e) { + console.log("validateAccount - CATCH", e); console.error(e); return { data: { valid: false, error: e.message } }; } diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 131e6c57ed..e7a8b092d5 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -48,6 +48,8 @@ export default class LndHub implements Connector { } async init() { + console.log("INIT?!"); + return this.authorize(); } @@ -286,30 +288,50 @@ export default class LndHub implements Connector { } async authorize() { - const { data: authData } = await axios.post( - `${this.config.url}/auth?type=auth`, - { + console.log("AUTHORIZE - config url: ", this.config.url); + + const res = await fetch(`${this.config.url}/auth?type=auth`, { + method: "POST", + headers: defaultHeaders, + body: JSON.stringify({ login: this.config.login, password: this.config.password, - }, - { - headers: defaultHeaders, - } - ); + }), + }); - if (authData.error || authData.errors) { - const error = authData.error || authData.errors; - const errMessage = error?.errors?.[0]?.message || error?.[0]?.message; + console.log("RES: ", res); - console.error(errMessage); - throw new Error("API error: " + errMessage); - } else { - this.refresh_token = authData.refresh_token; - this.access_token = authData.access_token; - this.refresh_token_created = +new Date(); - this.access_token_created = +new Date(); + try { + const { data: authData } = await axios.post( + `${this.config.url}/auth?type=auth`, + { + login: this.config.login, + password: this.config.password, + }, + { + headers: defaultHeaders, + } + ); + + console.log("AUTHORIZE - data", authData); - return authData; + if (authData.error || authData.errors) { + const error = authData.error || authData.errors; + const errMessage = error?.errors?.[0]?.message || error?.[0]?.message; + + console.error(errMessage); + throw new Error("API error: " + errMessage); + } else { + this.refresh_token = authData.refresh_token; + this.access_token = authData.access_token; + this.refresh_token_created = +new Date(); + this.access_token_created = +new Date(); + + return authData; + } + } catch (e) { + // https://stackoverflow.com/questions/72798574/axios-error-typeerror-adapter-is-not-a-function + console.log("AUTHORIZE - CATCH", e); } } diff --git a/src/extension/background-script/index.ts b/src/extension/background-script/index.ts index adc91e1efc..3f92447c88 100644 --- a/src/extension/background-script/index.ts +++ b/src/extension/background-script/index.ts @@ -1,3 +1,4 @@ +import axios, { AxiosRequestConfig, Method } from "axios"; import browser, { Runtime, Tabs } from "webextension-polyfill"; import utils from "~/common/lib/utils";