44 type FetchResult ,
55} from '@apollo/client' ;
66import { type ClientTypeTokens } from '@colony/colony-js' ;
7- import { utils } from 'ethers' ;
7+ import { utils , BigNumber } from 'ethers' ;
88import { useMemo } from 'react' ;
99
1010import { useAppContext } from '~context/AppContext/AppContext.ts' ;
@@ -75,6 +75,22 @@ export const convertTransactionType = ({
7575 titleValues : group . titleValues ? JSON . parse ( group . titleValues ) : undefined ,
7676 } ;
7777
78+ const convertedParams = JSON . parse ( params ?? '[]' ) . map ( ( param ) => {
79+ // @NOTE Try to convert BigNumber params back to Ethers BigNumber
80+ //
81+ // When the transaction gets saved in the database, the BigNumber objects get stringified
82+ // meaning it will loose its BigNumber properties and prototypes
83+ // Converting it back will create an Object shaped like a BigNumber, but it won't have the prototype, hence
84+ // it won't be a proper BigNumber object, and won't have the methods like add, sub, etc.
85+ //
86+ // Here we're trying to convert it back to a Ethers BigNumber object by "trying to be smart" and checking if
87+ // the object has a "tyhpe" property, with the value "BigNumber" (which is what Ethers uses), as well as a "hex" property
88+ if ( param ?. type === 'BigNumber' && param ?. hex ) {
89+ return BigNumber . from ( param ) ;
90+ }
91+ return param ;
92+ } ) ;
93+
7894 return {
7995 context : context as ClientTypeTokens | ExtendedClientType ,
8096 createdAt : new Date ( createdAt ) ,
@@ -88,7 +104,7 @@ export const convertTransactionType = ({
88104 groupId,
89105 hash : hash || '0x0' ,
90106 methodContext : methodContext ?? undefined ,
91- params : JSON . parse ( params ?? '[]' ) ,
107+ params : convertedParams ,
92108 title : title ? JSON . parse ( title ) : undefined ,
93109 titleValues : titleValues ? JSON . parse ( titleValues ) : undefined ,
94110 options : options ? JSON . parse ( options ) : undefined ,
0 commit comments