Page MenuHomePhabricator

D8601.id26183.diff
No OneTemporary

D8601.id26183.diff

diff --git a/web/cashtab/src/components/Send/SendToken.js b/web/cashtab/src/components/Send/SendToken.js
--- a/web/cashtab/src/components/Send/SendToken.js
+++ b/web/cashtab/src/components/Send/SendToken.js
@@ -4,7 +4,7 @@
import { CashSpin, CashSpinIcon } from '../Common/CustomSpinner';
import { Row, Col } from 'antd';
import Paragraph from 'antd/lib/typography/Paragraph';
-import { SecondaryButton } from '../Common/PrimaryButton';
+import PrimaryButton, { SecondaryButton } from '../Common/PrimaryButton';
import { CashLoader } from '../Common/CustomIcons';
import {
FormItemWithMaxAddon,
@@ -285,9 +285,11 @@
{apiError && <CashLoader />}
</>
) : (
- <SecondaryButton>
+ <PrimaryButton
+ onClick={() => submit()}
+ >
Send {token.info.tokenName}
- </SecondaryButton>
+ </PrimaryButton>
)}
</div>
{apiError && (
diff --git a/web/cashtab/src/hooks/useBCH.js b/web/cashtab/src/hooks/useBCH.js
--- a/web/cashtab/src/hooks/useBCH.js
+++ b/web/cashtab/src/hooks/useBCH.js
@@ -287,9 +287,7 @@
let tokenUtxosBeingSpent = [];
for (let i = 0; i < tokenUtxos.length; i++) {
finalTokenAmountSent = finalTokenAmountSent.plus(
- new BigNumber(tokenUtxos[i].tokenQty).div(
- Math.pow(10, tokenUtxos[i].decimals),
- ),
+ new BigNumber(tokenUtxos[i].tokenQty),
);
transactionBuilder.addInput(
tokenUtxos[i].tx_hash,
@@ -301,6 +299,27 @@
}
}
+ // Debug logging
+ console.log(
+ `string finalTokenAmountSent`,
+ finalTokenAmountSent.toString(),
+ );
+ console.log(
+ `string tokenAmount`,
+ tokenAmountBeingSentToAddress.toString(),
+ );
+
+ // Just in case -- make sure you are not sending more than your balance
+ if (finalTokenAmountSent.lt(tokenAmountBeingSentToAddress)) {
+ console.log(`Error: Trying to send more than your balance`);
+ throw new Error(
+ 'You are attempting to send more than your balance!',
+ );
+ }
+ // Debug logging
+ if (finalTokenAmountSent.eq(tokenAmountBeingSentToAddress)) {
+ console.log(`Sending your full token balance`);
+ }
// Run a test function to mock the outputs generated by BCH.SLP.TokenType1.generateSendOpReturn below
slpDebug(
tokenUtxosBeingSpent,
@@ -395,22 +414,29 @@
// END transaction construction.
- // Broadcast transaction to the network
-
- const txidStr = await BCH.RawTransactions.sendRawTransaction([hex]);
- if (txidStr && txidStr[0]) {
- console.log(`${currency.tokenTicker} txid`, txidStr[0]);
- }
+ // Broadcast transaction to the network if debugSlpa mode is false
+ const debugSlpa = false;
- let link;
- if (process.env.REACT_APP_NETWORK === `mainnet`) {
- link = `${currency.blockExplorerUrl}/tx/${txidStr}`;
+ if (debugSlpa) {
+ console.log(`RawTx Hex`, hex);
+ return hex;
} else {
- link = `${currency.blockExplorerUrlTestnet}/tx/${txidStr}`;
- }
- //console.log(`link`, link);
+ const txidStr = await BCH.RawTransactions.sendRawTransaction([hex]);
+ if (txidStr && txidStr[0]) {
+ console.log(`${currency.tokenTicker} txid`, txidStr[0]);
+ }
- return link;
+ let link;
+ if (process.env.REACT_APP_NETWORK === `mainnet`) {
+ link = `${currency.blockExplorerUrl}/tx/${txidStr}`;
+ } else {
+ link = `${currency.blockExplorerUrlTestnet}/tx/${txidStr}`;
+ }
+
+ //console.log(`link`, link);
+
+ return link;
+ }
};
const slpDebug = (tokenUtxos, sendQty) => {
diff --git a/web/cashtab/src/hooks/useWallet.js b/web/cashtab/src/hooks/useWallet.js
--- a/web/cashtab/src/hooks/useWallet.js
+++ b/web/cashtab/src/hooks/useWallet.js
@@ -664,25 +664,29 @@
tokens[receivedTokenObjectIndex].info.tokenName;
//console.log(`receivedSlpQty`, receivedSlpQty);
- // Notification
- notification.success({
- message: `SLP Transaction received: ${receivedSlpTicker}`,
- description: (
- <Paragraph>
- You received {receivedSlpQty} {receivedSlpName}
- </Paragraph>
- ),
- duration: 5,
- });
+ // Notification if you received SLP
+ if (receivedSlpQty > 0) {
+ notification.success({
+ message: `${currency.tokenTicker} Transaction received: ${receivedSlpTicker}`,
+ description: (
+ <Paragraph>
+ You received {receivedSlpQty} {receivedSlpName}
+ </Paragraph>
+ ),
+ duration: 5,
+ });
+ }
//
} else {
// 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) {
- if (tokens[i].balance > previousTokens[i].balance) {
+ if (tokens[i].balance.gt(previousTokens[i].balance)) {
// Received this token
// console.log(`previousTokenId`, previousTokens[i].tokenId);
// console.log(`currentTokenId`, tokens[i].tokenId);
+
if (previousTokens[i].tokenId !== tokens[i].tokenId) {
console.log(
`TokenIds do not match, breaking from SLP notifications`,
@@ -691,10 +695,10 @@
// Also don't 'continue' ; this means you have sent a token, just stop iterating through
break;
}
- const receivedSlpDecimals = tokens[i].info.decimals;
- const receivedSlpQty = (
- tokens[i].balance - previousTokens[i].balance
- ).toFixed(receivedSlpDecimals);
+ const receivedSlpQty = tokens[i].balance.minus(
+ previousTokens[i].balance,
+ );
+
const receivedSlpTicker = tokens[i].info.tokenTicker;
const receivedSlpName = tokens[i].info.tokenName;
@@ -702,7 +706,8 @@
message: `SLP Transaction received: ${receivedSlpTicker}`,
description: (
<Paragraph>
- You received {receivedSlpQty} {receivedSlpName}
+ You received {receivedSlpQty.toString()}{' '}
+ {receivedSlpName}
</Paragraph>
),
duration: 5,

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 19:13 (3 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865761
Default Alt Text
D8601.id26183.diff (7 KB)

Event Timeline