-
Notifications
You must be signed in to change notification settings - Fork 7
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 #127 from bancorprotocol/extend-trade-by-source-am…
…ount-input-range Extend the supported input range of trade-by-source-amount
- Loading branch information
Showing
6 changed files
with
168 additions
and
26 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
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 @@ | ||
/** | ||
* This module provides a way to read runtime configuration passed by means of global object. | ||
* This is useful in case the configuration is not available at compile time, such as log verbosity. | ||
*/ | ||
|
||
const globalObject = (() => { | ||
try { | ||
return self; | ||
} catch (e) { | ||
try { | ||
return window; | ||
} catch (e) { | ||
return global; | ||
} | ||
} | ||
})(); | ||
|
||
export type RuntimeConfig = { | ||
logVerbosityLevel: number; | ||
legacyTradeBySourceRange: boolean; | ||
}; | ||
|
||
function getVerbosityLevel(): number { | ||
if (globalObject !== undefined) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return Number((globalObject as any).CARBON_DEFI_SDK_VERBOSITY) || 0; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function getLegacyTradeBySourceRange(): boolean { | ||
if (globalObject !== undefined) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return Boolean((globalObject as any).LEGACY_TRADE_BY_SOURCE_RANGE); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function getRuntimeConfig(): RuntimeConfig { | ||
const logVerbosityLevel = getVerbosityLevel(); | ||
const legacyTradeBySourceRange = getLegacyTradeBySourceRange(); | ||
return { | ||
logVerbosityLevel, | ||
legacyTradeBySourceRange, | ||
}; | ||
} |
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