fmt: apply prettier to frontend JS/TS/CSS/JSON files
Initial prettier pass with tabWidth=4.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// API client for address management
|
||||
|
||||
import { getAuthHeaders, getAuthHeadersSimple } from './authHeaders';
|
||||
import { API_BASE } from './config';
|
||||
import { getAuthHeaders, getAuthHeadersSimple } from "./authHeaders";
|
||||
import { API_BASE } from "./config";
|
||||
|
||||
/**
|
||||
* Create a new blockchain address to monitor
|
||||
@@ -11,35 +11,37 @@ import { API_BASE } from './config';
|
||||
* @returns {Promise<Object>} Created address with id and metadata
|
||||
*/
|
||||
export async function createAddress(data) {
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/addresses`, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = 'Failed to create address';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
// Handle network errors
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/addresses`, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = "Failed to create address";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
// Handle network errors
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,33 +49,35 @@ export async function createAddress(data) {
|
||||
* @returns {Promise<Array>} List of all addresses
|
||||
*/
|
||||
export async function getAddresses() {
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/addresses`, {
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = 'Failed to fetch addresses';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
// Handle network errors or JSON parse errors
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/addresses`, {
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = "Failed to fetch addresses";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
// Handle network errors or JSON parse errors
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,31 +86,32 @@ export async function getAddresses() {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function deleteAddress(addressId) {
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/addresses/${addressId}`, {
|
||||
method: 'DELETE',
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok && response.status !== 204) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = 'Failed to delete address';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
} catch (error) {
|
||||
// Handle network errors
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/addresses/${addressId}`, {
|
||||
method: "DELETE",
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
if (!response.ok && response.status !== 204) {
|
||||
// Try to parse error response, but handle if it's not JSON
|
||||
let errorMessage = "Failed to delete address";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
// If JSON parse fails, use status text
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
} catch (error) {
|
||||
// Handle network errors
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
// API client for alert event history
|
||||
|
||||
import { getAuthHeadersSimple } from './authHeaders';
|
||||
import { API_BASE } from './config';
|
||||
import { getAuthHeadersSimple } from "./authHeaders";
|
||||
import { API_BASE } from "./config";
|
||||
|
||||
/**
|
||||
* Get all alert events (history)
|
||||
* @returns {Promise<Array>} List of alert events, sorted by most recent first
|
||||
*/
|
||||
export async function getAlertEvents() {
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/alert-events`, {
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to fetch alert events';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/alert-events`, {
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to fetch alert events";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// API client for alert rule management
|
||||
|
||||
import { getAuthHeaders, getAuthHeadersSimple } from './authHeaders';
|
||||
import { API_BASE } from './config';
|
||||
import { getAuthHeaders, getAuthHeadersSimple } from "./authHeaders";
|
||||
import { API_BASE } from "./config";
|
||||
|
||||
/**
|
||||
* Alert types supported by the system
|
||||
*/
|
||||
export const ALERT_TYPES = {
|
||||
INCOMING_TX: 'incoming_tx',
|
||||
OUTGOING_TX: 'outgoing_tx',
|
||||
LARGE_TRANSFER: 'large_transfer',
|
||||
BALANCE_BELOW: 'balance_below'
|
||||
INCOMING_TX: "incoming_tx",
|
||||
OUTGOING_TX: "outgoing_tx",
|
||||
LARGE_TRANSFER: "large_transfer",
|
||||
BALANCE_BELOW: "balance_below",
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -22,32 +22,37 @@ export const ALERT_TYPES = {
|
||||
* @returns {Promise<Object>} Created alert rule
|
||||
*/
|
||||
export async function createAlert(addressId, data) {
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/addresses/${addressId}/alerts`, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to create alert rule';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(
|
||||
`${API_BASE}/addresses/${addressId}/alerts`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to create alert rule";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,30 +61,35 @@ export async function createAlert(addressId, data) {
|
||||
* @returns {Promise<Array>} List of alert rules
|
||||
*/
|
||||
export async function getAlerts(addressId) {
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/addresses/${addressId}/alerts`, {
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to fetch alert rules';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(
|
||||
`${API_BASE}/addresses/${addressId}/alerts`,
|
||||
{
|
||||
headers: headers,
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to fetch alert rules";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,32 +99,34 @@ export async function getAlerts(addressId) {
|
||||
* @returns {Promise<Object>} Updated alert rule
|
||||
*/
|
||||
export async function updateAlertStatus(alertId, enabled) {
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/alerts/${alertId}`, {
|
||||
method: 'PATCH',
|
||||
headers: headers,
|
||||
body: JSON.stringify({ enabled })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to update alert rule';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/alerts/${alertId}`, {
|
||||
method: "PATCH",
|
||||
headers: headers,
|
||||
body: JSON.stringify({ enabled }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to update alert rule";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,27 +135,29 @@ export async function updateAlertStatus(alertId, enabled) {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function deleteAlert(alertId) {
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/alerts/${alertId}`, {
|
||||
method: 'DELETE',
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok && response.status !== 204) {
|
||||
let errorMessage = 'Failed to delete alert rule';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
try {
|
||||
const headers = await getAuthHeadersSimple();
|
||||
const response = await fetch(`${API_BASE}/alerts/${alertId}`, {
|
||||
method: "DELETE",
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
if (!response.ok && response.status !== 204) {
|
||||
let errorMessage = "Failed to delete alert rule";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/**
|
||||
* Auth Headers Helper
|
||||
*
|
||||
*
|
||||
* Provides authentication headers for API calls
|
||||
* Includes Firebase ID token in Authorization header
|
||||
*/
|
||||
|
||||
import { auth } from '../firebase/config';
|
||||
import { auth } from "../firebase/config";
|
||||
|
||||
/**
|
||||
* Get headers with authentication token
|
||||
* @returns {Promise<Object>} Headers object with Authorization
|
||||
*/
|
||||
export async function getAuthHeaders() {
|
||||
const currentUser = auth.currentUser;
|
||||
|
||||
if (!currentUser) {
|
||||
throw new Error('No authenticated user');
|
||||
}
|
||||
const currentUser = auth.currentUser;
|
||||
|
||||
// Get Firebase ID token
|
||||
const token = await currentUser.getIdToken();
|
||||
if (!currentUser) {
|
||||
throw new Error("No authenticated user");
|
||||
}
|
||||
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
};
|
||||
// Get Firebase ID token
|
||||
const token = await currentUser.getIdToken();
|
||||
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,16 +32,15 @@ export async function getAuthHeaders() {
|
||||
* @returns {Promise<Object>} Headers object with Authorization
|
||||
*/
|
||||
export async function getAuthHeadersSimple() {
|
||||
const currentUser = auth.currentUser;
|
||||
|
||||
if (!currentUser) {
|
||||
throw new Error('No authenticated user');
|
||||
}
|
||||
const currentUser = auth.currentUser;
|
||||
|
||||
const token = await currentUser.getIdToken();
|
||||
if (!currentUser) {
|
||||
throw new Error("No authenticated user");
|
||||
}
|
||||
|
||||
return {
|
||||
'Authorization': `Bearer ${token}`
|
||||
};
|
||||
const token = await currentUser.getIdToken();
|
||||
|
||||
return {
|
||||
Authorization: `Bearer ${token}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const API_BASE = import.meta.env.VITE_API_BASE || '/v1';
|
||||
export const API_BASE = import.meta.env.VITE_API_BASE || "/v1";
|
||||
|
||||
@@ -1,37 +1,39 @@
|
||||
// API client for notification configuration
|
||||
|
||||
import { getAuthHeaders } from './authHeaders';
|
||||
import { API_BASE } from './config';
|
||||
import { getAuthHeaders } from "./authHeaders";
|
||||
import { API_BASE } from "./config";
|
||||
|
||||
/**
|
||||
* Get notification configuration for current user
|
||||
* @returns {Promise<Object>} Notification config
|
||||
*/
|
||||
export async function getNotificationConfig() {
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/notification-config`, {
|
||||
headers: headers
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to fetch notification config';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/notification-config`, {
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to fetch notification config";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,32 +46,34 @@ export async function getNotificationConfig() {
|
||||
* @returns {Promise<Object>} Updated config
|
||||
*/
|
||||
export async function updateNotificationConfig(config) {
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/notification-config`, {
|
||||
method: 'PUT',
|
||||
headers: headers,
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = 'Failed to update notification config';
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
try {
|
||||
const headers = await getAuthHeaders();
|
||||
const response = await fetch(`${API_BASE}/notification-config`, {
|
||||
method: "PUT",
|
||||
headers: headers,
|
||||
body: JSON.stringify(config),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = "Failed to update notification config";
|
||||
try {
|
||||
const error = await response.json();
|
||||
errorMessage = error.message || errorMessage;
|
||||
} catch {
|
||||
errorMessage = `Server error: ${response.status} ${response.statusText}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes("fetch")) {
|
||||
throw new Error(
|
||||
"Cannot connect to server. Is the backend running?",
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error.message.includes('fetch')) {
|
||||
throw new Error('Cannot connect to server. Is the backend running?');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,21 +83,21 @@ export async function updateNotificationConfig(config) {
|
||||
* @returns {Promise<boolean>} True if test successful
|
||||
*/
|
||||
export async function testDiscordWebhook(webhookUrl) {
|
||||
try {
|
||||
const payload = {
|
||||
content: 'Koin Ping test notification - Your Discord webhook is configured correctly!',
|
||||
};
|
||||
try {
|
||||
const payload = {
|
||||
content:
|
||||
"Koin Ping test notification - Your Discord webhook is configured correctly!",
|
||||
};
|
||||
|
||||
const response = await fetch(webhookUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const response = await fetch(webhookUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
return response.ok;
|
||||
} catch (error) {
|
||||
console.error('Discord webhook test failed:', error);
|
||||
return false;
|
||||
}
|
||||
return response.ok;
|
||||
} catch (error) {
|
||||
console.error("Discord webhook test failed:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// API client for system status
|
||||
|
||||
import { API_BASE } from './config';
|
||||
import { API_BASE } from "./config";
|
||||
|
||||
/**
|
||||
* Get system status including latest processed block and health
|
||||
* @returns {Promise<Object>} System status
|
||||
*/
|
||||
export async function getSystemStatus() {
|
||||
const response = await fetch(`${API_BASE}/status`);
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || 'Failed to fetch system status');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
const response = await fetch(`${API_BASE}/status`);
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || "Failed to fetch system status");
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user