Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/main.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import {
allowExternalRequest
} from "./main_dev/externalRequests";
import { setupProxy } from "./main_dev/proxy";
import {
getAllVspsInfo,
getVSPInfo,
getVSPTicketStatus
} from "./main_dev/vspRequests";
import {
getDaemonInfo,
cleanShutdown,
Expand Down Expand Up @@ -471,6 +476,12 @@ handle("check-daemon", getBlockChainInfo);

handle("daemon-getinfo", getDaemonInfo);

handle("get-all-vsps-info", getAllVspsInfo);

handle("get-vsp-info", getVSPInfo);

handle("get-vsp-ticket-status", getVSPTicketStatus);

handle("clean-shutdown", () =>
cleanShutdown(mainWindow, app, GetDcrdPID(), GetDcrwPID())
);
Expand Down
56 changes: 56 additions & 0 deletions app/main_dev/vspRequests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { getJSON, postJSON } from "helpers/fetch";

const URL_BASE = "https://api.decred.org";

const GET = (path, vspClientSig) => {
const config = vspClientSig
? {
headers: {
"VSP-Client-Signature": vspClientSig
}
}
: {};
return getJSON(path, config);
};

const POST = (path, vspClientSig, json) => {
const config = vspClientSig
? {
headers: {
"VSP-Client-Signature": vspClientSig
}
}
: {};
// This json request is strigfied at the call which is making it.
return postJSON(path, json, config);
};

const pickResponse = (res) => ({ data: res.data, status: res.status });

// getAllVspsInfo gets vsp info from vsps v1 and v2.
// This can be removed after stopping to support them.
export const getAllVspsInfo = async () => {
const response = await GET(URL_BASE + "/?c=vsp");
const hosts = Object.keys(response.data);
return hosts.reduce((availableVsps, host) => {
const vspData = response.data[host];
if (vspData.closed) return availableVsps;
// call from /?c=vsp does not include its protocol, becaise when calling
// from dcrwallet, it is not used. Therefore, we need to add them.
availableVsps.push({
host,
vspData
});
return availableVsps;
}, []);
};

export const getVSPInfo = async (host) => ({
...pickResponse(await GET(host + "/api/v3/vspinfo")),
host
});

export const getVSPTicketStatus = async ({ host, sig, json }) => ({
...pickResponse(await POST(host + "/api/v3/ticketstatus", sig, json)),
host
});
68 changes: 0 additions & 68 deletions app/middleware/vspapi.js

This file was deleted.

26 changes: 9 additions & 17 deletions app/wallet/vsp.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import * as api from "../middleware/vspapi";
import { withLog as log, withLogNoData } from "./index";
import * as cfg from "../config";
import * as cfgConstants from "constants/config";
import { ipcRenderer } from "electron";
import { invoke } from "helpers/electronRenderer";
import { reloadAllowedExternalRequests } from "./daemon";
import { allowVSPHost as confDialogAllowVSPHost } from "./confirmationDialog";

const promisifyReqLogNoData = (fnName, Req) =>
withLogNoData(
(...args) =>
new Promise((ok, fail) =>
Req(...args, (res, err) => (err ? fail(err) : ok(res)))
),
fnName
);

export const getVSPInfo = promisifyReqLogNoData("getVSPInfo", api.getVSPInfo);
export const getVSPTicketStatus = promisifyReqLogNoData(
"getVSPTicketStatus",
api.getVSPTicketStatus
export const getVSPInfo = withLogNoData(
(host) => invoke("get-vsp-info", host),
"getVSPInfo"
);
export const getVSPTicketStatus = withLogNoData(
(req) => invoke("get-vsp-ticket-status", req),
"getVSPTicketStatus"
);

// addAllowedVSPsInCfg modifies the config file to allow the given VSP hosts
Expand All @@ -37,9 +31,7 @@ const addAllowedVSPsInCfg = (hosts) => {
};

export const getAllVSPs = withLogNoData(async () => {
const res = await new Promise((ok, fail) =>
api.getAllVspsInfo((res, err) => (err ? fail(err) : ok(res)))
);
const res = await invoke("get-all-vsps-info");

// Allow access to all VSPs returned by the official VSP listing endpoint.
// This is less then ideal because this endpoint might eventually return
Expand Down
Loading