Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show First 20 Lines • Show All 658 Lines • ▼ Show 20 Lines | ) { | ||||
receivedTokenObjectIndex | receivedTokenObjectIndex | ||||
].balance.toString(); | ].balance.toString(); | ||||
const receivedSlpTicker = | const receivedSlpTicker = | ||||
tokens[receivedTokenObjectIndex].info.tokenTicker; | tokens[receivedTokenObjectIndex].info.tokenTicker; | ||||
const receivedSlpName = | const receivedSlpName = | ||||
tokens[receivedTokenObjectIndex].info.tokenName; | tokens[receivedTokenObjectIndex].info.tokenName; | ||||
//console.log(`receivedSlpQty`, receivedSlpQty); | //console.log(`receivedSlpQty`, receivedSlpQty); | ||||
// Notification | // Notification if you received SLP | ||||
if (receivedSlpQty > 0) { | |||||
notification.success({ | notification.success({ | ||||
message: `SLP Transaction received: ${receivedSlpTicker}`, | message: `${currency.tokenTicker} Transaction received: ${receivedSlpTicker}`, | ||||
description: ( | description: ( | ||||
<Paragraph> | <Paragraph> | ||||
You received {receivedSlpQty} {receivedSlpName} | You received {receivedSlpQty} {receivedSlpName} | ||||
</Paragraph> | </Paragraph> | ||||
), | ), | ||||
duration: 5, | duration: 5, | ||||
}); | }); | ||||
} | |||||
// | // | ||||
} else { | } else { | ||||
// If tokens[i].balance > previousTokens[i].balance, a new SLP tx of an existing token has been received | // If tokens[i].balance > previousTokens[i].balance, a new SLP tx of an existing token has been received | ||||
// Note that tokens[i].balance is of type BigNumber | |||||
for (let i = 0; i < tokens.length; i += 1) { | for (let i = 0; i < tokens.length; i += 1) { | ||||
if (tokens[i].balance > previousTokens[i].balance) { | if (tokens[i].balance.gt(previousTokens[i].balance)) { | ||||
// Received this token | // Received this token | ||||
// console.log(`previousTokenId`, previousTokens[i].tokenId); | // console.log(`previousTokenId`, previousTokens[i].tokenId); | ||||
// console.log(`currentTokenId`, tokens[i].tokenId); | // console.log(`currentTokenId`, tokens[i].tokenId); | ||||
if (previousTokens[i].tokenId !== tokens[i].tokenId) { | if (previousTokens[i].tokenId !== tokens[i].tokenId) { | ||||
console.log( | console.log( | ||||
`TokenIds do not match, breaking from SLP notifications`, | `TokenIds do not match, breaking from SLP notifications`, | ||||
); | ); | ||||
// Then don't send the notification | // Then don't send the notification | ||||
// Also don't 'continue' ; this means you have sent a token, just stop iterating through | // Also don't 'continue' ; this means you have sent a token, just stop iterating through | ||||
break; | break; | ||||
} | } | ||||
const receivedSlpDecimals = tokens[i].info.decimals; | const receivedSlpQty = tokens[i].balance.minus( | ||||
const receivedSlpQty = ( | previousTokens[i].balance, | ||||
tokens[i].balance - previousTokens[i].balance | ); | ||||
).toFixed(receivedSlpDecimals); | |||||
const receivedSlpTicker = tokens[i].info.tokenTicker; | const receivedSlpTicker = tokens[i].info.tokenTicker; | ||||
const receivedSlpName = tokens[i].info.tokenName; | const receivedSlpName = tokens[i].info.tokenName; | ||||
notification.success({ | notification.success({ | ||||
message: `SLP Transaction received: ${receivedSlpTicker}`, | message: `SLP Transaction received: ${receivedSlpTicker}`, | ||||
description: ( | description: ( | ||||
<Paragraph> | <Paragraph> | ||||
You received {receivedSlpQty} {receivedSlpName} | You received {receivedSlpQty.toString()}{' '} | ||||
{receivedSlpName} | |||||
</Paragraph> | </Paragraph> | ||||
), | ), | ||||
duration: 5, | duration: 5, | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 386 Lines • Show Last 20 Lines |