-
Notifications
You must be signed in to change notification settings - Fork 12
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 #46 from TrustyFund/AddParameters
Add parameters api module
- Loading branch information
Showing
7 changed files
with
115 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
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,42 @@ | ||
import { Apis } from 'bitsharesjs-ws'; | ||
import { ChainTypes } from 'bitsharesjs'; | ||
|
||
const { operations } = ChainTypes; | ||
let cacheParameters = false; | ||
|
||
const getParameters = async () => { | ||
if (cacheParameters) { | ||
return cacheParameters; | ||
} | ||
|
||
const [{ parameters }] = await Apis.instance().db_api().exec('get_objects', [['2.0.0']]); | ||
cacheParameters = parameters; | ||
return cacheParameters; | ||
}; | ||
|
||
export const getCachedComissions = () => { | ||
const { current_fees: { parameters: fees, scale } } = cacheParameters; | ||
return { fees, scale }; | ||
}; | ||
|
||
export const getComissions = async () => { | ||
if (cacheParameters) { | ||
return getCachedComissions(); | ||
} | ||
|
||
const { current_fees: { parameters: fees, scale } } = await getParameters(); | ||
console.log('Service:', fees); | ||
return { fees, scale }; | ||
}; | ||
|
||
export const getComission = async (type) => { | ||
const ops = Object.keys(operations); | ||
const opIndex = ops.indexOf(type); | ||
const { fees } = await getComissions(); | ||
if (opIndex > -1) { | ||
return fees[opIndex][1].fee; | ||
} | ||
return false; | ||
}; | ||
|
||
export default { getParameters, getComissions, getComission, getCachedComissions }; |
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