mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-07-31 10:38:51 -04:00
feat: cargo project at root
This commit is contained in:
parent
bde04fbd76
commit
8c4531cfd3
493 changed files with 9665 additions and 1795 deletions
61
src-xmr-btc-swap/src-gui/src/renderer/api.ts
Normal file
61
src-xmr-btc-swap/src-gui/src/renderer/api.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { Alert, ExtendedProviderStatus } from 'models/apiModel';
|
||||
|
||||
const API_BASE_URL = 'https://api.unstoppableswap.net';
|
||||
|
||||
export async function fetchProvidersViaHttp(): Promise<
|
||||
ExtendedProviderStatus[]
|
||||
> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/list`);
|
||||
return (await response.json()) as ExtendedProviderStatus[];
|
||||
}
|
||||
|
||||
export async function fetchAlertsViaHttp(): Promise<Alert[]> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/alerts`);
|
||||
return (await response.json()) as Alert[];
|
||||
}
|
||||
|
||||
export async function submitFeedbackViaHttp(
|
||||
body: string,
|
||||
attachedData: string,
|
||||
): Promise<string> {
|
||||
type Response = {
|
||||
feedbackId: string;
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/submit-feedback`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ body, attachedData }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const responseBody = (await response.json()) as Response;
|
||||
|
||||
return responseBody.feedbackId;
|
||||
}
|
||||
|
||||
async function fetchCurrencyUsdPrice(currency: string): Promise<number> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.coingecko.com/api/v3/simple/price?ids=${currency}&vs_currencies=usd`,
|
||||
);
|
||||
const data = await response.json();
|
||||
return data[currency].usd;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching ${currency} price:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchBtcPrice(): Promise<number> {
|
||||
return fetchCurrencyUsdPrice('bitcoin');
|
||||
}
|
||||
|
||||
export async function fetchXmrPrice(): Promise<number> {
|
||||
return fetchCurrencyUsdPrice('monero');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue