This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from 0xProject/feature/instant/tell-amount-a…
…vailable [instant] Tell user how much of an asset is available
- Loading branch information
Showing
12 changed files
with
273 additions
and
17 deletions.
There are no files selected for viewing
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,22 @@ | ||
import { BigNumber } from '@0x/utils'; | ||
|
||
import { AssetBuyerError } from './types'; | ||
|
||
/** | ||
* Error class representing insufficient asset liquidity | ||
*/ | ||
export class InsufficientAssetLiquidityError extends Error { | ||
/** | ||
* The amount availabe to fill (in base units) factoring in slippage. | ||
*/ | ||
public amountAvailableToFill: BigNumber; | ||
/** | ||
* @param amountAvailableToFill The amount availabe to fill (in base units) factoring in slippage | ||
*/ | ||
constructor(amountAvailableToFill: BigNumber) { | ||
super(AssetBuyerError.InsufficientAssetLiquidity); | ||
this.amountAvailableToFill = amountAvailableToFill; | ||
// Setting prototype so instanceof works. See https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
Object.setPrototypeOf(this, InsufficientAssetLiquidityError.prototype); | ||
} | ||
} |
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
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,26 @@ | ||
import { BigNumber } from '@0x/utils'; | ||
|
||
import { InsufficientAssetLiquidityError } from '../../src/errors'; | ||
|
||
export const testHelpers = { | ||
expectInsufficientLiquidityError: ( | ||
expect: Chai.ExpectStatic, | ||
functionWhichTriggersError: () => void, | ||
expectedAmountAvailableToFill?: BigNumber, | ||
): void => { | ||
let wasErrorThrown = false; | ||
try { | ||
functionWhichTriggersError(); | ||
} catch (e) { | ||
wasErrorThrown = true; | ||
expect(e).to.be.instanceOf(InsufficientAssetLiquidityError); | ||
if (expectedAmountAvailableToFill) { | ||
expect(e.amountAvailableToFill).to.be.bignumber.equal(expectedAmountAvailableToFill); | ||
} else { | ||
expect(e.amountAvailableToFill).to.be.undefined(); | ||
} | ||
} | ||
|
||
expect(wasErrorThrown).to.be.true(); | ||
}, | ||
}; |
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.