MyCrypto/common/libs/nodes/rpc/requests.ts
William O'Beirne 1221a73a46 Better Offline Detection / Handling (#478)
* Change navigator.onLine to actually pinging the network. Refactor notifications to take Infinity instead of 'infinity'

* Stop polling when forced offline.

* Show spinners if unit display balance is null, show offline text if were actually offline.

* Fix issue with typescript and connected union-prop components.

* Only ping the node when navigator.onLine changes.
2017-11-28 18:17:26 -06:00

78 lines
1.6 KiB
TypeScript

import { Token } from 'config/data';
import ERC20 from 'libs/erc20';
import {
CallRequest,
EstimateGasRequest,
GetBalanceRequest,
GetTokenBalanceRequest,
GetTransactionCountRequest,
SendRawTxRequest,
GetCurrentBlockRequest
} from './types';
import { hexEncodeData } from './utils';
import { TxObj } from '../INode';
export default class RPCRequests {
public getNetVersion() {
return { method: 'net_version' };
}
public sendRawTx(signedTx: string): SendRawTxRequest | any {
return {
method: 'eth_sendRawTransaction',
params: [signedTx]
};
}
public estimateGas(transaction): EstimateGasRequest | any {
return {
method: 'eth_estimateGas',
params: [transaction]
};
}
public getBalance(address: string): GetBalanceRequest | any {
return {
method: 'eth_getBalance',
params: [hexEncodeData(address), 'pending']
};
}
public ethCall(txObj: TxObj): CallRequest | any {
return {
method: 'eth_call',
params: [txObj, 'pending']
};
}
public getTransactionCount(
address: string
): GetTransactionCountRequest | any {
return {
method: 'eth_getTransactionCount',
params: [address, 'pending']
};
}
public getTokenBalance(
address: string,
token: Token
): GetTokenBalanceRequest | any {
return {
method: 'eth_call',
params: [
{
to: token.address,
data: ERC20.balanceOf(address)
},
'pending'
]
};
}
public getCurrentBlock(): GetCurrentBlockRequest | any {
return {
method: 'eth_blockNumber'
};
}
}