Skip to content

Commit

Permalink
Fix Bignumber accurancy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Luphia1984 committed Dec 24, 2021
1 parent 1007423 commit 89d9255
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/lunar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cafeca/lunar",
"version": "0.3.5",
"version": "0.3.6",
"description": "Blockchain Connect Module",
"main": "./build/lunar.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions src/connectors/imtoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import Metamask from './metamask.js'

class ImToken extends Metamask {
_type = Wallets.imToken;

async send({ from = this.address, to, amount, data }) {
const decimals = await this.getDecimals();
const value = SmartContract.toSmallestUnit({ amount, decimals });
const transactionParameters = {
from,
to,
value,
data,
chainId: this.chainId
}
const requestData = {
method: 'eth_sendTransaction',
params: [ transactionParameters ],
};
const txHash = await ethereum.request(requestData);
return txHash;
}
}

export default ImToken;
3 changes: 1 addition & 2 deletions src/connectors/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Metamask extends Connector {

async send({ from = this.address, to, amount, data }) {
const decimals = await this.getDecimals();
const value = SmartContract.toSmallestUnit({ amount, decimals });
const value = SmartContract.toSmallestUnitHex({ amount, decimals });
const transactionParameters = {
from,
to,
Expand All @@ -40,7 +40,6 @@ class Metamask extends Connector {
method: 'eth_sendTransaction',
params: [ transactionParameters ],
};
console.log(requestData)
const txHash = await ethereum.request(requestData);
return txHash;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/smartcontract.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SmartContract {
static toSmallestUnit({ amount, decimals }) {
const result = new BigNumber(amount)
.multipliedBy(new BigNumber(10).pow(decimals))
.toString();
.toFixed();
return result;
}

Expand Down

0 comments on commit 89d9255

Please sign in to comment.