Skip to content

Commit

Permalink
attempt to update formatter, with some wrong-handling of union types
Browse files Browse the repository at this point in the history
  • Loading branch information
yerdua committed Oct 2, 2023
1 parent 0cffb30 commit 5230db1
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/chains/celo/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export const formattersCelo = {
return {
...formatTransaction(transaction as RpcTransaction),
feeCurrency: transaction.feeCurrency,
gatewayFee: transaction.gatewayFee
? hexToBigInt(transaction.gatewayFee)
: null,
gatewayFeeRecipient: transaction.gatewayFeeRecipient,
...(transaction.type === '0x7b'
? {}
: {
gatewayFee: transaction.gatewayFee
? hexToBigInt(transaction.gatewayFee)
: null,
gatewayFeeRecipient: transaction.gatewayFeeRecipient,
}),
}
}) as Hash[] | CeloTransaction[]
return {
Expand All @@ -51,8 +55,12 @@ export const formattersCelo = {
format(args: CeloRpcTransaction): CeloTransaction {
return {
feeCurrency: args.feeCurrency,
gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
gatewayFeeRecipient: args.gatewayFeeRecipient,
...(args.type === '0x7b'
? {}
: {
gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
gatewayFeeRecipient: args.gatewayFeeRecipient,
}),
} as CeloTransaction
},
}),
Expand All @@ -67,18 +75,29 @@ export const formattersCelo = {
}
},
}),

// TODO: Figure out how to deal with the error here. gateway fields aren't on all
// types in the union type. Also the type indicator can be blank, so.... this is super ambiguous
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
const request = {
feeCurrency: args.feeCurrency,
gatewayFee:
typeof args.gatewayFee !== 'undefined'
? numberToHex(args.gatewayFee)
: undefined,
gatewayFeeRecipient: args.gatewayFeeRecipient,
// gatewayFee:
// typeof args.gatewayFee !== 'undefined'
// ? numberToHex(args.gatewayFee)
// : undefined,
// gatewayFeeRecipient: args.gatewayFeeRecipient,
} as CeloRpcTransactionRequest
if (args.type === 'cip42') request.type = '0x7c'

if (args.type === 'cip64') request.type = '0x7b'
if (args.type === 'cip42') request.type = '0x7c'

if (typeof args.gatewayFee !== 'undefined') {
request.gatewayFee = numberToHex(args.gatewayFee)
}
if (args.gatewayFeeRecipient) {
request.gatewayFeeRecipient = args.gatewayFeeRecipient
}
return request
},
}),
Expand Down

0 comments on commit 5230db1

Please sign in to comment.