@@ -2,11 +2,12 @@ import _ from 'lodash';
22import { EventEmitter } from 'events' ;
33import { types } from '@polymathnetwork/new-shared' ;
44import { PostTransactionResolver } from '~/PostTransactionResolver' ;
5- import { TransactionSpec , ErrorCodes } from '~/types' ;
5+ import { TransactionSpec , ErrorCodes , DividendModuleTypes } from '~/types' ;
66import { PolymathError } from '~/PolymathError' ;
77import { TransactionReceipt } from 'web3/types' ;
88import { Entity } from '~/entities/Entity' ;
99import { TransactionQueue } from '~/entities/TransactionQueue' ;
10+ import BigNumber from 'bignumber.js' ;
1011
1112// @TODO RafaelVidaurre: Decide where this should go
1213const descriptionsByTag : {
@@ -83,7 +84,6 @@ export class PolyTransaction extends Entity {
8384 tag,
8485 receipt,
8586 error,
86- args,
8787 description,
8888 txHash,
8989 transactionQueue,
@@ -99,7 +99,7 @@ export class PolyTransaction extends Entity {
9999 txHash,
100100 receipt,
101101 error,
102- args,
102+ args : this . argsToObject ( ) ,
103103 } ;
104104 }
105105
@@ -214,4 +214,148 @@ export class PolyTransaction extends Entity {
214214 : this . unwrapArg ( arg ) ;
215215 } ) ;
216216 }
217+
218+ /**
219+ * Transforms the transaction arguments to an object depending
220+ * on the transaction type
221+ *
222+ * NOTE @monitz87: this is done so that the transaction modal has access
223+ * to named properties. This is a temporary solution. A proper solution would be to
224+ * create a class for each transaction type with its own toPojo method that exposes
225+ * the arguments as an object
226+ */
227+ private argsToObject ( ) {
228+ const { tag, args } = this ;
229+
230+ switch ( tag ) {
231+ case types . PolyTransactionTags . Approve : {
232+ const [ spender , amount ] = args as [ string , BigNumber ] ;
233+
234+ return {
235+ spender,
236+ amount,
237+ } ;
238+ }
239+ case types . PolyTransactionTags . CreateErc20DividendDistribution : {
240+ const [
241+ maturityDate ,
242+ expiryDate ,
243+ erc20Address ,
244+ amount ,
245+ checkpointId ,
246+ name ,
247+ excludedAddresses ,
248+ ] = args as [
249+ Date ,
250+ Date ,
251+ string ,
252+ BigNumber ,
253+ number ,
254+ string ,
255+ string [ ] | undefined
256+ ] ;
257+
258+ return {
259+ maturityDate,
260+ expiryDate,
261+ erc20Address,
262+ amount,
263+ checkpointId,
264+ name,
265+ excludedAddresses,
266+ } ;
267+ }
268+ case types . PolyTransactionTags . CreateEtherDividendDistribution : {
269+ const [
270+ maturityDate ,
271+ expiryDate ,
272+ amount ,
273+ checkpointId ,
274+ name ,
275+ excludedAddresses ,
276+ ] = args as [
277+ Date ,
278+ Date ,
279+ BigNumber ,
280+ number ,
281+ string ,
282+ string [ ] | undefined
283+ ] ;
284+
285+ return {
286+ maturityDate,
287+ expiryDate,
288+ amount,
289+ checkpointId,
290+ name,
291+ excludedAddresses,
292+ } ;
293+ }
294+ case types . PolyTransactionTags . CreateSecurityToken : {
295+ const [ name , symbol , detailsUrl , divisible ] = args as [
296+ string ,
297+ string ,
298+ string ,
299+ boolean
300+ ] ;
301+
302+ return {
303+ name,
304+ symbol,
305+ detailsUrl,
306+ divisible,
307+ } ;
308+ }
309+ case types . PolyTransactionTags . EnableDividends : {
310+ const [ type , storageWalletAddress ] = args as [
311+ DividendModuleTypes ,
312+ string
313+ ] ;
314+
315+ return {
316+ type,
317+ storageWalletAddress,
318+ } ;
319+ }
320+ case types . PolyTransactionTags . GetTokens : {
321+ const [ amount , beneficiaryAddress ] = args as [ BigNumber , string ] ;
322+
323+ return {
324+ amount,
325+ beneficiaryAddress,
326+ } ;
327+ }
328+ case types . PolyTransactionTags . ReclaimDividendFunds :
329+ case types . PolyTransactionTags . WithdrawTaxWithholdings : {
330+ const [ dividendIndex ] = args as [ number ] ;
331+
332+ return {
333+ dividendIndex,
334+ } ;
335+ }
336+ case types . PolyTransactionTags . ReserveSecurityToken : {
337+ const [ ownerAddress , symbol , name ] = args as [ string , string , string ] ;
338+
339+ return {
340+ ownerAddress,
341+ symbol,
342+ name,
343+ } ;
344+ }
345+ case types . PolyTransactionTags . SetErc20TaxWithholding :
346+ case types . PolyTransactionTags . SetEtherTaxWithholding : {
347+ const [ investorAddresses , percentages ] = args as [ string [ ] , number [ ] ] ;
348+
349+ return {
350+ investorAddresses,
351+ percentages,
352+ } ;
353+ }
354+ case types . PolyTransactionTags . CreateCheckpoint :
355+ case types . PolyTransactionTags . Any :
356+ default : {
357+ return { } ;
358+ }
359+ }
360+ }
217361}
0 commit comments