Skip to content

Commit

Permalink
convert bignumber t bigfloat
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme committed May 1, 2021
1 parent e164740 commit f231737
Show file tree
Hide file tree
Showing 15 changed files with 10,184 additions and 61 deletions.
10 changes: 8 additions & 2 deletions contracts/Doneth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ contract Ownable {
contract Doneth is Ownable {
using SafeMath for uint256;

bool initiated;

// Name of the contract
string public name;

Expand Down Expand Up @@ -79,12 +81,16 @@ contract Doneth is Ownable {
uint256 totalWithdrawn;
}

function Doneth(string _contractName, string _founderName) {
function Doneth() {}

function init(string _contractName, string _founderName) {
require(!initiated, "ALREADY_INITATED");
initiated = true;
if (bytes(_contractName).length > 21) revert();
if (bytes(_founderName).length > 21) revert();
name = _contractName;
genesisBlockNumber = block.number;
addMember(msg.sender, 1, true, _founderName);
addMember(msg.origin, 1, true, _founderName);
}

event Deposit(address from, uint value);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@babel/plugin-transform-spread": "^7.13.0",
"axios": "^0.21.1",
"bignumber.js": "9.0.1",
"bigfloat.js": "^3.0.1",
"moment": "^2.29.1",
"solc": "^0.8.4",
"vue": "^2.5.2",
Expand Down
12 changes: 7 additions & 5 deletions src/components/AllocationBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</template>

<script>
import {BigFloat} from 'bigfloat.js'
const BN = BigFloat
import { mapGetters } from 'vuex'
export default {
Expand All @@ -29,15 +31,15 @@ export default {
return (member && member.address) ? `#${member.address.slice(-6)}` : '#CCCCCC'
},
percentage (member) {
let num = parseInt(this.totalShares, 10)
if (num === 0) {
let num = new BN(this.totalShares)
if (num.eq(0)) {
this.patrons.map((p) => {
if (p && p.shares && !isNaN(parseInt(p.shares, 10))) {
num += parseInt(p.shares, 10)
if (p && p.shares) {
num = num.plus(p.shares)
}
})
}
return ((parseInt(member.shares, 10) * 100) / num).toFixed(2)
return new BN(member.shares).mul(100).div(num).toString(2)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Contract.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
return this.$moment(value).format('dddd, MMMM Do YYYY')
},
getCreatedAt () {
if (!this.sortedLogs || this.sortedLogs.length <= 0 || !this.sortedLogs[0] || !this.sortedLogs[0].blockNumber) {
if (!this.sortedLogs || this.sortedLogs.length >= 0 || !this.sortedLogs[0] || !this.sortedLogs[0].blockNumber) {
// NOTE: Added only for demo so no missing data :/
this.timestamp = (+new Date())
return
Expand Down Expand Up @@ -202,7 +202,7 @@ export default {
flex-direction: row;
flex-wrap: wrap;
margin: 20px auto 30px;
width: 820px;
width: 1020px;
}
.patron-card,
Expand Down
8 changes: 6 additions & 2 deletions src/components/ExpenseAllocateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@

<script>
import UiModal from '@/components/UiModal'
import BN from 'bignumber.js'
import utils from 'web3-utils'
import { BigFloat } from "bigfloat.js";
const BN = BigFloat;
import { mapGetters, mapActions, mapMutations } from 'vuex'
export default {
Expand Down Expand Up @@ -97,7 +101,7 @@ export default {
this.allocateAmount = new BN(this.getFullAllowedAmount()).div(2).toString()
},
useMinAmount () {
this.allocateAmount = new BN('0.005').toFixed(3)
this.allocateAmount = new BN('0.005').toString()
},
closeModal (ref) {
this.setModal(false)
Expand Down
8 changes: 5 additions & 3 deletions src/components/ExpenseCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<script>
import GoalBar from '@/components/GoalBar'
import { mapGetters, mapActions } from 'vuex'
import BN from 'bignumber.js'
import { BigFloat } from "bigfloat.js";
const BN = BigFloat;
import Web3 from 'web3'
export default {
name: 'ExpenseCard',
Expand All @@ -36,7 +38,7 @@ export default {
return Web3.utils.fromWei(this.totalExpenseWithdrawn.toString())
},
totalExpenseWei () {
return Web3.utils.fromWei(new BN(this.totalExpense).minus(new BN(this.totalExpenseWithdrawn)).toString())
return Web3.utils.fromWei(new BN(this.totalExpense).sub(new BN(this.totalExpenseWithdrawn)).toString())
}
},
watch: {
Expand All @@ -48,7 +50,7 @@ export default {
...mapActions(['convertToCurrency']),
getConvertedTotal () {
if (!this.totalExpenseWei) return 0
return this.convertToCurrency(new BN(this.totalExpenseWei, 10).toFixed(2))
return this.convertToCurrency(new BN(this.totalExpenseWei, 10).toString(2))
}
},
components: {
Expand Down
15 changes: 9 additions & 6 deletions src/components/ExpenseWithdrawForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

<script>
import UiModal from '@/components/UiModal'
import BN from 'bignumber.js'
import { BigFloat } from "bigfloat.js";
import utils from 'web3-utils'
const BN = BigFloat;
import { mapGetters, mapActions, mapMutations } from 'vuex'
export default {
Expand Down Expand Up @@ -72,10 +75,10 @@ export default {
return 100
// let patron = this.members.find((p) => p.address.toLowerCase() === address.toLowerCase())
// if (!patron || !patron.allowedAmount) return 0
// return new BN(patron.allowedAmount).toFixed(4)
// return new BN(patron.allowedAmount).toString(4)
},
getFullAllowedAmount () {
return new BN(utils.fromWei(this.totalExpense.toString())).minus(this.totalExpenseWithdrawn)
return new BN(utils.fromWei(this.totalExpense.toString())).sub(this.totalExpenseWithdrawn)
},
isOverdrafted (patron, withdrawing) {
if (isNaN(withdrawing) || withdrawing === '') return false
Expand Down Expand Up @@ -115,13 +118,13 @@ export default {
}
},
useAllAmount () {
this.withdrawAmount = this.getFullAllowedAmount()
this.withdrawAmount = this.getFullAllowedAmount().toString()
},
useHalfAmount () {
this.withdrawAmount = new BN(this.getFullAllowedAmount() / 2 + '')
this.withdrawAmount = new BN(this.getFullAllowedAmount() / 2 + '').toString()
},
useMinAmount () {
this.withdrawAmount = new BN('0.005').toFixed(3)
this.withdrawAmount = new BN('0.005').toString()
},
closeModal (ref) {
this.setModal(false)
Expand Down
30 changes: 17 additions & 13 deletions src/components/PatronCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<span>Shares: <strong>{{patron.shares}}/{{totalShares}}</strong></span>
</div>
<div class="meta-item">
<span>Alloted: <strong>{{alloted(patron)}}</strong></span>
<span>Used: <strong>{{fromWei(patron.withdrawn) || 0}}</strong></span>
<span>Alloted: <strong>{{alloted}} ETH</strong></span>
<span>Used: <strong>{{fromWei(patron.withdrawn) || 0}} ETH</strong></span>
</div>
</div>

Expand All @@ -30,8 +30,12 @@
import ShortHash from '@/components/ShortHash'
import PatronWithdrawForm from '@/components/PatronWithdrawForm'
import { mapGetters, mapMutations } from 'vuex'
import BN from 'bignumber.js'
import utils from 'web3-utils'
import { BigFloat } from "bigfloat.js";
const BN = BigFloat;
export default {
name: 'PatronCard',
Expand All @@ -43,7 +47,15 @@ export default {
}
},
computed: {
...mapGetters(['account', 'totalShares', 'members', 'isAdmin', 'totalBalance', 'totalWithdrawn', 'totalExpense', 'totalExpenseWithdrawn', 'totalShares'])
...mapGetters(['account', 'totalShares', 'members', 'isAdmin', 'totalBalance', 'totalWithdrawn', 'totalExpense', 'totalExpenseWithdrawn', 'totalShares']),
alloted () {
return new BN(this.totalBalance.toString())
.add(this.fromWei(this.totalWithdrawn.toString()))
.sub(this.fromWei(this.totalExpense.toString()))
.add(this.fromWei(this.totalExpenseWithdrawn.toString()))
.div(this.totalShares.toString())
.mul(this.patron.shares.toString()).toString()
}
},
methods: {
...mapMutations({setModal: 'SET_MODAL', setEditMember: 'SET_EDIT_MEMBER'}),
Expand All @@ -55,18 +67,10 @@ export default {
fromWei (amount) {
return utils.fromWei(amount.toString())
},
alloted (patron) {
return new BN(this.totalBalance)
.plus(this.fromWei(this.totalWithdrawn))
.minus(this.fromWei(this.totalExpense))
.plus(this.totalExpenseWithdrawn)
.div(this.totalShares)
.times(patron.shares).toString()
},
getAllowedAmount (address) {
let patron = this.members.find((p) => p.address === address)
if (!patron || !patron.allowedAmount) return 0
return new BN(patron.allowedAmount).toFixed(4)
return new BN(patron.allowedAmount).toString()
},
firstName (patron) {
let initial = (patron && patron.memberName) ? patron.memberName.substring(0, 2) : '0x'
Expand Down
20 changes: 12 additions & 8 deletions src/components/PatronWithdrawForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@

<script>
import UiModal from '@/components/UiModal'
import BN from 'bignumber.js'
import utils from 'web3-utils'
import { BigFloat } from "bigfloat.js";
const BN = BigFloat;
import { mapGetters, mapActions, mapMutations } from 'vuex'
export default {
Expand All @@ -66,7 +70,9 @@ export default {
...mapGetters(['account', 'members', 'conversions', 'currency'])
},
watch: {
withdrawAmount () {
withdrawAmount (new_, old) {
console.log({old, new_})
console.log(new_.toString())
this.updateConversion()
},
currency () {
Expand All @@ -79,7 +85,7 @@ export default {
getAllowedAmount (address) {
let patron = this.members.find((p) => p.address.toLowerCase() === address.toLowerCase())
if (!patron || !patron.allowedAmount) return 0
return new BN(patron.allowedAmount).toFixed(4)
return new BN(patron.allowedAmount).toString()
},
getFullAllowedAmount (address) {
let patron = this.members.find((p) => p.address.toLowerCase() === address.toLowerCase())
Expand Down Expand Up @@ -111,8 +117,6 @@ export default {
this.withdrawer = null
},
withdraw (patron) {
console.log('withdraw')
console.log(this.withdrawAmount)
if (this.withdrawAmount) {
this.withdrawer = patron.address
this.submitting = true
Expand All @@ -127,13 +131,13 @@ export default {
}
},
useAllAmount () {
this.withdrawAmount = this.getFullAllowedAmount(this.patron.address)
this.withdrawAmount = this.getFullAllowedAmount(this.patron.address).toString()
},
useHalfAmount () {
this.withdrawAmount = new BN(this.getFullAllowedAmount(this.patron.address) / 2 + '')
this.withdrawAmount = new BN(this.getFullAllowedAmount(this.patron.address) / 2 + '').toString()
},
useMinAmount () {
this.withdrawAmount = new BN('0.005').toFixed(3)
this.withdrawAmount = '0.005'
},
openModal (ref) {
this.userAddress = this.patron.address
Expand Down
5 changes: 4 additions & 1 deletion src/components/TransactionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@

<script>
import ShortHash from '@/components/ShortHash'
import BN from 'bignumber.js'
import { mapGetters } from 'vuex'
import utils from 'web3-utils'
import { BigFloat } from "bigfloat.js";
const BN = BigFloat;
export default {
name: 'TransactionsList',
Expand Down
2 changes: 1 addition & 1 deletion src/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $lightgrey: #a7a7a7 !default;
$border-radius: 3px !default;

// Page stuffs
$page-content-width: 800px !default;
$page-content-width: 1000px !default;
Loading

0 comments on commit f231737

Please sign in to comment.