Skip to content

Commit

Permalink
fix: stacking fee adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 27, 2021
1 parent a20a38e commit 327191e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions app/modals/stacking/stacking-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ interface StackingModalProps {
onClose(): void;
}

const CONTRACT_CALL_FEE = 260;

export const StackingModal: FC<StackingModalProps> = props => {
const { onClose, numCycles, poxAddress, amountToStack } = props;

Expand Down Expand Up @@ -93,6 +95,10 @@ export const StackingModal: FC<StackingModalProps> = props => {
balance: selectAddressBalance(state),
}));

const accountBalance = new BigNumber(balance?.balance ?? 0);

const shouldModifyTxFee = accountBalance.minus(amountToStack).isLessThan(CONTRACT_CALL_FEE);

const initialStep =
walletType === 'software'
? StackingModalStep.DecryptWalletAndSend
Expand Down Expand Up @@ -126,10 +132,12 @@ export const StackingModal: FC<StackingModalProps> = props => {
burnBlockHeight: coreNodeInfo.burn_block_height,
});
const tx = await makeContractCall({ ...txOptions, senderKey: privateKey });
const modifiedFeeTx = stackingClient.modifyLockTxFee({
tx,
amountMicroStx: new BN(amountToStack.toString()),
});
const modifiedFeeTx = shouldModifyTxFee
? stackingClient.modifyLockTxFee({
tx,
amountMicroStx: new BN(amountToStack.toString()),
})
: tx;

const signer = new TransactionSigner(modifiedFeeTx);
signer.signOrigin(createStacksPrivateKey(privateKey));
Expand All @@ -145,6 +153,7 @@ export const StackingModal: FC<StackingModalProps> = props => {
amountToStack,
poxAddress,
numCycles,
shouldModifyTxFee,
]);

const createLedgerWalletTx = useCallback(
Expand All @@ -168,10 +177,12 @@ export const StackingModal: FC<StackingModalProps> = props => {
publicKey: options.publicKey.toString('hex'),
});

const modifiedFeeTx = stackingClient.modifyLockTxFee({
tx: unsignedTx,
amountMicroStx: new BN(amountToStack.toString()),
});
const modifiedFeeTx = shouldModifyTxFee
? stackingClient.modifyLockTxFee({
tx: unsignedTx,
amountMicroStx: new BN(amountToStack.toString()),
})
: unsignedTx;
const resp: ResponseSign = await blockstackApp.sign(
STX_DERIVATION_PATH,
modifiedFeeTx.serialize()
Expand All @@ -190,6 +201,7 @@ export const StackingModal: FC<StackingModalProps> = props => {
amountToStack,
poxAddress,
numCycles,
shouldModifyTxFee,
]
);

Expand Down

0 comments on commit 327191e

Please sign in to comment.