Skip to content

Commit

Permalink
Corrections of reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Salim-belkhir committed Dec 23, 2024
1 parent 12e9475 commit 7d18f34
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
7 changes: 3 additions & 4 deletions libs/coin-framework/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type BlockInfo = {
height: number;
hash: string;
time: Date;
hash?: string;
time?: Date;
};

export type Operation = {
Expand All @@ -10,8 +10,7 @@ export type Operation = {
type: string;
value: bigint;
fee: bigint;
blockHeight: number;
block?: BlockInfo;
block: BlockInfo;
senders: string[];
recipients: string[];
date: Date;
Expand Down
10 changes: 8 additions & 2 deletions libs/coin-modules/coin-polkadot/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export type Operation = {
type: string;
value: bigint;
fee: bigint;
blockHeight: number;
block: {
height: number;
hash?: string;
time?: Date;
};
senders: string[];
recipients: string[];
date: Date;
Expand Down Expand Up @@ -43,7 +47,9 @@ const convertToCoreOperation = (address: string) => (operation: PolkadotOperatio
type,
value: BigInt(value.toString()),
fee: BigInt(fee.toString()),
blockHeight: blockHeight ?? 0,
block: {
height: blockHeight ?? 0,
},
senders,
recipients,
date,
Expand Down
8 changes: 3 additions & 5 deletions libs/coin-modules/coin-stellar/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export type Operation = {
type: string;
value: bigint;
fee: bigint;
blockHeight: number;
block?: {
hash: string;
time: Date;
block: {
hash?: string;
time?: Date;
height: number;
};
senders: string[];
Expand Down Expand Up @@ -46,7 +45,6 @@ const convertToCoreOperation = (address: string) => (operation: StellarOperation
type: operation.type,
value: BigInt(operation.value.toString()),
fee: BigInt(operation.fee.toString()),
blockHeight: operation.blockHeight!,
block: {
hash: operation.blockHash!,
time: operation.extra.blockTime,
Expand Down
18 changes: 10 additions & 8 deletions libs/coin-modules/coin-stellar/src/network/horizon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ Horizon.AxiosClient.interceptors.request.use(config => {
return config;
});

// This function allows to fix the URL, because the url returned by the Stellar SDK is not the correct one.
// It replaces the host of the URL returned with the host of the explorer.
function useConfigHost(url: string): string {
const u = new URL(url);
u.host = new URL(coinConfig.getCoinConfig().explorer.url).host;
return u.toString();
}

Horizon.AxiosClient.interceptors.response.use(response => {
if (coinConfig.getCoinConfig().enableNetworkLogs) {
const { url, method } = response.config;
Expand All @@ -74,21 +82,15 @@ Horizon.AxiosClient.interceptors.response.use(response => {
// included in server responses points to the node itself instead of our reverse proxy...
// (https://github.com/stellar/js-stellar-sdk/issues/637)

function fixURL(url: string): string {
const u = new URL(url);
u.host = new URL(coinConfig.getCoinConfig().explorer.url).host;
return u.toString();
}

const next_href = response?.data?._links?.next?.href;

if (next_href) {
response.data._links.next.href = fixURL(next_href);
response.data._links.next.href = useConfigHost(next_href);
}

response?.data?._embedded?.records?.forEach((r: any) => {
const href = r.transaction?._links?.ledger?.href;
if (href) r.transaction._links.ledger.href = fixURL(href);
if (href) r.transaction._links.ledger.href = useConfigHost(href);
});

return response;
Expand Down
8 changes: 3 additions & 5 deletions libs/coin-modules/coin-tezos/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export type Operation = {
type: string;
value: bigint;
fee: bigint;
blockHeight: number;
block?: {
hash: string;
block: {
hash?: string;
height: number;
time: Date;
time?: Date;
};
senders: string[];
recipients: string[];
Expand Down Expand Up @@ -58,7 +57,6 @@ function convertOperation(
value: BigInt(amount),
// storageFee for transaction is always present
fee: BigInt(storageFee ?? 0),
blockHeight: block.level,
block: {
hash: block.hash,
height: block.level,
Expand Down
3 changes: 0 additions & 3 deletions libs/coin-modules/coin-xrp/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe("listOperations", () => {
type: "Payment",
value: expectedValue,
fee: BigInt(10),
blockHeight: 1,
block: {
hash: "HASH_VALUE_BLOCK",
height: 1,
Expand All @@ -129,7 +128,6 @@ describe("listOperations", () => {
type: "Payment",
value: expectedValue,
fee: BigInt(10),
blockHeight: 1,
block: {
hash: "HASH_VALUE_BLOCK",
height: 1,
Expand All @@ -149,7 +147,6 @@ describe("listOperations", () => {
type: "Payment",
value: expectedValue,
fee: BigInt(10),
blockHeight: 1,
block: {
hash: "HASH_VALUE_BLOCK",
height: 1,
Expand Down
4 changes: 2 additions & 2 deletions libs/coin-modules/coin-xrp/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ async function operations(
const [ops, index] = await listOperations(address, { limit, startAt: start ?? 0 });
return [
ops.map(op => {
const { simpleType, blockHash, blockTime, ...rest } = op;
const { simpleType, blockHash, blockTime, blockHeight, ...rest } = op;
return {
...rest,
block: {
height: rest.blockHeight,
height: blockHeight,
hash: blockHash,
time: blockTime,
},
Expand Down

0 comments on commit 7d18f34

Please sign in to comment.