-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new lock helper to provide accompanying transaction and confir…
…mations (#253) * Adding new lock helper to provide accompanying transaction and confirmations * Linting fixes * Fixing tests
- Loading branch information
Showing
4 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { getLockTransaction, getLockConfirmations } from '../../helpers/Locks' | ||
|
||
describe('lockHelpers', () => { | ||
it ('should retrieve a transaction from a lock when a match exists', () => { | ||
const Lock = { | ||
address: '0x1234567890', | ||
} | ||
const transactions = { | ||
all: { | ||
notTheTransactionWereLookingFor: { | ||
hash: 'notTheTransactionWereLookingFor', | ||
confirmations: 24, | ||
lock: { | ||
address: '0x0987654321', | ||
}, | ||
}, | ||
theTransactionWereLookingFor: { | ||
hash: 'theTransactionWereLookingFor', | ||
confirmations: 12, | ||
lock: { | ||
address: '0x1234567890', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
expect(getLockTransaction(transactions, Lock.address).hash).toEqual('theTransactionWereLookingFor') | ||
}) | ||
it ('should not retrieve a transaction from a lock when no match exists', () => { | ||
const Lock = { | ||
address: '0x9999999999', | ||
} | ||
const transactions = { | ||
all: { | ||
notTheTransactionWereLookingFor: { | ||
hash: 'notTheTransactionWereLookingFor', | ||
confirmations: 24, | ||
lock: { | ||
address: '0x0987654321', | ||
}, | ||
}, | ||
theTransactionWereLookingFor: { | ||
hash: 'theTransactionWereLookingFor', | ||
confirmations: 12, | ||
lock: { | ||
address: '0x1234567890', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
expect(getLockTransaction(transactions, Lock.address)).toEqual(null) | ||
}) | ||
it ('should retrieve confirmations from a lock when a match exists', () => { | ||
const Lock = { | ||
address: '0x1234567890', | ||
} | ||
const transactions = { | ||
all: { | ||
notTheTransactionWereLookingFor: { | ||
hash: 'notTheTransactionWereLookingFor', | ||
confirmations: 24, | ||
lock: { | ||
address: '0x0987654321', | ||
}, | ||
}, | ||
theTransactionWereLookingFor: { | ||
hash: 'theTransactionWereLookingFor', | ||
confirmations: 12, | ||
lock: { | ||
address: '0x1234567890', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
expect(getLockConfirmations(transactions, Lock.address)).toEqual(12) | ||
}) | ||
it ('should retrieve no confirmations from a lock when no match exists', () => { | ||
const Lock = { | ||
address: '0x99999999999', | ||
} | ||
const transactions = { | ||
all: { | ||
notTheTransactionWereLookingFor: { | ||
hash: 'notTheTransactionWereLookingFor', | ||
confirmations: 24, | ||
lock: { | ||
address: '0x0987654321', | ||
}, | ||
}, | ||
theTransactionWereLookingFor: { | ||
hash: 'theTransactionWereLookingFor', | ||
confirmations: 12, | ||
lock: { | ||
address: '0x1234567890', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
expect(getLockConfirmations(transactions, Lock.address)).toEqual(null) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Given the address of a lock, returns its accompanying transaction | ||
* @param transactionStore | ||
* @param lockAddress | ||
* @returns {object} | ||
*/ | ||
export function getLockTransaction(transactionStore, lockAddress) { | ||
if (transactionStore && transactionStore.all) { | ||
for (let transaction in transactionStore.all) { | ||
let transactionObject = transactionStore.all[transaction] | ||
if (transactionObject.lock && transactionObject.lock.address === lockAddress) | ||
return transactionObject | ||
} | ||
} | ||
return null | ||
} | ||
|
||
/** | ||
* Given the address of a lock, returns the number of confirmations it has received | ||
* @param transactionStore | ||
* @param lockAddress | ||
* @returns {number} | ||
*/ | ||
export function getLockConfirmations(transactionStore, lockAddress) { | ||
let transaction = getLockTransaction(transactionStore, lockAddress) | ||
if (transaction) return transaction.confirmations | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters