Add lnproxy json responses, enable lnproxy on android app

This commit is contained in:
Reckless_Satoshi 2022-11-27 12:34:37 -08:00
parent 0ae63c50d2
commit f7d4648fa5
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 82 additions and 69 deletions

View File

@ -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]);

View File

@ -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 = ({
/>
</Grid>
{window.NativeRobosats === undefined ? (
<Grid item>
<Tooltip
enterTouchDelay={0}
leaveTouchDelay={4000}
placement='top'
title={t(
`Wrap this invoice using a Lnproxy server to protect your privacy (hides the receiving wallet).`,
)}
>
<div>
<FormControlLabel
onChange={(e) =>
setLightning({
...lightning,
useLnproxy: e.target.checked,
invoice: e.target.checked ? '' : lightning.invoice,
})
}
checked={lightning.useLnproxy}
control={<Checkbox />}
label={
<Typography color={lightning.useLnproxy ? 'primary' : 'text.secondary'}>
{t('Use Lnproxy')}
</Typography>
}
/>{' '}
<IconButton
component='a'
target='_blank'
href='https://www.lnproxy.org/about'
rel='noreferrer'
>
<Help sx={{ width: '0.9em', height: '0.9em', color: 'text.secondary' }} />
</IconButton>
</div>
</Tooltip>
</Grid>
) : (
<></>
)}
<Grid item>
<Tooltip
enterTouchDelay={0}
leaveTouchDelay={4000}
placement='top'
title={t(
`Wrap this invoice using a Lnproxy server to protect your privacy (hides the receiving wallet).`,
)}
>
<div>
<FormControlLabel
onChange={(e) =>
setLightning({
...lightning,
useLnproxy: e.target.checked,
invoice: e.target.checked ? '' : lightning.invoice,
})
}
checked={lightning.useLnproxy}
control={<Checkbox />}
label={
<Typography color={lightning.useLnproxy ? 'primary' : 'text.secondary'}>
{t('Use Lnproxy')}
</Typography>
}
/>{' '}
<IconButton
component='a'
target='_blank'
href='https://www.lnproxy.org/about'
rel='noreferrer'
>
<Help sx={{ width: '0.9em', height: '0.9em', color: 'text.secondary' }} />
</IconButton>
</div>
</Tooltip>
</Grid>
<Grid item>
<Collapse in={lightning.useLnproxy}>

View File

@ -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;