Skip to content

Commit

Permalink
remove BigNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jan 14, 2024
1 parent 197a624 commit c94710b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions vue-app/src/stores/__tests__/store-app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers'
import { expect } from 'vitest'

import { setActivePinia, createPinia } from 'pinia'
Expand Down Expand Up @@ -96,7 +95,7 @@ describe('Cart mutations', () => {
const appStore = useAppStore()
const item1 = createItem({ id: '0x1' })
const item2 = createItem({ id: '0x2' })
appStore.$patch({ cart: [item1, item2], contribution: BigNumber.from(0) })
appStore.$patch({ cart: [item1, item2], contribution: BigInt(0) })
appStore.removeCartItem(item1)
expect(appStore.cart.length).to.equal(1)
expect(appStore.cart[0].id).to.equal(item2.id)
Expand All @@ -105,7 +104,7 @@ describe('Cart mutations', () => {
it('does not remove item that is not in cart', () => {
const appStore = useAppStore()
const item = createItem({ id: '0x1' })
appStore.$patch({ cart: [item], contribution: BigNumber.from(0) })
appStore.$patch({ cart: [item], contribution: BigInt(0) })
const newItem = createItem({ id: '0x2' })
expect(() => {
appStore.removeCartItem(newItem)
Expand All @@ -128,7 +127,7 @@ describe('Cart mutations', () => {
const appStore = useAppStore()
const item1 = createItem({ id: '0x1' })
const item2 = createItem({ id: '0x2' })
appStore.$patch({ cart: [item1, item2], contribution: BigNumber.from(1) })
appStore.$patch({ cart: [item1, item2], contribution: BigInt(1) })
appStore.removeCartItem(item1)
expect(appStore.cart.length).to.equal(2)
expect(appStore.cart[0].amount).to.equal('0')
Expand All @@ -148,7 +147,7 @@ describe('Cart mutations', () => {
const newItem2 = createItem({ id: '92' })
appStore.$patch({
cart: [...items, newItem1, newItem2],
contribution: BigNumber.from(1),
contribution: BigInt(1),
})
expect(appStore.cart.length).to.equal(MAX_CART_SIZE + 1)

Expand Down
6 changes: 3 additions & 3 deletions vue-app/src/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type AppState = {
cartEditModeSelected: boolean
committedCart: CartItem[]
cartLoaded: boolean
contribution: BigNumber | null
contribution: BigInt | null
contributor: Contributor | null
hasVoted: boolean
currentRound: RoundInfo | null
Expand Down Expand Up @@ -146,7 +146,7 @@ export const useAppStore = defineStore('app', {
},
hasUserContributed: (state): boolean => {
const userStore = useUserStore()
return !!userStore.currentUser && !!state.contribution && !state.contribution.isZero()
return !!userStore.currentUser && !!state.contribution && state.contribution !== BigInt(0)
},
operator: (): string => {
return operator
Expand Down Expand Up @@ -348,7 +348,7 @@ export const useAppStore = defineStore('app', {
throw new Error('item is not in the cart')
} else if (this.contribution === null) {
throw new Error('invalid operation')
} else if (this.contribution.isZero() || this.cart.length > MAX_CART_SIZE) {
} else if (this.contribution === BigInt(0) || this.cart.length > MAX_CART_SIZE) {
this.cart.splice(itemIndex, 1)
} else {
// The number of MACI messages can't go down after initial submission
Expand Down

0 comments on commit c94710b

Please sign in to comment.