New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@elevenyellow.com/switchain-api-client

Package Overview
Dependencies
Maintainers
5
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elevenyellow.com/switchain-api-client - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

3

package.json
{
"name": "@elevenyellow.com/switchain-api-client",
"version": "0.2.0",
"version": "1.0.0",
"description": "client module to access switchains's api",

@@ -26,2 +26,3 @@ "main": "index.js",

"dependencies": {
"chai-as-promised": "^7.1.1",
"request": "^2.87.0",

@@ -28,0 +29,0 @@ "request-promise": "^4.2.2"

@@ -5,3 +5,3 @@ const request = require("request-promise");

exports.init = function({ apiKey }) {
function init({ apiKey }) {
return {

@@ -22,30 +22,40 @@ getMarketInfo: () => getMarketInfo({ apiKey }),

};
};
}
exports.getMarketInfo = getMarketInfo = async function({ apiKey }) {
async function getMarketInfo({ apiKey }) {
const uri = `${apiUrl}marketinfo/`;
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
json: true
});
try {
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
json: true
});
// console.log("SwitchainApi.getOffer", { response });
// console.log("SwitchainApi.getOffer", { response });
return { info: response, error: null };
};
return response;
} catch (error) {
console.log(`switchainApiClient.getMarketInfo.error: ${error}`);
throw error;
}
}
exports.getOffer = getOffer = async function({ pair, apiKey }) {
async function getOffer({ pair, apiKey }) {
const uri = `${apiUrl}offer/`;
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
qs: { pair },
json: true
});
try {
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
qs: { pair },
json: true
});
return { offer: response, error: null };
};
return response;
} catch (error) {
console.log(`switchainApiClient.getOffer.error: ${error}`);
throw error;
}
}
exports.postOrder = postOrder = async function({
async function postOrder({
toAddress,

@@ -59,30 +69,42 @@ refundAddress,

const uri = `${apiUrl}order/`;
const response = await request({
uri,
method: "POST",
body: {
toAddress,
refundAddress,
pair,
fromAmount,
signature
},
json: true,
headers: { Authorization: `Bearer ${apiKey}` }
});
try {
const response = await request({
uri,
method: "POST",
body: {
toAddress,
refundAddress,
pair,
fromAmount,
signature
},
json: true,
headers: { Authorization: `Bearer ${apiKey}` }
});
// console.log({ response });
// console.log({ response });
return { order: response, error: null };
};
return response;
} catch (error) {
console.log(`switchainApiClient.postOrder.error: ${error}`);
throw error;
}
}
exports.getOrderStatus = getOrderStatus = async function({ orderId, apiKey }) {
async function getOrderStatus({ orderId, apiKey }) {
const uri = `${apiUrl}order/${orderId}`;
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
json: true
});
try {
const response = await request({
uri,
headers: { Authorization: `Bearer ${apiKey}` },
json: true
});
return { status: response, error: null };
};
return response;
} catch (error) {
console.log(`switchainApiClient.getOrderStatus.error: ${error}`);
throw error;
}
}
module.exports = { init, getMarketInfo, getOffer, postOrder, getOrderStatus };

@@ -1,4 +0,15 @@

const { assert, expect } = require("chai");
const { getOffer, postOrder, getOrderStatus, init } = require("../src");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
const { assert, expect } = chai;
const {
getMarketInfo,
getOffer,
postOrder,
getOrderStatus,
init
} = require("../src");
let apiKey;

@@ -19,20 +30,27 @@ try {

const result = await getMarketInfo({ apiKey });
console.log({ result });
expect(result.info).to.be.an("array");
// console.log({ result });
expect(result).to.be.an("array");
});
});
describe("getOffer", async function() {
it("It gets an offer", async function() {
it("It gets an offer for ETH-DAI", async function() {
const pair = "ETH-DAI";
const result = await getOffer({ pair, apiKey });
// console.log({ result });
expect(result.offer.pair).to.be.equal(pair);
expect(result.offer.signature).to.be.a("string");
expect(result.offer.quote).to.be.a("string");
expect(result.offer.maxLimit).to.be.a("string");
expect(result.offer.expiryTs).to.be.a("number");
expect(result.pair).to.be.equal(pair);
expect(result.signature).to.be.a("string");
expect(result.quote).to.be.a("string");
expect(result.maxLimit).to.be.a("string");
expect(result.expiryTs).to.be.a("number");
});
it("It gets an offer for BTC-ETH", async function() {
const pair = "BTC-ETH";
// const result = await getOffer({ pair, apiKey });
// console.log({ result });
expect(getOffer({ pair, apiKey })).to.be.rejected;
});
});
describe("postOrder/getOrderStatus", async function() {
xit("It posts an order and checks the status", async function() {
it("It posts an order and checks the status", async function() {
this.timeout(20000);

@@ -42,3 +60,3 @@ const pair = "ETH-DAI";

const { signature } = offerResponse.offer;
const { signature } = offerResponse;
const toAddress = "0x668bf158d4A34A77145d2084C70a5B98b4280eDD";

@@ -58,13 +76,13 @@ const refundAddress = "0xb45166124a842ce57e1a86b7a975bb4effae1494";

expect(orderResponse.order.orderId).to.be.a("string");
expect(orderResponse.order.rate).to.be.a("string");
expect(orderResponse.order.exchangeAddress).to.be.a("string");
expect(orderResponse.order.toAddress).to.be.equal(toAddress);
expect(orderResponse.order.refundAddress).to.be.equal(refundAddress);
expect(orderResponse.order.fromAmount).to.be.equal(fromAmount);
expect(orderResponse.orderId).to.be.a("string");
expect(orderResponse.rate).to.be.a("string");
expect(orderResponse.exchangeAddress).to.be.a("string");
expect(orderResponse.toAddress).to.be.equal(toAddress);
expect(orderResponse.refundAddress).to.be.equal(refundAddress);
expect(orderResponse.fromAmount).to.be.equal(fromAmount);
const { orderId } = orderResponse.order;
const { orderId } = orderResponse;
const statusResponse = await getOrderStatus({ orderId, apiKey });
// console.log({ statusResponse });
expect(statusResponse.status.status).to.be.equal("waiting");
expect(statusResponse.status).to.be.equal("waiting");
});

@@ -78,9 +96,9 @@ });

// console.log({ result });
expect(result.offer.pair).to.be.equal(pair);
expect(result.offer.signature).to.be.a("string");
expect(result.offer.quote).to.be.a("string");
expect(result.offer.maxLimit).to.be.a("string");
expect(result.offer.expiryTs).to.be.a("number");
expect(result.pair).to.be.equal(pair);
expect(result.signature).to.be.a("string");
expect(result.quote).to.be.a("string");
expect(result.maxLimit).to.be.a("string");
expect(result.expiryTs).to.be.a("number");
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc