Skip to content

Commit 6442409

Browse files
committed
fix: revert some merge changes
1 parent 84d6b7f commit 6442409

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/structures/managers/TransactionManager.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { Transaction } from '../Transaction';
1212
import { Cache } from '../Cache';
1313
import { EventEmitter } from 'stream';
1414

15-
interface RawValueTransaction {
15+
interface ValueTransaction {
1616
recipient_s: string | string[];
1717
value: string | number | BigNumber;
1818
currencyCode: string;
1919
}
2020

21-
interface ValueTransaction {
21+
interface RawValueTransaction {
2222
recipient_s: string | string[];
2323
valueRaw: string | number | BigNumber;
2424
currencyCode: string;
@@ -32,7 +32,7 @@ interface Events {
3232
}
3333

3434
const isRawValueTransaction = (payload: any): payload is RawValueTransaction =>
35-
payload && payload.valueRaw;
35+
payload && typeof payload.valueRaw !== 'undefined';
3636

3737
export class TransactionManager extends EventEmitter {
3838
public client: TipccClient;
@@ -96,16 +96,23 @@ export class TransactionManager extends EventEmitter {
9696
const recipients = Array.isArray(payload.recipient_s)
9797
? payload.recipient_s
9898
: [payload.recipient_s];
99-
const value = BigNumber(
100-
isRawValueTransaction(payload) ? payload.value : payload.valueRaw,
101-
).toFixed(40);
102-
const currencyCode = payload.currencyCode;
99+
100+
const currency = await this.client.cryptos.fetch(payload.currencyCode);
101+
if (!currency) throw new Error('Invalid currency code.');
102+
103+
const value = (
104+
isRawValueTransaction(payload)
105+
? new BigNumber(payload.valueRaw)
106+
: new BigNumber(payload.value).shiftedBy(currency.format.scale)
107+
).toFixed(0);
103108

104109
const tx = (await this.client.REST.post(Routes.tips(), {
105-
recipients: recipients,
110+
...(Array.isArray(payload.recipient_s)
111+
? { recipients }
112+
: { recipient: recipients[0] }),
106113
amount: {
107114
value,
108-
currency: currencyCode,
115+
currency: currency.code,
109116
},
110117
service: 'discord',
111118
} as RESTPostAPITipBody)) as RESTPostAPITipResult;

0 commit comments

Comments
 (0)