-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connex implementation for vanilla js (#51)
- Loading branch information
1 parent
4c52395
commit 349941c
Showing
15 changed files
with
775 additions
and
52 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,7 +1,26 @@ | ||
import '@vechain/vanilla-wallet-kit'; | ||
// eslint-disable-next-line eslint-comments/disable-enable-pair | ||
/* eslint-disable no-undef */ | ||
import { | ||
VechainWalletKit, | ||
VechainWalletKitModal, | ||
} from '@vechain/vanilla-wallet-kit'; | ||
|
||
// eslint-disable-next-line no-undef | ||
addEventListener('vwk-source-card-clicked', (e) => { | ||
// eslint-disable-next-line no-console | ||
console.log('vwk-source-card-clicked', e.detail); | ||
}); | ||
const walletConnectOptions = { | ||
projectId: 'a0b855ceaf109dbc8426479a4c3d38d8', | ||
metadata: { | ||
name: 'Sample VeChain dApp', | ||
description: 'A sample VeChain dApp', | ||
url: window.location.origin, | ||
icons: [`${window.location.origin}/images/logo/my-dapp.png`], | ||
}, | ||
}; | ||
|
||
const vechainWalletKitOptions = { | ||
node: 'https://testnet.vechain.org/', | ||
network: 'test', | ||
walletConnectOptions, | ||
}; | ||
|
||
const walletKit = new VechainWalletKit(vechainWalletKitOptions); | ||
const vechainWalletKit = new VechainWalletKitModal(walletKit); | ||
vechainWalletKit.initModalListeners(); |
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,67 @@ | ||
import type { WalletSource } from '@vechain/wallet-kit'; | ||
import { MultiWalletConnex } from '@vechain/wallet-kit'; | ||
import type { SourceInfo } from './constants'; | ||
|
||
export interface VechainWalletKitOptions { | ||
connex?: MultiWalletConnex; | ||
nodeUrl: string; | ||
network: string; // TODO: add a type for this | ||
walletConnectOptions: { | ||
projectId: string; | ||
metadata: { | ||
name: string; | ||
description: string; | ||
url: string; | ||
icons: string[]; | ||
}; | ||
}; | ||
onDisconnected: () => void; | ||
} | ||
|
||
export class VechainWalletKit { | ||
connex: MultiWalletConnex; | ||
account: string | null = null; | ||
|
||
constructor(options: VechainWalletKitOptions) { | ||
if (options.connex) { | ||
this.connex = options.connex; | ||
} else { | ||
this.connex = new MultiWalletConnex({ | ||
nodeUrl: options.nodeUrl, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
genesis: options.network as any, | ||
walletConnectOptions: options.walletConnectOptions, | ||
onDisconnected: options.onDisconnected, | ||
}); | ||
} | ||
} | ||
|
||
setSource = (wallet: WalletSource): void => { | ||
this.connex.wallet.setSource(wallet); | ||
}; | ||
} | ||
|
||
export class VechainWalletKitModal { | ||
public walletKit: VechainWalletKit; | ||
constructor(walletKit: VechainWalletKit) { | ||
this.walletKit = walletKit; | ||
} | ||
|
||
initModalListeners(): void { | ||
addEventListener('vwk-source-card-clicked', (event) => { | ||
const source = (event as CustomEvent).detail as SourceInfo; | ||
// eslint-disable-next-line no-console | ||
console.log('vwk-source-card-clicked', source); | ||
this.walletKit.setSource(source.id); | ||
this.walletKit.connex.wallet | ||
.connect() | ||
.then(({ account }) => { | ||
this.walletKit.account = account; | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
}); | ||
}); | ||
} | ||
} |
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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 './components'; | ||
export * from './client'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.