mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-07-22 07:48:28 +00:00
fix: remove dead code (#197)
Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
/* import _AsyncStorage from "@react-native-async-storage/async-storage" */
|
||||
|
||||
/**
|
||||
* Loads a string from storage.
|
||||
*
|
||||
* @param key The key to fetch.
|
||||
*/
|
||||
/* const loadString = async function (key: string): Promise<string | null> {
|
||||
try {
|
||||
return await _AsyncStorage.getItem(key)
|
||||
} catch {
|
||||
// not sure why this would fail... even reading the RN docs I'm unclear
|
||||
return null
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Saves a string to storage.
|
||||
*
|
||||
* @param key The key to fetch.
|
||||
* @param value The value to store.
|
||||
*/
|
||||
/* const saveString = async function (key: string, value: string): Promise<boolean> {
|
||||
try {
|
||||
await _AsyncStorage.setItem(key, value)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Loads something from storage and runs it thru JSON.parse.
|
||||
*
|
||||
* @param key The key to fetch.
|
||||
*/
|
||||
/* const load = async function (key: string): Promise<any | null> {
|
||||
try {
|
||||
const almostThere = await _AsyncStorage.getItem(key)
|
||||
return JSON.parse(almostThere as string)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Saves an object to storage.
|
||||
*
|
||||
* @param key The key to fetch.
|
||||
* @param value The value to store.
|
||||
*/
|
||||
/* const save = async function (key: string, value: any): Promise<boolean> {
|
||||
try {
|
||||
await _AsyncStorage.setItem(key, JSON.stringify(value))
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Removes something from storage.
|
||||
*
|
||||
* @param key The key to kill.
|
||||
*/
|
||||
/* const remove = async function (key: string): Promise<void> {
|
||||
try {
|
||||
await _AsyncStorage.removeItem(key)
|
||||
} catch {}
|
||||
} */
|
||||
|
||||
/**
|
||||
* Burn it all to the ground.
|
||||
*/
|
||||
/* const cleanAll = async function (): Promise<void> {
|
||||
try {
|
||||
await _AsyncStorage.clear()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export const AsyncStorage = {
|
||||
loadString,
|
||||
saveString,
|
||||
load,
|
||||
save,
|
||||
remove,
|
||||
cleanAll
|
||||
} */
|
||||
@@ -1,129 +0,0 @@
|
||||
// import Tor, { RequestMethod, TorType } from 'react-native-tor'
|
||||
import AppError, { Err } from '../utils/AppError';
|
||||
import { log } from './logService';
|
||||
|
||||
/* let _tor: TorType
|
||||
let _globalRequestOptions: Partial<RequestOptions> = {};
|
||||
|
||||
const getInstance = function () {
|
||||
if (!_tor) {
|
||||
_tor = Tor()
|
||||
log.trace('Tor initialized')
|
||||
}
|
||||
|
||||
return _tor
|
||||
}
|
||||
|
||||
type RequestArgs = {
|
||||
endpoint: string;
|
||||
requestBody?: Record<string, unknown>;
|
||||
headers?: Record<string, string>;
|
||||
method?: string | RequestMethod,
|
||||
};
|
||||
|
||||
type RequestOptions = RequestArgs & Omit<RequestInit, 'body' | 'headers'>;
|
||||
|
||||
|
||||
const setGlobalRequestOptions = function (options: Partial<RequestOptions>): void {
|
||||
_globalRequestOptions = options;
|
||||
}
|
||||
|
||||
const _request = async function<T>({
|
||||
endpoint,
|
||||
requestBody,
|
||||
headers: requestHeaders,
|
||||
method: requestMethod,
|
||||
...options
|
||||
}: RequestOptions): Promise<Response> {
|
||||
|
||||
const tor = getInstance()
|
||||
|
||||
log.trace('[_request]', 'Starting tor if not yet running')
|
||||
await tor.startIfNotStarted()
|
||||
log.trace('_request', 'Tor daemon started')
|
||||
|
||||
const body = requestBody ? JSON.stringify(requestBody) : undefined;
|
||||
const method = requestMethod ? requestMethod : RequestMethod.GET
|
||||
const headers = {
|
||||
...{ Accept: 'application/json, text/plain' },
|
||||
...(body ? { 'Content-Type': 'application/json' } : undefined),
|
||||
...requestHeaders
|
||||
};
|
||||
|
||||
switch (method.toLowerCase()) {
|
||||
case RequestMethod.GET:
|
||||
log.trace('[GET] tor request', {endpoint})
|
||||
const getResult = await tor.get(endpoint, headers, true);
|
||||
if (getResult.json) {
|
||||
log.trace('[GET] tor response', {response: getResult.json})
|
||||
return getResult.json;
|
||||
}
|
||||
break;
|
||||
case RequestMethod.POST:
|
||||
log.trace('[POST] tor request', {endpoint})
|
||||
const postResult = await tor.post(
|
||||
endpoint,
|
||||
body || '',
|
||||
headers,
|
||||
true
|
||||
);
|
||||
if (postResult.json) {
|
||||
log.trace('[POST] tor response', {response: postResult.json})
|
||||
return postResult.json;
|
||||
}
|
||||
break;
|
||||
case RequestMethod.DELETE:
|
||||
const deleteResult = await tor.delete(endpoint, body, headers, true);
|
||||
if (deleteResult.json) {
|
||||
return deleteResult.json;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Invalid method', {method})
|
||||
}
|
||||
|
||||
const torRequest = async function<T>(options: RequestOptions): Promise<T> {
|
||||
const response = await _request({ ...options, ..._globalRequestOptions });
|
||||
checkResponse(response);
|
||||
return response as T;
|
||||
}
|
||||
|
||||
|
||||
const start = async () => {
|
||||
const tor = getInstance()
|
||||
await tor.startIfNotStarted()
|
||||
}
|
||||
|
||||
|
||||
const stop = async () => {
|
||||
const tor = getInstance()
|
||||
await tor.stopIfRunning()
|
||||
}
|
||||
|
||||
|
||||
const getStatus = async () => {
|
||||
const tor = getInstance()
|
||||
const status = await tor.getDaemonStatus()
|
||||
return status
|
||||
}
|
||||
|
||||
|
||||
const checkResponse = function(data: any) {
|
||||
if (!isObj(data)) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Invalid data', {data})
|
||||
}
|
||||
}
|
||||
|
||||
const isObj = function(v: unknown): v is object {
|
||||
return typeof v === 'object';
|
||||
}
|
||||
|
||||
export const TorDaemon = {
|
||||
start,
|
||||
stop,
|
||||
getStatus,
|
||||
getInstance,
|
||||
torRequest,
|
||||
setGlobalRequestOptions,
|
||||
} */
|
||||
Reference in New Issue
Block a user