@colony/purser-metamask
Version:
A javascript library to interact with a Metamask based Ethereum wallet
32 lines (28 loc) • 906 B
JavaScript
import _typeof from "@babel/runtime/helpers/esm/typeof";
import { validators as messages } from './messages';
/**
* Validate Metamask's internal state object.
* Basically, it checks for important props to be there.
*
* @method validateMetamaskState
*
* @param {Object} stateObject State object who's props to check
*
* @return {boolean} Throws if object is not valid. If it's all good, it returns true.
*/
export var validateMetamaskState = function validateMetamaskState(stateObject) {
if (!stateObject || _typeof(stateObject) !== 'object') {
throw new Error(messages.noState);
}
if (!stateObject.selectedAddress) {
throw new Error(messages.noStateAddress);
}
if (!stateObject.networkVersion) {
throw new Error(messages.noStateNetwork);
}
return true;
};
var metamaskValidators = {
validateMetamaskState: validateMetamaskState
};
export default metamaskValidators;