Skip to content

Commit

Permalink
Revert "refactor(frontend): 💡 remove hashconnect virtualization worka…
Browse files Browse the repository at this point in the history
…round"

This reverts commit fe4730d.
  • Loading branch information
apttx committed Dec 19, 2024
1 parent b7f1746 commit 4258dc4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/lib/hashconnect/dappMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DappMetadata } from 'hashconnect'
import type { DappMetadata } from 'virtual:hashconnect'

export const dappMetadata: DappMetadata = {
name: 'BIDI',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/hashconnect/hashConnect.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ExecuteTransaction } from '$lib/hedera/Execute'
import { MirrorNodeClient } from '$lib/hedera/MirrorNodeClient'
import { AccountId, LedgerId, TokenId } from '@hashgraph/sdk'
import { tokenUtils as getTokenUtils } from '@tikz/hedera-mirror-node-ts'
import { HashConnect, type SessionData } from 'hashconnect'
import type { HashConnectSigner } from 'hashconnect/dist/signer'
import { untrack } from 'svelte'
import { HashConnect, type SessionData } from 'virtual:hashconnect'
import { dappMetadata } from './dappMetadata'

/**
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/hashconnect/virtual:hashconnect.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'virtual:hashconnect' {
export * from 'hashconnect'
}
19 changes: 19 additions & 0 deletions frontend/src/lib/hashconnect/virtualHashConnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type Plugin } from 'vite'

/**
* a compatibility layer to import `hashconnect` through vite instead of allowing sveltekit to process it
*
* `hashconnect` can't be imported by node directly because it uses imports without extensions in its dist files. importing through sveltekit code doesn't work because of this, because sveltekit's processing is not as forgiving as vite's. but we can circumvent this by creating a virtual module that uses vite's module resolution to create a working bundle of `hashconnect` (as a pre-bundled dependency).
*/
export const getVirtualHashConnectPlugin = (): Plugin => {
const virtualModuleId = 'virtual:hashconnect'

return {
name: 'virtual-hashconnect', // required, will show up in warnings and errors
async resolveId(id) {
if (id === virtualModuleId) {
return await this.resolve('hashconnect')
}
},
}
}
3 changes: 2 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import { getVirtualHashConnectPlugin } from './src/lib/hashconnect/virtualHashConnect'

export default defineConfig({
plugins: [nodePolyfills(), sveltekit()],
plugins: [nodePolyfills(), getVirtualHashConnectPlugin(), sveltekit()],
ssr: {
noExternal: ['@tikz/hedera-mirror-node-ts'],
},
Expand Down

0 comments on commit 4258dc4

Please sign in to comment.