diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 31322587..877df09a 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -203,8 +203,10 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { useEffect(() => { // Sets Setting network from coordinator API param if accessing via web - if (settings.network == undefined) { - setSettings({ ...settings, network: info.network }); + if (settings.network == undefined && info.network) { + setSettings((settings: Settings) => { + return { ...settings, network: info.network }; + }); } }, [info]); diff --git a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx index 620a7a65..0c8f4dd6 100644 --- a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx +++ b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx @@ -172,44 +172,59 @@ export const LightningPayoutForm = ({ lnproxyUrl(); }, [lightning.lnproxyServer]); - // const fetchLnproxy = function () { - // setLoadingLnproxy(true); - // apiClient - // .get( - // lnproxyUrl(), - // `/api/${lightning.lnproxyInvoice}${lightning.lnproxyBudgetSats > 0 ? `?routing_msat=${lightning.lnproxyBudgetSats * 1000}` : ''}`, - // ) - // }; - - // Lnproxy API does not return JSON, therefore not compatible with current apiClient service - // Does not work on Android robosats! const fetchLnproxy = function () { setLoadingLnproxy(true); - fetch( - lnproxyUrl() + - `/api/${lightning.lnproxyInvoice.toLocaleLowerCase()}${ + apiClient + .get( + lnproxyUrl(), + `/api/${lightning.lnproxyInvoice}${ lightning.lnproxyBudgetSats > 0 ? `?routing_msat=${lightning.lnproxyBudgetSats * 1000}` : '' - }`, - ) - .then((response) => response.text()) - .then((text) => { - if (text.includes('lnproxy error')) { - setLightning({ ...lightning, badLnproxy: text }); + }&format=json`, + ) + .then((data) => { + if (data.reason) { + setLightning({ ...lightning, badLnproxy: data.reason }); + } else if (data.wpr) { + setLightning({ ...lightning, invoice: data.wpr, badLnproxy: '' }); } else { - const invoice = text.replace('\n', ''); - setLightning({ ...lightning, invoice, badLnproxy: '' }); + setLightning({ ...lightning, badLnproxy: 'Unknown lnproxy response' }); } }) .catch(() => { setLightning({ ...lightning, badLnproxy: 'Lnproxy server uncaught error' }); }) - .finally(() => { - setLoadingLnproxy(false); - }); + .finally(() => setLoadingLnproxy(false)); }; + // const fetchLnproxy = function () { + // setLoadingLnproxy(true); + // fetch( + // lnproxyUrl() + + // `/api/${lightning.lnproxyInvoice.toLocaleLowerCase()}${ + // lightning.lnproxyBudgetSats > 0 + // ? `?routing_msat=${lightning.lnproxyBudgetSats * 1000}` + // : '' + // }`, + // ) + // .then((response) => response.text()) + // .then((text) => { + // if (text.includes('lnproxy error')) { + // setLightning({ ...lightning, badLnproxy: text }); + // } else { + // const invoice = text.replace('\n', ''); + // setLightning({ ...lightning, invoice, badLnproxy: '' }); + // } + // }) + // .catch(() => { + // setLightning({ ...lightning, badLnproxy: 'Lnproxy server uncaught error' }); + // }) + // .finally(() => { + // setLoadingLnproxy(false); + // }); + // }; + const handleAdvancedOptions = function (checked: boolean) { if (checked) { setLightning({ @@ -376,47 +391,43 @@ export const LightningPayoutForm = ({ /> - {window.NativeRobosats === undefined ? ( - - -
- - setLightning({ - ...lightning, - useLnproxy: e.target.checked, - invoice: e.target.checked ? '' : lightning.invoice, - }) - } - checked={lightning.useLnproxy} - control={} - label={ - - {t('Use Lnproxy')} - - } - />{' '} - - - -
-
-
- ) : ( - <> - )} + + +
+ + setLightning({ + ...lightning, + useLnproxy: e.target.checked, + invoice: e.target.checked ? '' : lightning.invoice, + }) + } + checked={lightning.useLnproxy} + control={} + label={ + + {t('Use Lnproxy')} + + } + />{' '} + + + +
+
+
diff --git a/frontend/src/components/TradeBox/index.tsx b/frontend/src/components/TradeBox/index.tsx index fca89565..39dddb22 100644 --- a/frontend/src/components/TradeBox/index.tsx +++ b/frontend/src/components/TradeBox/index.tsx @@ -287,7 +287,7 @@ const TradeBox = ({ }, [order.status]); const statusToContract = function (order: Order) { - const status = 6; + const status = order.status; const isBuyer = order.is_buyer; const isMaker = order.is_maker;