Skip to content

Commit

Permalink
refactor(send): execute prepared transaction in saga (valora-inc#5001)
Browse files Browse the repository at this point in the history
### Description

Execute prepared tx directly in the send saga instead of using the
viem/saga's send payment method, which was simulating a contract call
and then executing it.

### Test plan

Manual, CI

### Related issues

- Fixes ACT-1049

### Backwards compatibility

Yes

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [X] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
satish-ravi authored and shottah committed May 15, 2024
1 parent 47ae779 commit 68edf25
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 1,521 deletions.
20 changes: 8 additions & 12 deletions src/fiatExchanges/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from 'src/transactions/types'
import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import { SerializableTransactionRequest } from 'src/viem/preparedTransactionSerialization'
import {
mockAccount,
mockCeurAddress,
Expand All @@ -37,6 +38,11 @@ const now = Date.now()
Date.now = jest.fn(() => now)

const loggerErrorSpy = jest.spyOn(Logger, 'error')
const mockPreparedTransaction: SerializableTransactionRequest = {
from: '0xfrom',
to: '0xto',
data: '0xdata',
}

describe(watchBidaliPaymentRequests, () => {
const amount = new BigNumber(20)
Expand Down Expand Up @@ -97,12 +103,7 @@ describe(watchBidaliPaymentRequests, () => {
'Some description (TEST_CHARGE_ID)',
recipient,
true,
{
fee: new BigNumber('0.01'),
gas: new BigNumber('0.01'),
gasPrice: new BigNumber('0.01'),
feeCurrency: expectedCurrency,
}
mockPreparedTransaction
)
)
.dispatch(sendPaymentSuccess({ amount, tokenId: expectedTokenId }))
Expand Down Expand Up @@ -157,12 +158,7 @@ describe(watchBidaliPaymentRequests, () => {
'Some description (TEST_CHARGE_ID)',
recipient,
true,
{
fee: new BigNumber('0.01'),
gas: new BigNumber('0.01'),
gasPrice: new BigNumber('0.01'),
feeCurrency: Currency.Dollar,
}
mockPreparedTransaction
)
)
.dispatch(sendPaymentFailure())
Expand Down
2 changes: 0 additions & 2 deletions src/send/SendConfirmation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ describe('SendConfirmation', () => {
'',
recipient,
false,
undefined,
getSerializablePreparedTransaction(mockPrepareTransactionsResultPossible.transactions[0])
)
)
Expand Down Expand Up @@ -293,7 +292,6 @@ describe('SendConfirmation', () => {
trimmedComment,
recipient,
false,
undefined,
getSerializablePreparedTransaction(mockPrepareTransactionsResultPossible.transactions[0])
),
])
Expand Down
1 change: 0 additions & 1 deletion src/send/SendConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ function SendConfirmation(props: Props) {
comment.trim(),
recipient,
fromModal,
undefined,
getSerializablePreparedTransaction(preparedTransaction)
)
)
Expand Down
8 changes: 2 additions & 6 deletions src/send/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import BigNumber from 'bignumber.js'
import { FeeInfo } from 'src/fees/saga'
import { Recipient } from 'src/recipients/recipient'
import { QrCode } from 'src/send/types'
import { Currency } from 'src/utils/currencies'
Expand Down Expand Up @@ -47,8 +46,7 @@ export interface SendPaymentAction {
comment: string
recipient: Recipient
fromModal: boolean
feeInfo?: FeeInfo
preparedTransaction?: SerializableTransactionRequest
preparedTransaction: SerializableTransactionRequest
}

export interface SendPaymentSuccessAction {
Expand Down Expand Up @@ -121,8 +119,7 @@ export const sendPayment = (
comment: string,
recipient: Recipient,
fromModal: boolean,
feeInfo?: FeeInfo,
preparedTransaction?: SerializableTransactionRequest
preparedTransaction: SerializableTransactionRequest
): SendPaymentAction => ({
type: Actions.SEND_PAYMENT,
amount,
Expand All @@ -131,7 +128,6 @@ export const sendPayment = (
comment,
recipient,
fromModal,
feeInfo,
preparedTransaction,
})

Expand Down

0 comments on commit 68edf25

Please sign in to comment.