Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Oct 31, 2023
1 parent ed70912 commit ee5e99a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/chains/celo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type CeloTransactionRequest =
export type CeloTransactionSerializable =
| TransactionSerializableCIP42
| TransactionSerializableCIP64
| TransactionSerializable
| CeloTransactionSerializableBase

export type CeloTransactionSerialized<
TType extends CeloTransactionType = 'legacy',
Expand Down Expand Up @@ -247,9 +247,17 @@ export type TransactionSerializableCIP64<
FeeValuesEIP1559<TQuantity> & {
accessList?: AccessList
feeCurrency?: Address
gatewayFee?: undefined
gatewayFeeRecipient?: undefined
chainId: number
type?: 'cip64'
}

export type CeloTransactionSerializableBase = TransactionSerializable & {
feeCurrency?: undefined
gatewayFee?: undefined
gatewayFeeRecipient?: undefined
}

export type TransactionSerializedCIP42 = `0x7c${string}`
export type TransactionSerializedCIP64 = `0x7b${string}`
22 changes: 8 additions & 14 deletions src/chains/celo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,31 @@ export function isEIP1559(
export function isCIP42(
transaction: CeloTransactionSerializable | CeloTransactionRequest,
): transaction is TransactionSerializableCIP42 {
const tx = transaction as TransactionSerializableCIP42

// Enable end-user to force the tx to be considered as a cip42
if (tx.type === 'cip42') {
if (transaction.type === 'cip42') {
return true
}

return (
isEIP1559(transaction) &&
(isPresent(tx.feeCurrency) ||
isPresent(tx.gatewayFeeRecipient) ||
isPresent(tx.gatewayFee))
(isPresent(transaction.feeCurrency) ||
isPresent(transaction.gatewayFeeRecipient) ||
isPresent(transaction.gatewayFee))
)
}

export function isCIP64(
transaction: CeloTransactionSerializable | CeloTransactionRequest,
): transaction is TransactionSerializableCIP64 {
const tx = transaction as TransactionSerializableCIP64

// Enable end-user to force the tx to be considered as a cip64
if (tx.type === 'cip64') {
if (transaction.type === 'cip64') {
return true
}

return (
isEIP1559(transaction) &&
isPresent(tx.feeCurrency) &&
// @ts-expect-error Property 'gatewayFee' does not exist on type 'TransactionSerializableCIP64'
isEmpty(tx.gatewayFee) &&
// @ts-expect-error Property 'gatewayFeeRecipient' does not exist on type 'TransactionSerializableCIP64'
isEmpty(tx.gatewayFeeRecipient)
isPresent(transaction.feeCurrency) &&
isEmpty(transaction.gatewayFee) &&
isEmpty(transaction.gatewayFeeRecipient)
)
}

0 comments on commit ee5e99a

Please sign in to comment.