Skip to content

Commit

Permalink
Merge pull request #265 from TokelPlatform/development
Browse files Browse the repository at this point in the history
Release v1.2.2: Fix fungible token transactions sum
  • Loading branch information
lenilsonjr committed Mar 16, 2022
2 parents efb48c0 + b5638cc commit 10bb6be
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/components/Dashboard/Portfolio/Portfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ const Portfolio = (): ReactElement => {
const tokenCount = useSelector(selectTokenCount);

const tokelPriceUSD = useSelector(selectTokelPriceUSD);
const priceString = tokelPriceUSD
? ` ~ $${Math.round(balance * tokelPriceUSD * 100) / 100}`
: null;
const priceString = tokelPriceUSD ? ` ~ $${Math.round(balance * tokelPriceUSD * 100) / 100}` : '';

useEffect(() => {
fetchTokelPrice();
Expand Down
2 changes: 1 addition & 1 deletion src/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tokel_app",
"productName": "tokelPlatform",
"version": "1.2.1",
"version": "1.2.2",
"description": "Komodo ecosystem’s Token Platform",
"main": "./main.js",
"author": {
Expand Down
19 changes: 17 additions & 2 deletions src/electron/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ const { parentPort } = require('worker_threads');
const sb = require('satoshi-bitcoin');
const BN = require('bn.js');

// Same as parseBigNumObject in helpers.ts TODO: don't repeat myself
const parseBigNumObject = bnObj => {
if (!bnObj) return new BN(0);

const bn = new BN(0);
Object.entries(bnObj).forEach(([propName, propValue]) => {
bn[propName] = propValue;
});
return bn;
};

const {
ECPair,
ccutils,
Expand Down Expand Up @@ -154,10 +165,14 @@ class BitgoSingleton {
const res = {};
ccUtxos.forEach(utxo => {
if (utxo?.tokendata?.tokenid) {
res[utxo.tokendata.tokenid.reverse().toString('hex')] = utxo.satoshis;
const tokenId = utxo.tokendata.tokenid.reverse().toString('hex');
const currentSatoshis = parseBigNumObject(res[tokenId]);
res[tokenId] = currentSatoshis.add(parseBigNumObject(utxo.satoshis));
} else if (!!utxo?.tokendata?.name && utxo?.tokendata?.funcid === 'c') {
// In case token was created by the wallet, but has no transactions
res[utxo.txid.reverse().toString('hex')] = utxo.satoshis;
const txId = utxo.txid.reverse().toString('hex');
const currentSatoshis = parseBigNumObject(res[txId]);
res[txId] = currentSatoshis.add(parseBigNumObject(utxo.satoshis));
}
});
return {
Expand Down
8 changes: 6 additions & 2 deletions src/store/models/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createModel } from '@rematch/core';
import BN from 'bn.js';
import dp from 'dot-prop-immutable';

import { parseBigNumObject } from 'util/helpers';
import { TICKER, TokenFilter } from 'vars/defines';

import type { RootModel } from './models';
Expand Down Expand Up @@ -45,7 +47,9 @@ export default createModel<RootModel>()({
...state,
tokenBalances,
}),
UPDATE_TOKEN_BALANCE: (state, tokenid: string, balance: number) =>
dp.set(state, `tokenBalances.${tokenid}`, v => v - balance),
UPDATE_TOKEN_BALANCE: (state, tokenid: string, amount: number) =>
dp.set(state, `tokenBalances.${tokenid}`, balance =>
parseBigNumObject(balance).sub(new BN(amount))
),
},
});
6 changes: 4 additions & 2 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import BN from 'bn.js';
import format from 'date-fns/format';
import fromUnixTime from 'date-fns/fromUnixTime';
import getUnixTime from 'date-fns/getUnixTime';
import BigNumObject from 'util/types/BigNum';

import BigNumObject from 'util/types/BigNum';
import { Config, EXTRACT_IPFS_HASH_REGEX, SATOSHIS, WindowSize } from 'vars/defines';

interface ResponsiveType {
Expand All @@ -26,7 +26,9 @@ export const Responsive = {

export const randomColor = () => `hsla(${(360 * Math.random()).toString()}, 70%, 80%, 1)`;

const parseBigNumObject = (bnObj: BigNumObject) => {
export const parseBigNumObject = (bnObj: BigNumObject) => {
if (!bnObj) return new BN(0);

const bn = new BN(0);
Object.entries(bnObj).forEach(([propName, propValue]) => {
bn[propName] = propValue;
Expand Down
1 change: 1 addition & 0 deletions src/util/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
KMD: () => 'https://kmd.explorer.dexstats.info',
TKL: path => `https://explorer.tokel.io/${path}`,
TKLTEST: path => `http://explorer.komodoplatform.com:20000/${path}/TKLTEST`,
TKLTEST2: path => `http://explorer.komodoplatform.com:20000/${path}/TKLTEST2`,
},
insightApi: {
TKL: 'https://tokel.explorer.dexstats.info/insight-api-komodo',
Expand Down

0 comments on commit 10bb6be

Please sign in to comment.