Skip to content

Commit

Permalink
loan
Browse files Browse the repository at this point in the history
  • Loading branch information
adibas03 committed Nov 5, 2019
1 parent a4d5d2f commit 0b5187e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/components/pages/loanOffer/checkout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import {
connectToWallet,
getInjectedAccountAddress,
prepBigNumber,
setTransactionEvents,
} from '../../../../utils/web3Utils'
import { getDeployedFromConfig } from '../../../../utils/getDeployed'
import {
Expand Down
49 changes: 44 additions & 5 deletions src/components/pages/myLoan/component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import { RouteComponentProps, withRouter } from 'react-router-dom'
import { ChasingDots } from 'styled-spinkit'
import { store } from '../../../store'
import RenderBorrowerLoan from './renderBorrowerLoan'
import RenderLenderLoan from './renderLenderLoan'
import RenderConnectWallet from '../renderConnectWallet'
import contractAddresses from '../../../config/ines.fund.js'
import { LoanStatuses, MILLISECONDS, ZERO } from '../../../config/constants.js'
import { networksExplorer } from '../../../utils/getWeb3'
import {
BN,
connectToWallet,
Expand Down Expand Up @@ -92,6 +94,31 @@ class MyLoan extends React.Component<MyLoanProps, MyLoanState> {
},
}

get txEvents() {
const { networkId, toastProvider } = store.getState()
return {
onTransactionHash: hash =>
toastProvider.addMessage('Processing transaction...', {
secondaryMessage: 'Check progress on Etherscan',
actionHref: `${networksExplorer[networkId]}/tx/${hash}`,
actionText: 'Check',
variant: 'processing',
}),
onReceipt: receipt =>
toastProvider.addMessage('Transaction completed...', {
secondaryMessage: 'View transaction Etherscan',
actionHref: `${networksExplorer[networkId]}/tx/${receipt.transactionHash}`,
actionText: 'View',
variant: 'success',
}),
onError: error =>
toastProvider.addMessage('Transaction failed...', {
secondaryMessage: `${error.message || error}`,
variant: 'failure',
}),
}
}

onWithdraw = async () => {
// const {history} = this.props;
const { releaseAllowance, crowdloanInstance } = this.state
Expand All @@ -102,7 +129,9 @@ class MyLoan extends React.Component<MyLoanProps, MyLoanState> {
try {
this.setState({ transacting: true })

const tx = await withdrawRepayment(crowdloanInstance)
const tx = await withdrawRepayment(crowdloanInstance, {
txEvents: this.txEvents,
})
console.log(tx)

this.setState({ transacting: false, loaded: false }, () =>
Expand All @@ -126,7 +155,9 @@ class MyLoan extends React.Component<MyLoanProps, MyLoanState> {
return console.error('Crowdfund already started')
}

const tx = await startCrowdfund(crowdloanInstance)
const tx = await startCrowdfund(crowdloanInstance, {
txEvents: this.txEvents,
})
console.log(tx)

this.setState({ transacting: false, loaded: false }, () =>
Expand All @@ -152,7 +183,10 @@ class MyLoan extends React.Component<MyLoanProps, MyLoanState> {

const tx = await withdrawPrincipal(
crowdloanInstance,
prepBigNumber(amount, paymentToken.decimals)
prepBigNumber(amount, paymentToken.decimals),
{
txEvents: this.txEvents,
}
)
console.log(tx)

Expand Down Expand Up @@ -207,10 +241,15 @@ class MyLoan extends React.Component<MyLoanProps, MyLoanState> {
tx = await approveAndPay(
paymentTokenInstance,
crowdloanInstance,
amountInERC20
amountInERC20,
{
txEvents: this.txEvents,
}
)
} else {
tx = await repay(crowdloanInstance, amountInERC20)
tx = await repay(crowdloanInstance, amountInERC20, {
txEvents: this.txEvents,
})
}

console.log(tx)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/crowdloan.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const totalRepaymentWithdrawn = instance =>
contractMethodCall(instance, 'totalRepaymentWithdrawn')

// Transactions
const startCrowdfund = instance =>
contractMethodTransaction(instance, 'startCrowdfund')
const startCrowdfund = (instance, txOptions) =>
contractMethodTransaction(instance, 'startCrowdfund', txOptions)
const fund = (instance, amount, txOptions) =>
contractMethodTransaction(instance, 'fund', amount, txOptions)
const withdrawPrincipal = (instance, amount, txOptions) =>
Expand Down
3 changes: 2 additions & 1 deletion src/utils/web3Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const contractMethodTransaction = async (contract, method, ...args) => {
let contractEvents = {}
let txOptions = {} //set default value for txOptions

txOptions = args[args.length - 1] || txOptions
txOptions = args[args.length - 1]
if (args.length > 0 && !txOptions) {
//remove UNDEFINED txOptions
args = args.slice(0, args.length - 1)
Expand All @@ -77,6 +77,7 @@ const contractMethodTransaction = async (contract, method, ...args) => {
!txOptions.gasPrice &&
!txOptions.txEvents)
) {
txOptions = {}
} else {
args = args.slice(0, args.length - 1) //remove txOptions from args array
}
Expand Down

0 comments on commit 0b5187e

Please sign in to comment.