-
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.
feat: store indexed data in persisted transactions (#2869)
* feat: poll noves indexer data * feat: store indexed data in persisted transactions * feat: adds latest block fetched logic and store for noves
- Loading branch information
1 parent
8f2e3ed
commit 21c2bd4
Showing
8 changed files
with
130 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './apis' | ||
export * from './constants' | ||
export * from './interfaces' | ||
export * from './types' |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './latest-block-persisted-for-noves-transactions.store' | ||
export * from './transactions.store' |
51 changes: 51 additions & 0 deletions
51
...d/src/lib/core/transactions/stores/latest-block-persisted-for-noves-transactions.store.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,51 @@ | ||
import { NetworkId } from '@core/network' | ||
import { get, writable } from 'svelte/store' | ||
|
||
type LatestBlockPersistedForAccountNetwork = { | ||
[profileId: string]: { | ||
[accountId: number]: { | ||
[networkId in NetworkId]?: { | ||
latestBlock?: number | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const latestBlockPersistedForNovesTransactions = writable<LatestBlockPersistedForAccountNetwork>({}) | ||
|
||
export function getLatestBlockForPersistedNovesTransactionsForAccountNetwork( | ||
profileId: string, | ||
accountId: number, | ||
networkId: NetworkId | ||
): number | undefined { | ||
return get(latestBlockPersistedForNovesTransactions)[profileId]?.[accountId]?.[networkId]?.latestBlock | ||
} | ||
|
||
export function updateLatestBlockForPersistedNovesTransactionsForAccountNetwork( | ||
profileId: string, | ||
accountId: number, | ||
networkId: NetworkId, | ||
latestBlock: number | ||
): void { | ||
latestBlockPersistedForNovesTransactions.update((state) => { | ||
if (!state[profileId]) { | ||
state[profileId] = {} | ||
} | ||
|
||
if (!state[profileId][accountId]) { | ||
state[profileId][accountId] = {} | ||
} | ||
|
||
if (!state[profileId][accountId][networkId]) { | ||
state[profileId][accountId][networkId] = {} | ||
} | ||
|
||
const obj = state[profileId][accountId][networkId] ?? {} | ||
|
||
obj.latestBlock = latestBlock | ||
|
||
state[profileId][accountId][networkId] = obj | ||
|
||
return state | ||
}) | ||
} |
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
34 changes: 8 additions & 26 deletions
34
packages/shared/src/lib/core/transactions/types/persisted-transaction.type.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,30 +1,12 @@ | ||
import { IBlockscoutTransaction } from '@auxiliary/blockscout/interfaces' | ||
import { LocalEvmTransaction } from './local-evm-transaction.interface' | ||
import { BlockscoutTokenTransfer } from '@auxiliary/blockscout/types' | ||
import { NovesTxResponse } from '@auxiliary/noves' | ||
import { AtLeastOne } from '@core/utils/types' | ||
|
||
export type PersistedTransaction = | ||
| { | ||
blockscout: IBlockscoutTransaction | ||
tokenTransfer: BlockscoutTokenTransfer | ||
local: LocalEvmTransaction | ||
} | ||
| { | ||
blockscout?: IBlockscoutTransaction | ||
tokenTransfer: BlockscoutTokenTransfer | ||
local: LocalEvmTransaction | ||
} | ||
| { | ||
blockscout: IBlockscoutTransaction | ||
tokenTransfer: BlockscoutTokenTransfer | ||
local?: LocalEvmTransaction | ||
} | ||
| { | ||
blockscout?: IBlockscoutTransaction | ||
tokenTransfer: BlockscoutTokenTransfer | ||
local?: LocalEvmTransaction | ||
} | ||
| { | ||
blockscout?: IBlockscoutTransaction | ||
tokenTransfer?: BlockscoutTokenTransfer | ||
local: LocalEvmTransaction | ||
} | ||
export type PersistedTransaction = AtLeastOne<{ | ||
blockscout: IBlockscoutTransaction | ||
noves: NovesTxResponse | ||
tokenTransfer: BlockscoutTokenTransfer | ||
local: LocalEvmTransaction | ||
}> |
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 +1,5 @@ | ||
export type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>> | ||
|
||
export type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T | ||
? Required<Pick<T, Keys>> & Partial<Omit<T, Keys>> | ||
: never |