Skip to content

Commit

Permalink
react-native-tor does not implement PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Sep 20, 2022
1 parent feb3190 commit c8fcec3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/BottomBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class BottomBar extends Component {
handleSetStealthInvoice = (wantsStealth) => {
apiClient
.put('/api/stealth/', { wantsStealth })
.then((data) => this.props.setAppState({ stealthInvoices: data.wantsStealth }));
.then((data) => this.props.setAppState({ stealthInvoices: data?.wantsStealth }));
};

getHost() {
Expand Down
18 changes: 7 additions & 11 deletions frontend/src/services/api/ApiNativeClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ class ApiNativeClient implements ApiClient {
};

public put: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
const requestOptions = {
method: 'PUT',
headers: this.getHeaders(),
body: JSON.stringify(body),
};
return await fetch('https://unsafe.robosats.com' + path, requestOptions).then(async (response) => await response.json());
return new Promise((res, _rej) => res({}))
};

public delete: (path: string) => Promise<object | undefined> = async (path) => {
const requestOptions = {
method: 'DELETE',
headers: this.getHeaders(),
};
return await fetch('https://unsafe.robosats.com' + path, requestOptions).then(async (response) => await response.json());
return window.NativeRobosats?.postMessage({
category: 'http',
type: 'delete',
path,
headers: this.getHeaders()
})
};

public post: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
Expand Down
13 changes: 6 additions & 7 deletions mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const App = () => {
);
};

const manageWebViewMessage = (data: any) => {
const onMessage = async (event: WebViewMessageEvent) => {
const data = JSON.parse(event.nativeEvent.data);
if (data.category === 'http') {
if (data.type === 'get') {
torClient.get(data.path).then((response: object) => {
Expand All @@ -30,14 +31,13 @@ const App = () => {
injectMessage(data.id, response);
});
}
} else if (data.type === 'delete') {
torClient.delete(data.path, data.headers).then((response: object) => {
injectMessage(data.id, response);
});
}
};

const onMessage = async (event: WebViewMessageEvent) => {
const data = JSON.parse(event.nativeEvent.data);
manageWebViewMessage(data);
};

torClient.startDaemon();

return (
Expand Down Expand Up @@ -66,7 +66,6 @@ const App = () => {
mediaPlaybackRequiresUserAction={false}
allowsLinkPreview={false}
renderLoading={() => <Text>Loading RoboSats</Text>}
onError={syntheticEvent => <Text>{syntheticEvent}</Text>}
/>
</SafeAreaView>
);
Expand Down
21 changes: 21 additions & 0 deletions mobile/services/Tor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ class TorClient {
});
};

public delete: (path: string, headers: object) => Promise<object> = async (
path,
headers,
) => {
await this.startDaemon();

return new Promise<object>(async (resolve, reject) => {
try {
const response = await this.daemon.delete(
`${this.baseUrl}${path}`,
'',
headers,
);

resolve(response.json);
} catch (error) {
reject(error);
}
});
};

public post: (
path: string,
body: object,
Expand Down

0 comments on commit c8fcec3

Please sign in to comment.