Skip to content

Commit

Permalink
feat: update events to accomodate accounts WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 committed Jan 8, 2024
1 parent ee32362 commit 5af0ce7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte'
import { Platform } from '@core/app'
import { ImplicitAccountCreationRoute, implicitAccountCreationRoute } from '@core/router'
import { subscribeToWalletApiEventsForImplicitAccountCreation } from '@contexts/implicit-account-creation'
import { unsubscribeFromWalletApiEvents } from '@core/wallet'
import features from '@features/features'
import { Transition } from 'shared/components'
$: if (features.analytics.implicitAccountCreationRoute.enabled && $implicitAccountCreationRoute)
Platform.trackEvent('account-route', { route: $implicitAccountCreationRoute })
onMount(() => {
subscribeToWalletApiEventsForImplicitAccountCreation()
})
onDestroy(() => {
unsubscribeFromWalletApiEvents()
})
</script>

{#if $implicitAccountCreationRoute === ImplicitAccountCreationRoute.Activate}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { get } from 'svelte/store'
import { Event, NewOutputWalletEvent, WalletEventType } from '@iota/sdk'
import { activeWallets } from 'shared/lib/core/profile'
import { loadWallet, validateWalletApiEvent } from 'shared/lib/core/wallet'

export function handleNewOutputForImplicitAccountCreation(error: Error, rawEvent: Event): void {
const { walletId, payload } = validateWalletApiEvent(error, rawEvent, WalletEventType.NewOutput)
const type = payload.type
if (type === WalletEventType.TransactionInclusion) {
handleNewOutputForImplicitAccountCreationInternal(walletId, payload as NewOutputWalletEvent)
}
}

export async function handleNewOutputForImplicitAccountCreationInternal(
walletId: string,
payload: NewOutputWalletEvent
): Promise<void> {
const wallet = get(activeWallets)?.find((wallet) => wallet.id === walletId)
const outputData = payload.output
// TODO: Check if the outputData is the implicit account output or account output type

if (!wallet || !outputData) return
await loadWallet(wallet)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './subscribeToWalletApiEventsForImplicitAccountCreation'
export * from './handleNewOutputForImplicitAccountCreation'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WalletEventType } from '@iota/sdk/out/types'

import { getSelectedWallet, subscribeToWalletApiEvents, WalletApiEventMap } from '@core/wallet'
import { handleNewOutputForImplicitAccountCreation } from './handleNewOutputForImplicitAccountCreation'

export function subscribeToWalletApiEventsForImplicitAccountCreation(): void {
const wallet = getSelectedWallet()
const eventMap: WalletApiEventMap = {
[WalletEventType.NewOutput]: handleNewOutputForImplicitAccountCreation,
}

subscribeToWalletApiEvents({
eventMap,
wallet,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './actions'

0 comments on commit 5af0ce7

Please sign in to comment.