Skip to content

Commit

Permalink
fix: getFloatDetails() return type
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-rib committed Dec 22, 2020
1 parent 68c5af2 commit 3395b27
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 65 deletions.
65 changes: 28 additions & 37 deletions src/modules/generic-details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,21 @@ type ServerReturnType<R extends SkybridgeResource, M extends SkybridgeMode> = {
>;
};

type ReturnType<R extends SkybridgeResource, M extends SkybridgeMode> = R extends 'pool'
? Pick<
SkybridgeParams<R, M>,
| 'addressDeposit'
| 'addressReceiving'
| 'amountDeposit'
| 'amountReceiving'
| 'currencyDeposit'
| 'currencyReceiving'
| 'hash'
| 'status'
| 'timestamp'
> & {
txDepositId: SkybridgeParams<R, M>['txDepositId'] | null;
}
: Pick<
SkybridgeParams<R, M>,
| 'addressDeposit'
| 'addressReceiving'
| 'amountDeposit'
| 'amountReceiving'
| 'currencyDeposit'
| 'currencyReceiving'
| 'feeTotal'
| 'feeCurrency'
| 'hash'
| 'status'
| 'timestamp'
> & {
txDepositId: SkybridgeParams<R, M>['txDepositId'] | null;
txReceivingId: SkybridgeParams<R, M>['txReceivingId'] | null;
};
type ReturnType<R extends SkybridgeResource, M extends SkybridgeMode> = Pick<
SkybridgeParams<R, M>,
| 'addressDeposit'
| 'addressReceiving'
| 'amountDeposit'
| 'amountReceiving'
| 'currencyDeposit'
| 'currencyReceiving'
| 'hash'
| 'status'
| 'timestamp'
> & {
txDepositId: SkybridgeParams<R, M>['txDepositId'] | null;
txReceivingId: SkybridgeParams<R, M>['txReceivingId'] | null;
} & (R extends 'pool' ? {} : Pick<SkybridgeParams<R, M>, 'feeTotal' | 'feeCurrency'>);

const bridgeCache = new Map<string, SkybridgeBridge>();

Expand Down Expand Up @@ -125,20 +108,28 @@ export const getDetails = async <R extends SkybridgeResource, M extends Skybridg
throw new Error(`"${hash}" is not a swap, it is a withdrawal.`);
}

return {
const fees =
resource === 'pool'
? {}
: {
feeCurrency:
((result.feeCurrency as any) === 'BTCE' ? 'WBTC' : result.feeCurrency) || null,
feeTotal: result.fee,
};

return ({
...fees,
addressReceiving: result.addressOut,
addressDeposit: result.addressDeposit,
amountDeposit: result.amountIn,
amountReceiving: result.amountOut || null,
// Temporarily fixes API bug where it retuns `BTCE` instead of `WBTC`
currencyDeposit: (result.currencyIn as any) === 'BTCE' ? 'WBTC' : result.currencyIn,
currencyReceiving: (result.currencyOut as any) === 'BTCE' ? 'WBTC' : result.currencyOut,
feeCurrency: ((result.feeCurrency as any) === 'BTCE' ? 'WBTC' : result.feeCurrency) || null,
feeTotal: result.fee || null,
hash: result.hash,
hash: result.hash || undefined,
status: result.status,
txDepositId: result.txIdIn || null,
txReceivingId: result.txIdOut || null,
timestamp: new Date(result.timestamp * 1000),
} as ReturnType<R, M>;
} as unknown) as ReturnType<R, M>;
};
14 changes: 6 additions & 8 deletions src/modules/pool/getFloatDetails/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ import { getFloatDetails } from './';
jest.mock('../../context/buildContext');

it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([
{ hash: 'dniUX39yLjKMPixHawxeyreUYpgaDafFlpP1YN4BK_o=' },
{ hash: 'bWRloGO3ah3p9jJ_MKNZLF6x3Nr4rgp0fh0D5RIYo5E=' },
])('gets float details for %O', async ({ hash }) => {
expect.assertions(1);

const context = await buildContext({ mode: 'test' });
const result = await getFloatDetails({ context, hash });

return expect(result).toMatchObject({
addressReceiving: '0x3F4341a0599f63F444B6f1e0c7C5cAf81b5843Cc',
addressReceiving: '0x3f4341a0599f63f444b6f1e0c7c5caf81b5843cc',
addressDeposit: 'msEKP7ZSma3rQtWSQBBZCiJAvjAaowf2c6',
amountDeposit: '0.00099747',
amountReceiving: null,
amountDeposit: '0.00099019',
amountReceiving: '0.00099019',
currencyDeposit: 'BTC',
currencyReceiving: 'sbBTC',
feeCurrency: null,
feeTotal: null,
hash,
status: 'COMPLETED',
txDepositId: 'd5680247e9a7a1b2551831ec3b4b942970041448d02999a2af8cdd49473681f3',
txDepositId: '1bca4204aed84e083e7f0207b0018e844b8087c5d45158568643c79df268f4ef',
txReceivingId: null,
timestamp: new Date('2020-12-21T09:00:07.000Z'),
timestamp: new Date('2020-12-22T15:51:17.000Z'),
});
});
24 changes: 12 additions & 12 deletions src/modules/swap/getSwapDetails/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ import { getSwapDetails } from './';
jest.mock('../../context/buildContext');

