Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

[KAVA] Stored CDP, HARD, incentive and auctions details in db #547

Open
wants to merge 25 commits into
base: kava
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update CDP
MonikaCat committed Jul 14, 2021
commit de852f2b7f52af13b6c69e938eeaf30355bc8716
35 changes: 32 additions & 3 deletions imports/api/cdp/server/methods.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,14 @@ Meteor.methods({
}
}

CDPCollection.upsert({}, { $set: { CDPList }});
try{
if(CDPList.length > 0){
CDPCollection.upsert({}, { $set: { CDPList } });
}
}
catch(e){
console.log("Error updating CDP list " + e)
}
return CDPList;
},
'cdp.parameters': function () {
@@ -80,8 +87,30 @@ Meteor.methods({

'cdp.fetchList': function () {
this.unblock();
let CDPList = CDPCollection.find().fetch();
return CDPList[0]
try{
let CDPList = CDPCollection.find().fetch();
return CDPList[0]
}
catch(e){
console.log(e)
}
},

//get Account CDP
'cdp.account': function (address, collateralType) {
this.unblock();

try{
let CDPList = CDPCollection.find().fetch();
let findCDP = CDPList[0].CDPList[collateralType]
for(let d in findCDP){
if (findCDP[d].cdp.owner === address){
return findCDP[d]
}
}
}
catch(e){
console.log(e)
}
}
})
45 changes: 15 additions & 30 deletions imports/ui/cdp/CDP.jsx
Original file line number Diff line number Diff line change
@@ -60,26 +60,21 @@ export default class CDP extends Component {
}

updateCDP() {
Meteor.call('accounts.getAccountCDP', this.props.owner, this.props.collateralType, (error, result) => {
Meteor.call('cdp.account', this.props.owner, this.props.collateralType, (error, result) => {
if (error) {
console.warn(error);
this.setState({
loading: true,
userCDP: null
})
}
if (result) {
else if (result) {
this.setState({
loading: false,
userCDP: result
})
}
if (result === null) {
this.setState({
loading: false,
userCDP: undefined
})
}

})
}

@@ -108,17 +103,8 @@ export default class CDP extends Component {
this.updateDeposits();
this.getUserBalances();

// timer = Meteor.setInterval(() => {
// this.updateCDP();
// this.updateDeposits();
// this.getUserBalances();
// }, 9000)

}

// componentWillUnmount() {
// Meteor.clearInterval(timer);
// }

componentDidUpdate(prevProps) {
if (!_.isEqual(prevProps.collateralType, this.props.collateralType)){
@@ -137,14 +123,13 @@ export default class CDP extends Component {
return totalValue
}

getCDPParams(denomType, valueToGet) {
let value = (this.props.collateralParams).find(({ denom }) => denom === denomType);
let totalValue = value ? value[valueToGet] : null;
if(totalValue >= 0){
return parseFloat(totalValue)
}
else{
return totalValue
getCollateralizationRatio(denomType) {
for (let c in this.props?.collateralParams){
if (this.props.collateralParams[c]?.type === denomType){
if (this.props.collateralParams[c]?.liquidation_ratio) {
return parseFloat(this.props.collateralParams[c]?.liquidation_ratio)
}
}
}
}

@@ -209,7 +194,7 @@ export default class CDP extends Component {
collateralDenom={this.props.collateralDenom ? this.props.collateralDenom : null}
principalDenom={this.state.userCDP ? this.state.userCDP.cdp.principal.denom : null}
principalDeposited={this.state.userCDP ? this.state.userCDP.cdp.principal.amount : null}
collateralizationRatio={this.getCDPParams(this.props.collateralDenom, 'liquidation_ratio') ?? null}
collateralizationRatio={this.getCollateralizationRatio(this.props.collateralDenom) ?? null}
/>
{((this.props.owner == this.props.user) || (this.state.isDepositor)) ? <WithdrawCDPButton
amountAvailable={this.state.total ? this.findTotalValue(this.state.total, this.props.collateralDenom) : null}
@@ -219,7 +204,7 @@ export default class CDP extends Component {
collateralDenom={this.props.collateralDenom ? this.props.collateralDenom : null}
principalDenom={this.state.userCDP ? this.state.userCDP.cdp.principal.denom : null}
principalDeposited={this.state.userCDP ? this.state.userCDP.cdp.principal.amount : null}
collateralizationRatio={this.getCDPParams(this.props.collateralDenom, 'liquidation_ratio') ?? null}
collateralizationRatio={this.getCollateralizationRatio(this.props.collateralDenom) ?? null}
isDepositor={this.state.isDepositor ? this.state.isDepositor : null}
/> : null}
{(this.props.owner == this.props.user) ? <DrawDebtCDPButton
@@ -229,7 +214,7 @@ export default class CDP extends Component {
collateralDenom={this.props.collateralDenom ? this.props.collateralDenom : null}
principalDenom={this.state.userCDP ? this.state.userCDP.cdp.principal.denom : null}
principalDeposited={this.state.userCDP ? this.state.userCDP.cdp.principal.amount : null}
collateralizationRatio={this.getCDPParams(this.props.collateralDenom, 'liquidation_ratio') ?? null}
collateralizationRatio={this.getCollateralizationRatio(this.props.collateralDenom) ?? null}
/> : null}

{(this.props.owner == this.props.user) ? <RepayDebtCDPButton
@@ -239,7 +224,7 @@ export default class CDP extends Component {
collateralDenom={this.props.collateralDenom ? this.props.collateralDenom : null}
principalDenom={this.state.userCDP ? this.state.userCDP.cdp.principal.denom : null}
principalDeposited={this.state.userCDP ? this.state.userCDP.cdp.principal.amount : null}
collateralizationRatio={this.getCDPParams(this.props.collateralDenom, 'liquidation_ratio') ?? null}
collateralizationRatio={this.getCollateralizationRatio(this.props.collateralDenom) ?? null}
disabled={!this.state.userCDP}
/> : null}
</div>
@@ -269,7 +254,7 @@ export default class CDP extends Component {
CDPParameters={this.props.collateralParams ?? null}
debtParams={this.props.debtParams ?? null}
collateralDenom={this.props.collateralDenom ? this.props.collateralDenom : null}
collateralizationRatio={this.getCDPParams(this.props.collateralDenom, 'liquidation_ratio') ?? null}
collateralizationRatio={this.getCollateralizationRatio(this.props.collateralDenom) ?? null}
/>
</div>
</div >
2 changes: 1 addition & 1 deletion imports/ui/cdp/List.jsx
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ export default class List extends Component {
this.setState({
cdpList: result?.CDPList[this.props.collateralType]?.length > 1 ? result.CDPList[this.props.collateralType].map((cdpList, i) => {
return <CDPRow key={i} index={i} cdpList={cdpList} />
}) : <CDPRow cdpList={result?.CDPList[this.props.collateralType][0]} />,
}) : result?.CDPList[this.props.collateralType]?.length === 0 ? <CDPRow cdpList={result?.CDPList[this.props.collateralType][0]} /> : null,
pagesCount: Math.ceil(result.length / this.state.pageSize),
currentPage: 1,
loading: false,