@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
84 lines • 4.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockServer = exports.TRONGRID_BASE_URL_MOCKED = void 0;
const msw_1 = require("msw");
const node_1 = require("msw/node");
const fetchAccount_fixture_json_1 = __importDefault(require("./fixtures/fetchAccount.fixture.json"));
const fetchTronAccountTxs_fixture_json_1 = __importDefault(require("./fixtures/fetchTronAccountTxs.fixture.json"));
const fetchTronAccountTxsTrc20_fixture_json_1 = __importDefault(require("./fixtures/fetchTronAccountTxsTrc20.fixture.json"));
const getAccountResource_fixture_json_1 = __importDefault(require("./fixtures/getAccountResource.fixture.json"));
const getTransactionInfoById_fixture_json_1 = __importDefault(require("./fixtures/getTransactionInfoById.fixture.json"));
// This URL can also be find in the fixture with pagination, so there can be a consistency with paginated requests.
exports.TRONGRID_BASE_URL_MOCKED = "https://api.mock.trongrid.io";
const handlers = [
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/v1/accounts/:address`, ({ params }) => {
const address = typeof params.address === "string" ? params.address : (params.address?.[0] ?? "");
const response = fetchAccount_fixture_json_1.default[address];
if (!response) {
return new msw_1.HttpResponse(null, { status: 404 });
}
return msw_1.HttpResponse.json(response);
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/v1/accounts/:address/transactions`, ({ params, request }) => {
const address = typeof params.address === "string" ? params.address : (params.address?.[0] ?? "");
const response = fetchTronAccountTxs_fixture_json_1.default[address];
const url = new URL(request.url);
const fingerprint = url.searchParams.get("fingerprint") ?? "";
if (!response) {
return new msw_1.HttpResponse(null, { status: 404 });
}
return msw_1.HttpResponse.json(response[fingerprint]);
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/v1/accounts/:address/transactions/trc20`, ({ params }) => {
const address = typeof params.address === "string" ? params.address : (params.address?.[0] ?? "");
const response = fetchTronAccountTxsTrc20_fixture_json_1.default[address];
if (!response) {
return new msw_1.HttpResponse(null, { status: 404 });
}
return msw_1.HttpResponse.json(response);
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/wallet/getnowblock`, () => {
return msw_1.HttpResponse.json({
blockID: "00000000042676341cfaf5c785ad75a90b88e9f75407e909decdcb857afed099",
block_header: {
raw_data: {
number: 69629492,
txTrieRoot: "95ea9c4c04a4d0145b9a1d9658636f0ee1084d3026ac5a644a7ababfd2a3276a",
witness_address: "41d376d829440505ea13c9d1c455317d51b62e4ab6",
parentHash: "00000000042676336ee51411bd47bc68df4b2a89f0c1cc9347b98d70d00a5640",
version: 31,
timestamp: 1739540559000,
},
witness_signature: "26f2fcb0a80c2731a00387ba753e162e9161db1bd3ab4ec61eb4d4b70d5983fc00f6edb117d4fb1d0624ac728da3b1f60e011b76fa95a490455ffb1c42593ea101",
},
});
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/wallet/gettransactioninfobyid`, ({ request }) => {
const url = new URL(request.url);
const txID = url.searchParams.get("value");
const response = getTransactionInfoById_fixture_json_1.default[txID];
if (!response) {
return new msw_1.HttpResponse(null, { status: 404 });
}
return msw_1.HttpResponse.json(response);
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/wallet/getaccountresource*`, ({ request }) => {
const url = new URL(request.url);
const address = url.searchParams.get("address");
const response = getAccountResource_fixture_json_1.default[address];
if (!response) {
return new msw_1.HttpResponse(null, { status: 404 });
}
return msw_1.HttpResponse.json(response);
}),
msw_1.http.get(`${exports.TRONGRID_BASE_URL_MOCKED}/wallet/getReward*`, () => {
return msw_1.HttpResponse.json({
reward: 1802573,
});
}),
];
exports.mockServer = (0, node_1.setupServer)(...handlers);
//# sourceMappingURL=index.mock.js.map