mirror of
https://github.com/status-im/keycard-redeem.git
synced 2025-02-17 14:37:16 +00:00
add utils
This commit is contained in:
parent
fa1f796695
commit
003c875590
@ -12,9 +12,7 @@ import {
|
||||
ERROR_LOADING_GIFT,
|
||||
ERROR_GIFT_NOT_FOUND,
|
||||
} from '../actions/bucket';
|
||||
import Web3Utils from "web3-utils";
|
||||
|
||||
const BN = Web3Utils.BN;
|
||||
import { toBaseUnit } from "../utils";
|
||||
|
||||
const errorMessage = (error: BucketError): string => {
|
||||
switch (error.type) {
|
||||
@ -29,21 +27,6 @@ const errorMessage = (error: BucketError): string => {
|
||||
}
|
||||
}
|
||||
|
||||
const toBaseUnit = (fullAmount: string, decimalsSize: number, roundDecimals: number) => {
|
||||
const amount = new BN(fullAmount);
|
||||
const base = new BN(10).pow(new BN(decimalsSize));
|
||||
const whole = amount.div(base).toString();
|
||||
let decimals = amount.mod(base).toString();
|
||||
for (let i = decimals.length; i < decimalsSize; i++) {
|
||||
decimals = `0${decimals}`;
|
||||
}
|
||||
|
||||
const full = `${whole}.${decimals}`;
|
||||
const rounded = `${whole}.${decimals.slice(0, roundDecimals)}`;
|
||||
|
||||
return [full, rounded];
|
||||
}
|
||||
|
||||
export default function(ownProps: any) {
|
||||
const dispatch = useDispatch()
|
||||
const match = useRouteMatch({
|
||||
@ -99,5 +82,7 @@ export default function(ownProps: any) {
|
||||
Display Amount: {displayAmount} <br />
|
||||
Rounded Display Amount: {roundedDisplayAmount} <br />
|
||||
Receiver: {props.receiver} <br />
|
||||
|
||||
<br /><br /><br />
|
||||
</>;
|
||||
}
|
||||
|
18
app/js/utils.ts
Normal file
18
app/js/utils.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import Web3Utils from "web3-utils";
|
||||
|
||||
const BN = Web3Utils.BN;
|
||||
|
||||
export const toBaseUnit = (fullAmount: string, decimalsSize: number, roundDecimals: number) => {
|
||||
const amount = new BN(fullAmount);
|
||||
const base = new BN(10).pow(new BN(decimalsSize));
|
||||
const whole = amount.div(base).toString();
|
||||
let decimals = amount.mod(base).toString();
|
||||
for (let i = decimals.length; i < decimalsSize; i++) {
|
||||
decimals = `0${decimals}`;
|
||||
}
|
||||
|
||||
const full = `${whole}.${decimals}`;
|
||||
const rounded = `${whole}.${decimals.slice(0, roundDecimals)}`;
|
||||
|
||||
return [full, rounded];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user