-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend the swap preview. Specify errors;
- Loading branch information
1 parent
b8714dd
commit 20ffdd9
Showing
10 changed files
with
311 additions
and
114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type { SwapPreview, SwapPreviewCurrencyData, SwapPreviewDirectionData, SwapPreviewFee } from './swapPreview'; | ||
export type { SwapPreviewError } from './swapPreviewError'; | ||
export type { SwapPreviewWarning } from './swapPreviewWarning'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type BigNumber from 'bignumber.js'; | ||
|
||
import type { Currency } from '../../../common/index'; | ||
import type { Swap } from '../../../swaps'; | ||
|
||
interface SwapPreviewErrorBase<TErrorId extends string = string, TErrorData = unknown> { | ||
readonly id: TErrorId; | ||
readonly data?: TErrorData; | ||
} | ||
|
||
type CheckErrorType<TErrorId extends string, TError extends SwapPreviewErrorBase<TErrorId>> = TError; | ||
|
||
type NotEnoughFundsSwapPreviewError = CheckErrorType< | ||
'not-enough-funds', | ||
| { | ||
readonly id: 'not-enough-funds'; | ||
readonly data: { | ||
readonly type: 'balance'; | ||
readonly currencyId: Currency['id']; | ||
readonly requiredAmount: BigNumber; | ||
}; | ||
} | ||
| { | ||
readonly id: 'not-enough-funds'; | ||
readonly data: { | ||
readonly type: 'fees'; | ||
readonly currencyId: Currency['id']; | ||
readonly requiredAmount: BigNumber; | ||
}; | ||
} | ||
| { | ||
readonly id: 'not-enough-funds'; | ||
readonly data: { | ||
readonly type: 'swaps'; | ||
readonly swapIds: ReadonlyArray<Swap['id']>; | ||
readonly currencyId: Currency['id']; | ||
readonly lockedAmount: BigNumber; | ||
}; | ||
} | ||
>; | ||
|
||
export type SwapPreviewError = CheckErrorType< | ||
string, | ||
| NotEnoughFundsSwapPreviewError | ||
| { | ||
readonly id: 'not-enough-liquidity' | ||
} | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
interface SwapPreviewWarningBase<TWarningId extends string = string, TWarningData = unknown> { | ||
readonly id: TWarningId; | ||
readonly data?: TWarningData; | ||
} | ||
|
||
type CheckWarningType<TWarningId extends string, TWarning extends SwapPreviewWarningBase<TWarningId>> = TWarning; | ||
|
||
export type SwapPreviewWarning = CheckWarningType< | ||
string, | ||
never | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.