Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support transaction null status #189

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions src/stores/TxStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ class TxStore {

async getTxStatus(hash) {
const web3 = this.web3Store.injectedWeb3;
const { toBN } = web3.utils
web3.eth.getTransactionReceipt(hash, (error, res) => {
if(res && res.blockNumber){
if(res.status === true || toBN(res.status).eq(toBN(1))){
if(this.isStatusSuccess(res)){
if(this.web3Store.metamaskNet.id === this.web3Store.homeNet.id.toString()) {
const blockConfirmations = this.homeStore.latestBlockNumber - res.blockNumber
if(blockConfirmations >= 8) {
Expand Down Expand Up @@ -175,6 +174,13 @@ class TxStore {
})
}

isStatusSuccess(tx) {
const { toBN } = this.web3Store.injectedWeb3.utils
const statusSuccess = tx.status && (tx.status === true || toBN(tx.status).eq(toBN(1)))
const eventEmitted = tx.logs && tx.logs.length
return statusSuccess || eventEmitted
}

}

export default TxStore;
97 changes: 97 additions & 0 deletions src/stores/__tests__/TxStore.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import TxStore from '../TxStore'
import Web3 from 'web3'

describe('TxStore', function () {
let txStore
beforeEach(() => {
const rootStore = {
web3Store: {
injectedWeb3: new Web3()
}
}
txStore = new TxStore(rootStore)
})
describe('isStatusSuccess', function () {
it('should return true if status field is 0x1', () => {
// Given
const tx = {
status: '0x1',
logs: []
}

// When
const result = txStore.isStatusSuccess(tx)

// Then
expect(result).toBeTruthy()
})
it('should return false if status field is 0x0', () => {
// Given
const tx = {
status: '0x0',
logs: []
}

// When
const result = txStore.isStatusSuccess(tx)

// Then
expect(result).toBeFalsy()
})
it('should work if status field is boolean', () => {
// Given
const tx = {
status: false,
logs: []
}
const tx2 = {
status: true,
logs: []
}

// When
const result = txStore.isStatusSuccess(tx)
const result2 = txStore.isStatusSuccess(tx2)

// Then
expect(result).toBeFalsy()
expect(result2).toBeTruthy()
})
it('should return true if status field not present and logs length > 0', () => {
// Given
const tx = {
logs: [
{}
]
}

// When
const result = txStore.isStatusSuccess(tx)

// Then
expect(result).toBeTruthy()
})
it('should return false if status field not present and no logs', () => {
// Given
const tx = {
logs: []
}

// When
const result = txStore.isStatusSuccess(tx)

// Then
expect(result).toBeFalsy()
})
it('should return false if status field not present and logs field not present', () => {
// Given
const tx = {}

// When
const result = txStore.isStatusSuccess(tx)

// Then
expect(result).toBeFalsy()
})
})
})