it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([
{ hash: 'D6ffXDodsQevLWS0EX_Od4i120TNvbAdCRAjAouKDXg=' },
{ hash: 'sQmT1Q1RROVwVLxs2wJWa5ZVa49zFIBr-9jC_wJsyqM=' },
])('gets swaps details for %O', async ({ hash }) => {
expect.assertions(1);

const context = await buildContext({ mode: 'test' });
const result = await getSwapDetails({ context, hash });

return expect(result).toMatchObject({
addressReceiving: 'tb1q8hk7wlqgtvdrvtmjll4xtxkpjdf5svtcgmacep',
addressReceiving: '0x3f4341a0599f63f444b6f1e0c7c5caf81b5843cc',
addressDeposit: 'msEKP7ZSma3rQtWSQBBZCiJAvjAaowf2c6',
amountDeposit: '0.00099717',
amountReceiving: '0.00074517',
amountDeposit: '0.00099289',
amountReceiving: '0.0007409',
currencyDeposit: 'BTC',
currencyReceiving: 'BTC',
feeCurrency: 'BTC',
feeTotal: '0.000252',
currencyReceiving: 'WBTC',
feeCurrency: 'WBTC',
feeTotal: '0.00025199',
hash,
status: 'REFUNDED',
txDepositId: 'b025316d9f6f4c1b111f525988ebcdc2ad67a798c0b276ffb9be7e48e8ba814b',
txReceivingId: 'd0b7fae62c5c5ef281fd021eac9da9dbd6340324d642cddb5e76fbc61a995a9a',
timestamp: new Date('2020-12-21T08:31:56.000Z'),
status: 'COMPLETED',
txDepositId: 'e474cb45766526d71a08ad3e31efecb27d4bc17cfed93a9bc864102a4ce6f831',
txReceivingId: '0x18140256bab379b282a152d93effd8ace0301bbefb48d3cd41e8a0d51daab79f',
timestamp: new Date('2020-12-22T15:48:48.000Z'),
});
});

it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([
{ hash: 'wV5XmpgMgU9T9S-3wiaaYJN32RV9bNpLGB7XM78khj8=' },
{ hash: 't2CaqiS60g0wEyGXgrYi4nwKWw8F7dJRNQPAceWVx8I=' },
])('throws for withdrawal %O', async ({ hash }) => {
expect.assertions(1);

Expand Down
16 changes: 8 additions & 8 deletions src/modules/withdrawal/getWithdrawalDetails/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getWithdrawalDetails } from './';
jest.mock('../../context/buildContext');

it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([
{ hash: 'wV5XmpgMgU9T9S-3wiaaYJN32RV9bNpLGB7XM78khj8=' },
{ hash: 't2CaqiS60g0wEyGXgrYi4nwKWw8F7dJRNQPAceWVx8I=' },
])('gets withdrawal details for %O', async ({ hash }) => {
expect.assertions(1);

Expand All @@ -15,23 +15,23 @@ it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([

return expect(result).toMatchObject({
addressReceiving: '0x3f4341a0599f63f444b6f1e0c7c5caf81b5843cc',
addressDeposit: '0xe06ff2b69b822807b8ac14479ff4386fe051e242',
amountDeposit: '0.00098766',
amountReceiving: '0.00073568',
addressDeposit: '0xF963E81109186B933F1bA674beC7A74186C20740',
amountDeposit: '0.00098851',
amountReceiving: '0.00073653',
currencyDeposit: 'sbBTC',
currencyReceiving: 'WBTC',
feeCurrency: 'WBTC',
feeTotal: '0.00025198',
hash,
status: 'SENDING',
txDepositId: '0x207cb67ff5aa3e435444dd6ffb900232ed2e5abb94c90b4a4b3d7d8e4e5787ce',
status: 'COMPLETED',
txDepositId: '0xa772b0ec48c436f82739e69ed624f8f5427afac6bbaa70361a67490340b762fc',
txReceivingId: null,
timestamp: new Date('2020-12-21T14:13:48.000Z'),
timestamp: new Date('2020-12-22T16:26:08.000Z'),
});
});

it.each<Pick<SkybridgeParams<'swap', 'test'>, 'hash'>>([
{ hash: 'D6ffXDodsQevLWS0EX_Od4i120TNvbAdCRAjAouKDXg=' },
{ hash: 'sQmT1Q1RROVwVLxs2wJWa5ZVa49zFIBr-9jC_wJsyqM=' },
])('throws for normal swap %O', async ({ hash }) => {
expect.assertions(1);

Expand Down

0 comments on commit 3395b27

Please sign in to comment.