UNPKG

@firefly-exchange/firefly-client

Version:

The Firefly Client Library allows traders to sign, create, retrieve and listen to orders on Firefly Exchange.

62 lines 3.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.APIErrorMessages = exports.VerificationStatus = exports.SuccessMessages = exports.TransformToResponseSchema = exports.handleResponse = void 0; const library_1 = require("@firefly-exchange/library"); const eth_rpc_errors_1 = require("eth-rpc-errors"); const handleResponse = (response, ok) => { const mutatedResponse = { ok, data: (0, library_1.getValue)(response.data, "originalError.transaction", response.data), message: (0, library_1.getValue)(response.data, "originalError.reason", response.message), code: (0, library_1.getValue)(response.data, "originalError.code", response.code), stack: response.message, }; return mutatedResponse; }; exports.handleResponse = handleResponse; const TransformToResponseSchema = (contactCall, successMessage) => __awaiter(void 0, void 0, void 0, function* () { try { const result = yield contactCall(); return (0, exports.handleResponse)({ data: result, message: successMessage, code: 200, }, true); } catch (error) { return (0, exports.handleResponse)(Object.assign({}, (0, eth_rpc_errors_1.serializeError)(error)), false); } }); exports.TransformToResponseSchema = TransformToResponseSchema; var SuccessMessages; (function (SuccessMessages) { SuccessMessages["adjustLeverage"] = "Leverage Adjusted to {leverage}x."; SuccessMessages["adjustMarginAdd"] = "{amount} USDC margin Added to position."; SuccessMessages["adjustMarginRemove"] = "{amount} USDC margin Removed from position."; SuccessMessages["withdrawMargin"] = "{amount} USDC withdrawn."; SuccessMessages["approveUSDC"] = "{amount} USDC approved."; SuccessMessages["depositToBank"] = "{amount} USDC deposited to Margin Bank."; SuccessMessages["setSubAccounts"] = "This {address} is successfully {status} as a subaccount"; SuccessMessages["positionClosed"] = "Position is closed against this {address}"; })(SuccessMessages = exports.SuccessMessages || (exports.SuccessMessages = {})); var VerificationStatus; (function (VerificationStatus) { VerificationStatus["Success"] = "success"; VerificationStatus["Restricted"] = "restricted"; VerificationStatus["Blocked"] = "blocked"; })(VerificationStatus = exports.VerificationStatus || (exports.VerificationStatus = {})); var APIErrorMessages; (function (APIErrorMessages) { // eslint-disable-next-line max-len APIErrorMessages["restrictedUser"] = "This wallet address has been identified as high-risk. You will not be able to open any new positions or deposit funds on the exchange. You may, however, close out any open positions and withdraw free collateral"; })(APIErrorMessages = exports.APIErrorMessages || (exports.APIErrorMessages = {})); //# sourceMappingURL=contractErrorHandling.service.js.map