mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-31 10:08:03 +03:00
Price conversion iprovements
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ethers } from 'ethers';
|
||||
import {
|
||||
AtomicSwapStatus, type AtomicSwap, type SupportedChainId,
|
||||
type AtomicSwap, type SupportedChainId,
|
||||
type Unit, INTERNAL_PROTOCOL_PRECISION
|
||||
} from '../../index.js';
|
||||
import getHistoryExt from './getHistory.js';
|
||||
@@ -8,14 +8,6 @@ import swapExt from './swap.js';
|
||||
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
|
||||
const backendStatusToAtomicSwapStatus = {
|
||||
LOCKED: AtomicSwapStatus.ROUTING,
|
||||
CLAIMED: AtomicSwapStatus.SETTLED,
|
||||
REFUNDED: AtomicSwapStatus.REFUNDED,
|
||||
REDEEMED: AtomicSwapStatus.SETTLED,
|
||||
'BEFORE-REDEEM': AtomicSwapStatus.ROUTING,
|
||||
} as const;
|
||||
|
||||
export default class Bridge {
|
||||
constructor(
|
||||
private readonly unitsArray: Unit[],
|
||||
@@ -38,13 +30,12 @@ export default class Bridge {
|
||||
targetChainId,
|
||||
asset,
|
||||
sourceChainId,
|
||||
status: asStatus,
|
||||
claimed,
|
||||
sender,
|
||||
transactions,
|
||||
expiration,
|
||||
creationDate,
|
||||
} = atomicSwap;
|
||||
|
||||
const localSwap = externalStoredAtomicSwaps.find(
|
||||
(swap) => secretHash === swap.secretHash,
|
||||
);
|
||||
@@ -61,53 +52,24 @@ export default class Bridge {
|
||||
assetName = '—'; // We don't want to display address even if we can't find asset name
|
||||
}
|
||||
|
||||
// Define status
|
||||
let historyStatus = backendStatusToAtomicSwapStatus[asStatus.source];
|
||||
if (asStatus.source === 'LOCKED') {
|
||||
const historySwap = bridgeHistory[secretHash];
|
||||
if (historySwap?.status.target === 'REDEEMED') {
|
||||
historyStatus = AtomicSwapStatus.SETTLED;
|
||||
}
|
||||
}
|
||||
if (claimed) historyStatus = AtomicSwapStatus.SETTLED;
|
||||
let status: AtomicSwapStatus | undefined;
|
||||
if (
|
||||
[AtomicSwapStatus.SETTLED, AtomicSwapStatus.REFUNDED].includes(
|
||||
historyStatus,
|
||||
)
|
||||
) {
|
||||
status = historyStatus;
|
||||
} else {
|
||||
status = localSwap !== undefined ? localSwap.status : historyStatus;
|
||||
}
|
||||
|
||||
// Define secret
|
||||
const secret = localSwap !== undefined ? localSwap.secret : '';
|
||||
|
||||
// Define environment
|
||||
const env = localSwap?.env;
|
||||
|
||||
return {
|
||||
liquidityMigrationTxHash: localSwap?.liquidityMigrationTxHash,
|
||||
localSwap,
|
||||
sourceNetwork: sourceChainId,
|
||||
targetNetwork: targetChainId,
|
||||
amount: new BigNumber(amount)
|
||||
.multipliedBy(new BigNumber(10).pow(INTERNAL_PROTOCOL_PRECISION))
|
||||
.toString(),
|
||||
walletAddress: sender,
|
||||
secret,
|
||||
secretHash,
|
||||
lockTransactionHash: transactions?.lock,
|
||||
refundTransactionHash: transactions?.refund,
|
||||
status,
|
||||
asset: assetName,
|
||||
expiration:
|
||||
expiration?.lock ?? creationDate.getTime() + 60 * 60 * 24 * 4, // Or default 4 days
|
||||
creationDate: creationDate.getTime(),
|
||||
env,
|
||||
redeemOrder: atomicSwap.redeemOrder,
|
||||
};
|
||||
}).filter((swap) => swap.env === undefined || swap.env === this.env);
|
||||
});
|
||||
}
|
||||
|
||||
getHistory(address: string, limit = 1000) {
|
||||
|
||||
Reference in New Issue
Block a user