Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove usage of __typename for the tx feed #6186

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,11 @@ interface EarnEventsProperties {
} & EarnCommonProperties
[EarnEvents.earn_deposit_add_gas_press]: EarnCommonProperties & { gasTokenId: string }
[EarnEvents.earn_feed_item_select]: {
origin: 'EarnDeposit' | 'EarnWithdraw' | 'EarnClaimReward' | 'EarnSwapDeposit'
origin:
| TokenTransactionTypeV2.EarnDeposit
| TokenTransactionTypeV2.EarnWithdraw
| TokenTransactionTypeV2.EarnClaimReward
| TokenTransactionTypeV2.EarnSwapDeposit
Comment on lines -1617 to +1621
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satish-ravi do you think this could be a problem?
The value will be different now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we generally try to avoid breaking changes for analytics in case there's some dashboard dependencies. We have had instances in the past where we had to workaround to avoid this. But maybe fine here, I don't think this is a critical analytics event. Would be good to confirm with product

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks yes I'll check.

}
[EarnEvents.earn_collect_earnings_press]: EarnWithdrawProperties
[EarnEvents.earn_withdraw_submit_start]: EarnWithdrawProperties
Expand Down
5 changes: 0 additions & 5 deletions src/earn/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ describe('depositSubmitSaga', () => {
}

const expectedApproveStandbyTx = {
__typename: 'TokenApproval',
context: {
id: 'id-earn/saga-Earn/Approve',
tag: 'earn/saga',
Expand All @@ -162,7 +161,6 @@ describe('depositSubmitSaga', () => {
}

const expectedDepositStandbyTx = {
__typename: 'EarnDeposit',
context: {
id: 'id-earn/saga-Earn/Deposit',
tag: 'earn/saga',
Expand All @@ -184,7 +182,6 @@ describe('depositSubmitSaga', () => {
}

const expectedSwapDepositStandbyTx = {
__typename: 'EarnSwapDeposit',
context: {
id: 'id-earn/saga-Earn/SwapDeposit',
tag: 'earn/saga',
Expand Down Expand Up @@ -734,7 +731,6 @@ describe('withdrawSubmitSaga', () => {
}

const expectedWithdrawStandbyTx = {
__typename: 'EarnWithdraw',
context: {
id: 'id-earn/saga-Earn/Withdraw',
tag: 'earn/saga',
Expand All @@ -757,7 +753,6 @@ describe('withdrawSubmitSaga', () => {

// TODO: replace with EarnClaimReward type
const expectedClaimRewardTx = {
__typename: 'EarnClaimReward',
context: {
id: 'id-earn/saga-Earn/ClaimReward-1',
tag: 'earn/saga',
Expand Down
5 changes: 0 additions & 5 deletions src/earn/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export function* depositSubmitSaga(action: PayloadAction<DepositInfo>) {
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Earn/Approve'),
__typename: 'TokenApproval',
networkId,
type: TokenTransactionTypeV2.Approval,
transactionHash,
Expand All @@ -177,7 +176,6 @@ export function* depositSubmitSaga(action: PayloadAction<DepositInfo>) {
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Earn/Deposit'),
__typename: 'EarnDeposit',
networkId,
type: TokenTransactionTypeV2.EarnDeposit,
inAmount: {
Expand All @@ -199,7 +197,6 @@ export function* depositSubmitSaga(action: PayloadAction<DepositInfo>) {
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Earn/SwapDeposit'),
__typename: 'EarnSwapDeposit',
networkId,
type: TokenTransactionTypeV2.EarnSwapDeposit,
swap: {
Expand Down Expand Up @@ -352,7 +349,6 @@ export function* withdrawSubmitSaga(action: PayloadAction<WithdrawInfo>) {
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Earn/Withdraw'),
__typename: 'EarnWithdraw',
networkId,
type: TokenTransactionTypeV2.EarnWithdraw,
inAmount: {
Expand All @@ -378,7 +374,6 @@ export function* withdrawSubmitSaga(action: PayloadAction<WithdrawInfo>) {
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, `Earn/ClaimReward-${index + 1}`),
__typename: 'EarnClaimReward',
networkId,
amount: {
value: balance,
Expand Down
1 change: 0 additions & 1 deletion src/fiatExchanges/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ describe(tagTxsWithProviderInfo, () => {
const mockProviderAccount = '0x30d5ca2a263e0c0d11e7a668ccf30b38f1482251'

const mockTransactionDetails = {
__typename: 'TokenTransferV3' as const,
amount: mockAmount,
timestamp: 1578530602,
address: mockAccount,
Expand Down
2 changes: 1 addition & 1 deletion src/fiatExchanges/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function* tagTxsWithProviderInfo(action: UpdateTransactionsPayload) {
const txHashesToProvider = yield* call(fetchTxHashesToProviderMapping)

for (const tx of transactions) {
if (tx.__typename !== 'TokenTransferV3' || tx.type !== TokenTransactionTypeV2.Received) {
if (tx.type !== TokenTransactionTypeV2.Received) {
continue
}

Expand Down
1 change: 0 additions & 1 deletion src/fiatconnect/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ export function* _initiateSendTxToProvider({
transactionHash: string,
feeCurrencyId?: string
): BaseStandbyTransaction => ({
__typename: 'TokenTransferV3',
type: TokenTransactionTypeV2.Sent,
context,
networkId: tokenInfo.networkId,
Expand Down
1 change: 0 additions & 1 deletion src/firebase/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe(handleNotification, () => {

expect(navigate).toHaveBeenCalledWith(Screens.TransactionDetailsScreen, {
transaction: {
__typename: 'TokenTransferV3',
networkId: NetworkId['celo-alfajores'],
type: 'RECEIVED',
transactionHash: '0xTXHASH',
Expand Down
1 change: 0 additions & 1 deletion src/firebase/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function handlePaymentReceived(transferNotification: TransferNotificationData) {

navigate(Screens.TransactionDetailsScreen, {
transaction: {
__typename: 'TokenTransferV3',
networkId: networkConfig.defaultNetworkId,
type: TokenTransactionTypeV2.Received,
transactionHash: transferNotification.txHash,
Expand Down
3 changes: 1 addition & 2 deletions src/jumpstart/JumpstartTransactionDetailsScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ describe('JumpstartTransactionDetailsScreen', () => {
fees = [],
status = TransactionStatus.Complete,
}: {
type: TokenTransactionTypeV2
type: TokenTransactionTypeV2.Sent | TokenTransactionTypeV2.Received
address?: string
amount?: TokenAmount
metadata?: TokenTransferMetadata
fees?: Fee[]
status?: TransactionStatus
}): TokenTransfer {
return {
__typename: 'TokenTransferV3',
networkId: NetworkId['celo-alfajores'],
type,
transactionHash: mockTransactionHash,
Expand Down
2 changes: 0 additions & 2 deletions src/jumpstart/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ describe('dispatchPendingERC20Transactions', () => {
)
.put(
addStandbyTransaction({
__typename: 'TokenTransferV3',
type: TokenTransactionTypeV2.Received,
context: { id: mockTransactionHash },
transactionHash: mockTransactionHash,
Expand Down Expand Up @@ -305,7 +304,6 @@ describe('dispatchPendingERC721Transactions', () => {
])
.put(
addStandbyTransaction({
__typename: 'NftTransferV3',
type: TokenTransactionTypeV2.NftReceived,
context: { id: mockTransactionHash },
transactionHash: mockTransactionHash,
Expand Down
5 changes: 0 additions & 5 deletions src/jumpstart/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export function* dispatchPendingERC20Transactions(

yield* put(
addStandbyTransaction({
__typename: 'TokenTransferV3',
type: TokenTransactionTypeV2.Received,
context: {
id: transactionHash,
Expand Down Expand Up @@ -175,7 +174,6 @@ export function* dispatchPendingERC721Transactions(

yield* put(
addStandbyTransaction({
__typename: 'NftTransferV3',
type: TokenTransactionTypeV2.NftReceived,
context: {
id: transactionHash,
Expand Down Expand Up @@ -261,7 +259,6 @@ export function* sendJumpstartTransactions(
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Approve jumpstart transaction'),
__typename: 'TokenApproval',
networkId,
type: TokenTransactionTypeV2.Approval,
transactionHash: txHash,
Expand All @@ -277,7 +274,6 @@ export function* sendJumpstartTransactions(
hash: string,
feeCurrencyId?: string
): BaseStandbyTransaction => ({
__typename: 'TokenTransferV3',
type: TokenTransactionTypeV2.Sent,
context: newTransactionContext(TAG, 'Send jumpstart transaction'),
networkId,
Expand Down Expand Up @@ -369,7 +365,6 @@ export function* jumpstartReclaim(action: PayloadAction<JumpstarReclaimAction>)
): BaseStandbyTransaction => {
return {
context: newTransactionContext(TAG, 'Reclaim transaction'),
__typename: 'TokenTransferV3',
networkId,
type: TokenTransactionTypeV2.Received,
transactionHash: transactionHash,
Expand Down
1 change: 1 addition & 0 deletions src/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1924,4 +1924,5 @@ export const migrations = {
feedFirstPage: [],
},
}),
235: (state: any) => state,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a migration for this change? it feels odd to update the root schema without incrementing the schema number but this migration doesn't remove the __typename property on persisted transactions which is the only thing that changes about the state...the persisted transactions are replaced on app start very quickly anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I decided to increase the schema number (and hence the no-op migration) to make this change more explicit.
But we could have skipped it.

}
2 changes: 1 addition & 1 deletion src/redux/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('store state', () => {
{
"_persist": {
"rehydrated": true,
"version": 234,
"version": 235,
},
"account": {
"acceptedTerms": false,
Expand Down
2 changes: 1 addition & 1 deletion src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const persistConfig: PersistConfig<ReducersRootState> = {
key: 'root',
// default is -1, increment as we make migrations
// See https://github.com/valora-inc/wallet/tree/main/WALLET.md#redux-state-migration
version: 234,
version: 235,
keyPrefix: `reduxStore-`, // the redux-persist default is `persist:` which doesn't work with some file systems.
storage: FSStorage(),
blacklist: [
Expand Down
2 changes: 0 additions & 2 deletions src/send/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ describe(sendPaymentSaga, () => {
.call(getViemWallet, networkConfig.viemChain.celo, false)
.put(
addStandbyTransaction({
__typename: 'TokenTransferV3',
context: { id: 'mock' },
type: TokenTransactionTypeV2.Sent,
networkId: NetworkId['celo-alfajores'],
Expand Down Expand Up @@ -176,7 +175,6 @@ describe(sendPaymentSaga, () => {
.call(getViemWallet, networkConfig.viemChain.celo, false)
.put(
addStandbyTransaction({
__typename: 'TokenTransferV3',
context: { id: 'mock' },
type: TokenTransactionTypeV2.Sent,
networkId: NetworkId['celo-alfajores'],
Expand Down
1 change: 0 additions & 1 deletion src/send/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function* sendPaymentSaga({
transactionHash: string,
feeCurrencyId?: string
): BaseStandbyTransaction => ({
__typename: 'TokenTransferV3',
type: TokenTransactionTypeV2.Sent,
context,
networkId: tokenInfo.networkId,
Expand Down
9 changes: 1 addition & 8 deletions src/swap/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Approve',
},
__typename: 'TokenApproval',
networkId,
type: TokenTransactionTypeV2.Approval,
transactionHash: mockApproveTxReceipt.transactionHash,
Expand All @@ -419,7 +418,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Execute',
},
__typename: 'TokenExchangeV3',
networkId,
type: TokenTransactionTypeV2.SwapTransaction,
inAmount: {
Expand Down Expand Up @@ -558,7 +556,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Execute',
},
__typename: 'TokenExchangeV3',
networkId: NetworkId['celo-alfajores'],
type: TokenTransactionTypeV2.SwapTransaction,
inAmount: {
Expand All @@ -577,7 +574,7 @@ describe(swapSubmitSaga, () => {
action: {
type: actions.addStandbyTransaction.type,
transaction: {
__typename: 'TokenApproval',
type: TokenTransactionTypeV2.Approval,
},
},
})
Expand All @@ -601,7 +598,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Approve',
},
__typename: 'TokenApproval',
networkId: NetworkId['celo-alfajores'],
type: TokenTransactionTypeV2.Approval,
transactionHash: mockApproveTxReceipt.transactionHash,
Expand All @@ -617,7 +613,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Execute',
},
__typename: 'TokenExchangeV3',
networkId: NetworkId['celo-alfajores'],
type: TokenTransactionTypeV2.SwapTransaction,
inAmount: {
Expand Down Expand Up @@ -646,7 +641,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Approve',
},
__typename: 'TokenApproval',
networkId: NetworkId['celo-alfajores'],
type: TokenTransactionTypeV2.Approval,
transactionHash: mockApproveTxReceipt.transactionHash,
Expand All @@ -662,7 +656,6 @@ describe(swapSubmitSaga, () => {
tag: 'swap/saga',
description: 'Swap/Execute',
},
__typename: 'CrossChainTokenExchange',
networkId: NetworkId['celo-alfajores'],
type: TokenTransactionTypeV2.CrossChainSwapTransaction,
inAmount: {
Expand Down
2 changes: 0 additions & 2 deletions src/swap/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export function* swapSubmitSaga(action: PayloadAction<SwapInfo>) {
): BaseStandbyTransaction => {
return {
context: swapApproveContext,
__typename: 'TokenApproval',
networkId,
type: TokenTransactionTypeV2.Approval,
transactionHash,
Expand All @@ -225,7 +224,6 @@ export function* swapSubmitSaga(action: PayloadAction<SwapInfo>) {
feeCurrencyId?: string
): BaseStandbyTransaction => ({
context: swapExecuteContext,
__typename: swapType === 'same-chain' ? 'TokenExchangeV3' : 'CrossChainTokenExchange',
networkId,
type:
swapType === 'same-chain'
Expand Down
10 changes: 5 additions & 5 deletions src/transactions/feed/EarnFeedItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Screens } from 'src/navigator/Screens'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import EarnFeedItem from 'src/transactions/feed/EarnFeedItem'
import { NetworkId } from 'src/transactions/types'
import { NetworkId, TokenTransactionTypeV2 } from 'src/transactions/types'
import { createMockStore } from 'test/utils'
import {
mockAaveArbUsdcAddress,
Expand Down Expand Up @@ -107,31 +107,31 @@ const store = createMockStore({

describe.each([
{
type: 'EarnWithdraw',
type: TokenTransactionTypeV2.EarnWithdraw,
transaction: mockEarnWithdrawTransaction,
expectedTitle: 'earnFlow.transactionFeed.earnWithdrawTitle',
expectedSubTitle: 'earnFlow.transactionFeed.earnWithdrawSubtitle, {"providerName":"Aave"}',
expectedTotal: '+1.00 USDC',
expectedTotalLocal: '₱1.33',
},
{
type: 'EarnDeposit',
type: TokenTransactionTypeV2.EarnDeposit,
transaction: mockEarnDepositTransaction,
expectedTitle: 'earnFlow.transactionFeed.earnDepositTitle',
expectedSubTitle: 'earnFlow.transactionFeed.earnDepositSubtitle, {"providerName":"Aave"}',
expectedTotal: '-10.00 USDC',
expectedTotalLocal: '₱13.30',
},
{
type: 'EarnSwapDeposit',
type: TokenTransactionTypeV2.EarnSwapDeposit,
transaction: mockEarnSwapDeposit,
expectedTitle: 'earnFlow.transactionFeed.earnDepositTitle',
expectedSubTitle: 'earnFlow.transactionFeed.earnDepositSubtitle, {"providerName":"Aave"}',
expectedTotal: '-10.00 USDC',
expectedTotalLocal: '₱13.30',
},
{
type: 'EarnClaimReward',
type: TokenTransactionTypeV2.EarnClaimReward,
transaction: mockEarnClaimRewardTransaction,
expectedTitle: 'earnFlow.transactionFeed.earnClaimTitle',
expectedSubTitle: 'earnFlow.transactionFeed.earnClaimSubtitle, {"providerName":"Aave"}',
Expand Down
Loading
Loading