Skip to content

Commit

Permalink
Use different curried functions for the different OASIS instances
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Aug 13, 2024
1 parent eeb014f commit f10ad4a
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 84 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@nimiq/fastspot-api": "https://github.com/nimiq/fastspot-api#3a7c4b68529d7ec9ba8955a399412eaae946c528",
"@nimiq/hub-api": "file:../hub/client",
"@nimiq/iqons": "^1.5.2",
"@nimiq/libswap": "github:nimiq/libswap-js#8f66adf",
"@nimiq/oasis-api": "github:nimiq/oasis-api-js#dbfcdf4707c8a030022b3474126f4596bacbc1c1",
"@nimiq/libswap": "github:nimiq/libswap-js#f868f6407b122806a89f29c71351e8fb8289e879",
"@nimiq/oasis-api": "github:nimiq/oasis-api-js#fbd74179a5b9590f8e6dfe9b08ca47122db2ce1e",
"@nimiq/oasis-bank-list": "https://github.com/nimiq/oasis-bank-list#main",
"@nimiq/rpc": "^0.4.1",
"@nimiq/style": "^0.8.2",
Expand Down
3 changes: 1 addition & 2 deletions src/components/modals/BuyCryptoModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ import {
EurHtlcDetails,
} from '@nimiq/fastspot-api';
import {
getHtlc,
Htlc as OasisHtlc,
HtlcStatus,
sandboxMockClearHtlc,
TransactionType,
SepaClearingInstruction,
} from '@nimiq/oasis-api';
Expand Down Expand Up @@ -379,6 +377,7 @@ import { useBankStore } from '../../stores/Bank';
import { useKycStore } from '../../stores/Kyc';
import KycPrompt from '../kyc/KycPrompt.vue';
import KycOverlay from '../kyc/KycOverlay.vue';
import { getHtlc, sandboxMockClearHtlc } from '../../lib/OasisEur';
enum Pages {
WELCOME,
Expand Down
3 changes: 1 addition & 2 deletions src/components/modals/SellCryptoModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ import {
Contract,
} from '@nimiq/fastspot-api';
import {
getHtlc,
exchangeAuthorizationToken,
HtlcStatus,
TransactionType as OasisTransactionType,
} from '@nimiq/oasis-api';
Expand Down Expand Up @@ -344,6 +342,7 @@ import {
import { useKycStore } from '../../stores/Kyc';
import KycPrompt from '../kyc/KycPrompt.vue';
import KycOverlay from '../kyc/KycOverlay.vue';
import { exchangeAuthorizationToken, getHtlc } from '../../lib/OasisEur';
type KycResult = import('../../swap-kyc-handler').SetupSwapWithKycResult['kyc'];
Expand Down
7 changes: 4 additions & 3 deletions src/components/swap/SwapNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ import {
ClearingInfo,
ClearingStatus,
DeniedReason,
getHtlc,
Htlc as OasisHtlc,
HtlcStatus,
settleHtlc,
SettlementInfo,
SettlementStatus,
} from '@nimiq/oasis-api';
Expand Down Expand Up @@ -88,6 +86,8 @@ import {
} from '../../ethers';
import { useUsdcTransactionsStore, Transaction as UsdcTransaction } from '../../stores/UsdcTransactions';
import { POLYGON_BLOCKS_PER_MINUTE } from '../../lib/usdc/OpenGSN';
import { getHtlc as getEurHtlc, settleHtlc as settleEurHtlc } from '../../lib/OasisEur';
import { getHtlc as getCrcHtlc, settleHtlc as settleCrcHtlc } from '../../lib/OasisCrc';
enum SwapError {
EXPIRED = 'EXPIRED',
Expand Down Expand Up @@ -285,8 +285,9 @@ export default defineComponent({
};
}
case SwapAsset.CRC:
return { getHtlc: getCrcHtlc, settleHtlc: settleCrcHtlc };
case SwapAsset.EUR:
return { getHtlc, settleHtlc };
return { getHtlc: getEurHtlc, settleHtlc: settleEurHtlc };
default: throw new Error(`Unsupported asset: ${asset}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/composables/asset-transfer/useSinpeMovilSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
SinpeMovilHtlcCreationInstructions,
} from '@nimiq/hub-api';
import {
getHtlc,
HtlcStatus,
TransactionType as OasisTransactionType,
} from '@nimiq/oasis-api';
Expand All @@ -46,6 +45,7 @@ import SinpeUserInfo from '../../components/SinpeUserInfo.vue';
import AddressSelector from '../../components/AddressSelector.vue';
import { AssetTransferOptions, AssetTransferParams } from './types';
import { useConfig } from '../useConfig';
import { getHtlc } from '../../lib/OasisCrc';

function isCryptoCurrency(currency: any): currency is CryptoCurrency {
return Object.values(CryptoCurrency).includes(currency.toLocaleLowerCase() as CryptoCurrency);
Expand Down
16 changes: 10 additions & 6 deletions src/composables/useOasisPayoutStatusUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { onUnmounted, Ref, watch } from '@vue/composition-api';
import { getHtlc, SettlementInfo, SettlementStatus } from '@nimiq/oasis-api';
import { SettlementInfo, SettlementStatus } from '@nimiq/oasis-api';
import { SwapAsset } from '@nimiq/fastspot-api';
import { SwapData, SwapEurData, useSwapsStore } from '../stores/Swaps';
import { SwapCrcData, SwapData, SwapEurData, useSwapsStore } from '../stores/Swaps';
import { getHtlc as getEurHtlc } from '../lib/OasisEur';
import { getHtlc as getCrcHtlc } from '../lib/OasisCrc';

// TODO: Remove logging when stable
/* eslint-disable no-console */
Expand All @@ -16,7 +18,7 @@ export function useOasisPayoutStatusUpdater(swapData: Ref<SwapData | null>) {
return;
}

const data = swapData.value as SwapEurData;
const data = swapData.value as SwapEurData | SwapCrcData;
const settlement = data.htlc!.settlement!;

// Determine check interval
Expand All @@ -30,7 +32,9 @@ export function useOasisPayoutStatusUpdater(swapData: Ref<SwapData | null>) {
oasisPayoutCheckTimeout = 1; // Ensure no parallel executions
console.log('Fetching HTLC now');

const htlc = await getHtlc(data.htlc!.id);
const htlc = data.asset === SwapAsset.EUR
? await getEurHtlc(data.htlc!.id)
: await getCrcHtlc(data.htlc!.id);
console.log('Got HTLC:', htlc);

settlement.status = htlc.settlement.status;
Expand Down Expand Up @@ -73,10 +77,10 @@ export function useOasisPayoutStatusUpdater(swapData: Ref<SwapData | null>) {
}

watch(swapData, (data, previousData) => { // eslint-disable-line consistent-return
if (previousData?.asset === SwapAsset.EUR) {
if (previousData?.asset === SwapAsset.EUR || previousData?.asset === SwapAsset.CRC) {
stop();
}
if (data?.asset !== SwapAsset.EUR) return stop();
if (data?.asset !== SwapAsset.EUR && data?.asset !== SwapAsset.CRC) return stop();
if (data.htlc?.settlement?.status !== SettlementStatus.ACCEPTED) return stop();
if (oasisPayoutCheckTimeout) return; // eslint-disable-line consistent-return
checkOasisPayoutStatus();
Expand Down
Loading

0 comments on commit f10ad4a

Please sign in to comment.