Skip to content

Instantly share code, notes, and snippets.

@alexroan
Created June 29, 2020 10:08
Show Gist options
  • Save alexroan/683491c625e7b838cf6dc9ab1bfe146f to your computer and use it in GitHub Desktop.
Save alexroan/683491c625e7b838cf6dc9ab1bfe146f to your computer and use it in GitHub Desktop.
compound_interactions.js
export const supplyEth = async (dispatch, cEthInstance, account, supplyValue, web3, network) => {
cEthInstance.methods.mint().send({from: account, value: supplyValue})
.once('transactionHash', (hash) => {
dispatch(depositing());
})
.on('confirmation', (number, receipt) => {
if (number < 4){
dispatch(depositConfirmation(number+1));
if (number === 3) {
dispatch(finishedDepositing());
loadBalance(dispatch, web3, account, network);
}
}
})
.on('error', (error) => {
console.log(error);
});
}
export const redeemEth = async (dispatch, cEthInstance, account, redeemAmount, web3, network) => {
cEthInstance.methods.redeemUnderlying(redeemAmount).send({from: account})
.once('transactionHash', (hash) => {
dispatch(withdrawing());
})
.on('confirmation', (number, receipt) => {
if(number < 4){
dispatch(withdrawConfirmation(number+1));
if(number === 3) {
dispatch(finishedWithdrawing());
loadBalance(dispatch, web3, account, network);
}
}
})
.on('error', (error) => {
console.log(error);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment