Skip to content

Commit

Permalink
Add lnproxy json responses, enable lnproxy on android app
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Nov 27, 2022
1 parent 0ae63c5 commit f7d4648
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 69 deletions.
6 changes: 4 additions & 2 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
143 changes: 77 additions & 66 deletions frontend/src/components/TradeBox/Forms/LightningPayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TradeBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f7d4648

Please sign in to comment.