Skip to content

Commit

Permalink
Merge pull request #11 from mintme-com/deployed-tokens
Browse files Browse the repository at this point in the history
deployed tokens
  • Loading branch information
Denlev authored Dec 8, 2020
2 parents 6fe37e3 + 81ee508 commit e24f514
Show file tree
Hide file tree
Showing 7 changed files with 1,870 additions and 1,710 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/MyCryptoHQ/MyCrypto.svg?branch=develop)](https://travis-ci.org/MyCryptoHQ/MyCrypto)
[![Coverage Status](https://coveralls.io/repos/github/MyCryptoHQ/MyCrypto/badge.svg?branch=develop)](https://coveralls.io/github/MyCryptoHQ/MyCrypto?branch=develop)

* **Just looking to download?** Grab our [latest release](https://https://github.com/webchain-network/new-wallet/releases).
* **Just looking to download?** Grab our [latest release](https://github.com/webchain-network/new-wallet/releases).

## Development / Build Requirements

Expand Down
11 changes: 11 additions & 0 deletions common/api/mintme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {bityConfig, mintmeApiV2URL} from 'config';
import {checkHttpStatus, parseJSON} from "./utils";

export default function getDeployedTokens() {
return fetch(`${mintmeApiV2URL}/open/assets/`, {
method: 'get',
headers: new Headers(bityConfig.postConfig.headers)
})
.then(checkHttpStatus)
.then(parseJSON);
}
3 changes: 3 additions & 0 deletions common/config/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export const gasPriceDefaults: GasPriceSetting = {

export const MINIMUM_PASSWORD_LENGTH = 12;

// MINTME
export const knowledgeBaseURL = 'https://www.mintme.com/coin/faq';
export const mintmeApiV2URL = 'https://www.mintme.com/dev/api/v2';

export const ledgerReferralURL = 'https://www.ledgerwallet.com/r/1985?path=/products/';
export const trezorReferralURL = 'https://shop.trezor.io/?offer_id=10&aff_id=1735';
// TODO - Update url
Expand Down
100 changes: 74 additions & 26 deletions common/features/wallet/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
import { SagaIterator, delay, Task } from 'redux-saga';
import { apply, call, fork, put, select, takeEvery, take, cancel } from 'redux-saga/effects';
import {delay, SagaIterator, Task} from 'redux-saga';
import {apply, call, cancel, fork, put, select, take, takeEvery} from 'redux-saga/effects';

import configTokens from 'config/tokens';
import { translateRaw } from 'translations';
import { INode } from 'libs/nodes/INode';
import { Wei } from 'libs/units';
import { Token } from 'types/network';
import {translateRaw} from 'translations';
import {INode} from 'libs/nodes/INode';
import {Wei} from 'libs/units';
import {Token} from 'types/network';
import {
IWallet,
MnemonicWallet,
getPrivKeyWallet,
getKeystoreWallet,
determineKeystoreType,
KeystoreTypes,
getKeystoreWallet,
getPrivKeyWallet,
getUtcWallet,
IWallet,
KeystoreTypes,
MnemonicWallet,
signWrapper,
WalletConfig
} from 'libs/wallet';
import { loadWalletConfig, saveWalletConfig } from 'utils/localStorage';
import { getAddressesAndSymbols } from 'utils/tokens';
import { AppState } from 'features/reducers';
import {loadWalletConfig, saveWalletConfig} from 'utils/localStorage';
import {getAddressesAndSymbols} from 'utils/tokens';
import {AppState} from 'features/reducers';
import * as derivedSelectors from 'features/selectors';
import {
configMetaTypes,
configMetaSelectors,
configNodesSelectors,
configSelectors
} from 'features/config';
import { notificationsActions } from 'features/notifications';
import {
customTokensTypes,
customTokensActions,
customTokensSelectors
} from 'features/customTokens';
import {configMetaSelectors, configMetaTypes, configNodesSelectors, configSelectors} from 'features/config';
import {notificationsActions} from 'features/notifications';
import {customTokensActions, customTokensSelectors, customTokensTypes} from 'features/customTokens';
import * as types from './types';
import * as actions from './actions';
import * as selectors from './selectors';
import getDeployedTokens from 'api/mintme';
import {shepherdProvider} from "../../libs/nodes";
import ERC20 from "../../libs/erc20";
import {AddCustomTokenAction, CustomTokensActions} from "../customTokens/types";

export function* getTokenBalancesSaga(wallet: IWallet, tokens: Token[]) {
const node: INode = yield select(configNodesSelectors.getNodeLib);
Expand Down Expand Up @@ -166,7 +161,57 @@ export function* handleScanWalletAction(action: types.ScanWalletForTokensAction)
yield call(scanWalletForTokensSaga, action.payload);
}

function *scanForDeployedTokens(wallet: IWallet) {
try {
let deployedTokensBalance: any = [];
let deployedTokens: object = yield call(getDeployedTokens);

for (const key in deployedTokens) {
if (deployedTokens.hasOwnProperty(key) && deployedTokens[key].hasOwnProperty('token_address')) {
let data: object = {
data: ERC20.balanceOf.encodeInput({_owner: wallet.getAddressString()}),
to: deployedTokens[key].token_address
};
let request = yield call(shepherdProvider.sendCallRequest, data);

deployedTokensBalance.push({
name: deployedTokens[key].name,
address: deployedTokens[key].token_address,
balance: ERC20.balanceOf.decodeOutput(request)
});
}
}
const customTokens: AppState['customTokens'] = yield select(
customTokensSelectors.getCustomTokens
);

const customTokensSymbols = customTokens.map((token: Token) => token.symbol);

let i: number = 0;
do {
if (parseInt(deployedTokensBalance[i].balance.balance) > 0 &&
!customTokensSymbols.includes(deployedTokensBalance[i].name)
) {
const action: AddCustomTokenAction = {
type: CustomTokensActions.ADD,
payload: {
address: deployedTokensBalance[i].address,
decimal: 12,
symbol: deployedTokensBalance[i].name,
},
};
yield call(handleCustomTokenAdd, action);
}
i++;
} while (deployedTokensBalance.hasOwnProperty(i));
} catch (error) {
//
}
}

export function* scanWalletForTokensSaga(wallet: IWallet): SagaIterator {
yield call(scanForDeployedTokens, wallet);

try {
const isOffline = yield select(configMetaSelectors.getOffline);
if (isOffline) {
Expand Down Expand Up @@ -233,6 +278,7 @@ export function* unlockPrivateKeySaga(action: types.UnlockPrivateKeyAction): Sag
return;
}
yield put(actions.setWallet(wallet));
yield call(scanForDeployedTokens, wallet);
}

export function* startLoadingSpinner(): SagaIterator {
Expand Down Expand Up @@ -274,6 +320,7 @@ export function* unlockKeystoreSaga(action: types.UnlockKeystoreAction): SagaIte
// TODO: provide a more descriptive error than the two 'ERROR_6' (invalid pass) messages above
yield call(stopLoadingSpinner, spinnerTask);
yield put(actions.setWallet(wallet));
yield call(scanForDeployedTokens, wallet);
}

export function* unlockMnemonicSaga(action: types.UnlockMnemonicAction): SagaIterator {
Expand All @@ -289,6 +336,7 @@ export function* unlockMnemonicSaga(action: types.UnlockMnemonicAction): SagaIte
}

yield put(actions.setWallet(wallet));
yield call(scanForDeployedTokens, wallet);
}

export function* handleCustomTokenAdd(
Expand Down
3 changes: 2 additions & 1 deletion electron-app/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function getWindow() {
devTools: true,
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "MintMeCoinWallet",
"author": "abchosting",
"version": "1.7.7",
"version": "1.1.0",
"main": "main.js",
"description": "MyCrypto is a free, open-source interface for interacting with the blockchain",
"repository": "https://github.com/MyCryptoHQ/MyCrypto",
Expand Down
Loading

0 comments on commit e24f514

Please sign in to comment.