ghost-portal/packages/react-signer/src/Checks/ContractCall.tsx
Jaco Greeff f35b2d4428
Update fees, mortal & tips (#1590)
* Update fees, mortal & tips

* Linting

* Revert findCall

* Fix fee calculation (take version byte  into account)

* Remove MAX (weights), add weight note

* does not *
2019-09-18 14:53:51 +02:00

46 lines
1.2 KiB
TypeScript

// Copyright 2017-2019 @polkadot/react-signer authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { DerivedContractFees } from '@polkadot/api-derive/types';
import { ExtraFees as State } from './types';
import BN from 'bn.js';
import React, { useEffect, useState } from 'react';
import { Compact, UInt } from '@polkadot/types';
interface Props {
endowment: BN | Compact<UInt>;
fees: DerivedContractFees;
onChange: (fees: State) => void;
}
export default function ContractCall ({ endowment, fees, onChange }: Props): React.ReactElement<Props> | null {
const [state, setState] = useState<State>({
extraFees: new BN(0),
extraAmount: new BN(0),
extraWarn: false
});
useEffect((): void => {
const extraFees = new BN(fees.callBaseFee);
const extraAmount = endowment instanceof Compact
? endowment.toBn()
: new BN(endowment || 0);
const update = {
extraAmount,
extraFees,
extraWarn: false
};
if (!update.extraAmount.eq(state.extraAmount) || !update.extraFees.eq(state.extraFees)) {
onChange(update);
}
setState(update);
}, [endowment, fees]);
return null;
}