fix(generateBurnOpReturn): Added handler when burning amount is higher than token amount

This commit is contained in:
Gary Nadir
2021-01-16 14:22:02 -04:00
parent 2472dc3606
commit aef56c5c14
2 changed files with 8 additions and 3 deletions
+6 -1
View File
@@ -220,7 +220,12 @@ class TokenType1 {
// Calculate the total amount of tokens owned by the wallet.
let totalTokens = 0
for (let i = 0; i < tokenUtxos.length; i++) {
totalTokens += tokenUtxos[i].tokenQty
totalTokens += parseFloat(tokenUtxos[i].tokenQty)
}
// Make sure burn quantity isn't bigger than the total amount in tokens
if (burnQty > totalTokens) {
burnQty = totalTokens
}
const remainder = totalTokens - burnQty
+2 -2
View File
@@ -1217,11 +1217,11 @@ describe('#SLP TokenType1', () => {
tokenDocumentUrl: '',
tokenDocumentHash: '',
decimals: 8,
tokenQty: 7
tokenQty: '7'
}
]
const result = bchjs.SLP.TokenType1.generateBurnOpReturn(tokenUtxos, 1)
const result = bchjs.SLP.TokenType1.generateBurnOpReturn(tokenUtxos, 8)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
// console.log(`result: `, result)