Skip to content

Commit

Permalink
fix(wallet): fix ladle build
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Dec 13, 2023
1 parent 49cb2c5 commit ff8d94b
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 544 deletions.
2 changes: 1 addition & 1 deletion packages/features/.ladle/components.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@/index.css'
import '@/globals.css'
import { useEffect } from 'react'
import {
ActionType,
Expand Down
2 changes: 0 additions & 2 deletions packages/features/.ladle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const MNEMONIC =

export const useStoriesWallet = () => {
const restoreWallet = useVault((state) => state.restoreWallet)
const switchNetwork = useVault((state) => state.switchNetwork)
useEffect(() => {
const restore = async () => {
await restoreWallet(
Expand All @@ -25,7 +24,6 @@ export const useStoriesWallet = () => {
getPassphrase: async () => Buffer.from('passphrase')
}
)
await switchNetwork(Mina.Networks.DEVNET)
}
restore()
}, [])
Expand Down
1 change: 0 additions & 1 deletion packages/mina-core/src/Providers/UnifiedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type UnifiedMinaProviderConfig = {
}

export interface UnifiedMinaProviderType {
onNetworkChanged(listener: (url: string) => void): void
changeNetwork(nodeUrl: string, archiveUrl: string): Promise<void>
destroy(): Promise<void>

Expand Down
14 changes: 0 additions & 14 deletions packages/mina-graphql/src/Providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
TxStatus,
TxStatusArgs
} from '@palladxyz/mina-core'
import { EventEmitter } from 'events'

import { AccountInfoGraphQLProvider } from './AccountInfo'
import { TxStatusGraphQLProvider } from './TxStatus'
Expand All @@ -17,22 +16,15 @@ export class MinaProvider implements ProviderNode {
private accountInfoProvider: AccountInfoGraphQLProvider | null
private txSubmitProvider: TxSubmitGraphQLProvider | null
private txStatusProvider: TxStatusGraphQLProvider | null
private emitter: EventEmitter
public providerUrl: string

constructor(nodeUrl: string) {
this.accountInfoProvider = new AccountInfoGraphQLProvider(nodeUrl)
this.txSubmitProvider = new TxSubmitGraphQLProvider(nodeUrl)
this.txStatusProvider = new TxStatusGraphQLProvider(nodeUrl)
this.emitter = new EventEmitter()
this.providerUrl = nodeUrl
}

public onNetworkChanged(listener: (nodeUrl: string) => void) {
this.emitter.removeAllListeners('networkChanged')
this.emitter.on('networkChanged', listener)
}

public get provider(): this {
return this
}
Expand All @@ -42,23 +34,17 @@ export class MinaProvider implements ProviderNode {
await this.txSubmitProvider?.changeNetwork(nodeUrl)
await this.txStatusProvider?.changeNetwork(nodeUrl)
this.providerUrl = nodeUrl

this.emitter.emit('networkChanged', nodeUrl)
}

public async destroy(): Promise<void> {
await this.accountInfoProvider?.destroy()
await this.txSubmitProvider?.destroy()
await this.txStatusProvider?.destroy()

// Remove all listeners to avoid memory leaks
this.emitter.removeAllListeners()

// Nullify or reinitialize the properties, as per the requirements of your application
this.accountInfoProvider = null
this.txSubmitProvider = null
this.txStatusProvider = null
this.emitter = new EventEmitter()
this.providerUrl = ''
}

Expand Down
14 changes: 0 additions & 14 deletions packages/mina-graphql/src/Providers/providerArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import {
TransactionsByAddressesArgs,
TransactionsByIdsArgs
} from '@palladxyz/mina-core'
import { EventEmitter } from 'events'

import { ChainHistoryGraphQLProvider } from './ChainHistory'
import { ProviderArchive } from './types'

export class MinaArchiveProvider implements ProviderArchive {
private chainHistoryProvider: ChainHistoryGraphQLProvider | null
public providerUrl: string
private emitter: EventEmitter

constructor(archiveUrl: string) {
this.chainHistoryProvider = new ChainHistoryGraphQLProvider(archiveUrl)
this.providerUrl = archiveUrl
this.emitter = new EventEmitter()
}

public onNetworkChanged(listener: (nodeUrl: string) => void) {
this.emitter.removeAllListeners('networkChanged')
this.emitter.on('networkChanged', listener)
}

public get provider(): this {
Expand All @@ -31,19 +23,13 @@ export class MinaArchiveProvider implements ProviderArchive {
public async changeNetwork(nodeUrl: string): Promise<void> {
await this.chainHistoryProvider?.changeNetwork(nodeUrl)
this.providerUrl = nodeUrl

this.emitter.emit('networkChanged', nodeUrl)
}

public async destroy(): Promise<void> {
await this.chainHistoryProvider?.destroy()

// Remove all listeners to avoid memory leaks
this.emitter.removeAllListeners()

// Nullify or reinitialize the properties, as per the requirements of your application
this.chainHistoryProvider = null
this.emitter = new EventEmitter()
this.providerUrl = ''
}

Expand Down
16 changes: 0 additions & 16 deletions packages/mina-graphql/src/Providers/unifiedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
TxStatusArgs,
UnifiedMinaProviderConfig
} from '@palladxyz/mina-core'
import { EventEmitter } from 'events'

import { MinaProvider } from './provider'
import { MinaArchiveProvider } from './providerArchive'
Expand All @@ -19,24 +18,10 @@ import { ProviderArchive, ProviderNode } from './types'
export class UnifiedMinaProvider implements ProviderNode, ProviderArchive {
private nodeProvider: MinaProvider
private archiveProvider: MinaArchiveProvider
private emitter: EventEmitter

constructor(config: UnifiedMinaProviderConfig) {
this.nodeProvider = new MinaProvider(config.nodeUrl)
this.archiveProvider = new MinaArchiveProvider(config.archiveUrl)
this.emitter = new EventEmitter()

this.nodeProvider.onNetworkChanged((url) =>
this.emitter.emit('networkChanged', url)
)
this.archiveProvider.onNetworkChanged((url) =>
this.emitter.emit('networkChanged', url)
)
}

public onNetworkChanged(listener: (url: string) => void) {
this.emitter.removeAllListeners('networkChanged')
this.emitter.on('networkChanged', listener)
}

public get provider(): this {
Expand All @@ -54,7 +39,6 @@ export class UnifiedMinaProvider implements ProviderNode, ProviderArchive {
public async destroy(): Promise<void> {
await this.nodeProvider.destroy()
await this.archiveProvider.destroy()
this.emitter.removeAllListeners()
}

// Methods related to MinaProvider
Expand Down
Loading

0 comments on commit ff8d94b

Please sign in to comment.