-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove balance changes for evm assets (#2054)
* cleanup L2 balance fetches * generate balance changes only if IRC is sent * fix name * cleanup old balance changes * improve erc detection * add prod migration
- Loading branch information
Showing
13 changed files
with
119 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { isValidEthereumAddress } from '@core/utils/crypto/utils/isValidEthereumAddress' | ||
|
||
export function isErcAsset(assetId: string): boolean { | ||
const [address] = assetId.split(':') | ||
|
||
return isValidEthereumAddress(address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/shared/src/lib/core/profile/constants/profile-version.constant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { AppStage } from '@core/app/enums' | ||
|
||
export const PROFILE_VERSION: Record<AppStage, number> = { | ||
[AppStage.ALPHA]: 6, | ||
[AppStage.ALPHA]: 7, | ||
[AppStage.BETA]: 0, | ||
[AppStage.PROD]: 3, | ||
[AppStage.PROD]: 4, | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/shared/src/lib/core/profile/migrations/actions/removeEvmBalanceChanges.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { persistedBalanceChanges } from '@core/activity' | ||
import { isErcAsset } from '@core/layer-2' | ||
import { NetworkId } from '@core/network' | ||
import { BASE_TOKEN_ID } from '@core/token' | ||
|
||
export function removeEvmBalanceChanges(profileId: string): void { | ||
persistedBalanceChanges.update((state) => { | ||
const profileBalanceChanges = state[profileId] | ||
if (!profileBalanceChanges) { | ||
return state | ||
} | ||
|
||
for (const accountId of Object.keys(profileBalanceChanges)) { | ||
const accountBalanceChanges = profileBalanceChanges[accountId] | ||
|
||
for (const networkId of Object.keys(accountBalanceChanges)) { | ||
const networkBalanceChanges = accountBalanceChanges[networkId as NetworkId] | ||
if (!networkBalanceChanges) { | ||
continue | ||
} | ||
const tokens = networkBalanceChanges.tokens | ||
const nfts = networkBalanceChanges.nfts | ||
|
||
for (const nftId of Object.keys(nfts ?? {})) { | ||
if (isErcAsset(nftId)) { | ||
delete nfts[nftId] | ||
} | ||
} | ||
|
||
for (const tokenId of Object.keys(tokens ?? {})) { | ||
if (tokenId === BASE_TOKEN_ID || isErcAsset(tokenId)) { | ||
delete tokens[tokenId] | ||
} | ||
} | ||
|
||
accountBalanceChanges[networkId as NetworkId] = networkBalanceChanges | ||
} | ||
profileBalanceChanges[accountId] = accountBalanceChanges | ||
} | ||
|
||
state[profileId] = profileBalanceChanges | ||
return state | ||
}) | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-6-to-7.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { removeEvmBalanceChanges } from '../actions/removeEvmBalanceChanges' | ||
|
||
export function alphaProfileMigration6To7(existingProfile: unknown): Promise<void> { | ||
const profile = existingProfile as { id: string } | ||
|
||
try { | ||
removeEvmBalanceChanges(profile.id) | ||
} catch (error) { | ||
return Promise.reject() | ||
} | ||
|
||
return Promise.resolve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-3-to-4.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { removeEvmBalanceChanges } from '../actions/removeEvmBalanceChanges' | ||
|
||
export function prodProfileMigration3To4(existingProfile: unknown): Promise<void> { | ||
const profile = existingProfile as { id: string } | ||
|
||
try { | ||
removeEvmBalanceChanges(profile.id) | ||
} catch (error) { | ||
return Promise.reject() | ||
} | ||
|
||
return Promise.resolve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
packages/shared/src/lib/core/wallet/actions/updateL2BalanceWithoutActivity.ts
This file was deleted.
Oops, something went wrong.