@yoroi/exchange
Version:
The Exchange package of Yoroi SDK
50 lines (49 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.encryptusApiGetBaseUrl = exports.encryptusApiConfig = void 0;
var _common = require("@yoroi/common");
var _immer = require("immer");
var _zod = require("zod");
var _getValidationError = require("../../helpers/get-validation-error");
const initialDeps = (0, _immer.freeze)({
request: _common.fetchData
}, true);
const encryptusApiGetBaseUrl = function (_ref) {
let {
isProduction
} = _ref;
let {
request
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : initialDeps;
return async fetcherConfig => {
const config = {
url: encryptusApiConfig[isProduction ? 'production' : 'sandbox'].getBaseUrl
};
try {
const response = await request(config, fetcherConfig);
if ((0, _common.isLeft)(response)) throw (0, _common.getApiError)(response.error);
const parsedResponse = EncryptusApiResponseSchema.parse(response.value.data);
return parsedResponse.data.link;
} catch (error) {
throw (0, _getValidationError.getValidationError)(error);
}
};
};
exports.encryptusApiGetBaseUrl = encryptusApiGetBaseUrl;
const EncryptusApiResponseSchema = _zod.z.object({
data: _zod.z.object({
link: _zod.z.string()
})
});
const encryptusApiConfig = (0, _immer.freeze)({
production: {
getBaseUrl: 'https://api.yoroiwallet.com/api/v2/encryptus/payoutlink'
},
sandbox: {
getBaseUrl: 'https://preprod-backend.yoroiwallet.com/api/v2/encryptus/payoutlink'
}
}, true);
exports.encryptusApiConfig = encryptusApiConfig;
//# sourceMappingURL=api.js.map