-
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.
157 create a better flow when a certificate is required for wallet co…
…nnect (#170) * fix: fix opening logic * fix: refactor of the dapp-kit-ui * fix: fix dispatch * fix: styles * fix: add i18n and modalParent configuration * fix: unit tests * fix: react package * fix: test js * fix: lint * fix: update all sample apps * feat: add onSourceClick configuration * fix: versions and imports * fix: rename components * fix: readme * fix: null coalish and theme variables * fix: add default i18n languages * fix: minors * feat: return certificate for sync, sync2 and veworld * feat: wip adding certificate request * feat: add signature of the connection certificate for wallet-connect wallets * refactor: modal component * fix: refactor modal name * refactor: dapp-kit * fix: remove DEFAULT_SIGN_IN_MESSAGE * fix: add loader * fix: add loader to other wallets
- Loading branch information
1 parent
b886ad3
commit 099e540
Showing
61 changed files
with
842 additions
and
427 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
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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
import type { WalletManager, WalletSource } from '@vechain/dapp-kit'; | ||
import { DAppKitLogger } from '@vechain/dapp-kit'; | ||
import { subscribeKey } from 'valtio/vanilla/utils'; | ||
import { createModalIfNotPresent, dispatchCustomEvent } from '../utils'; | ||
|
||
export interface ConnectModalManagerOptions { | ||
modalParent?: HTMLElement; | ||
} | ||
|
||
export class ConnectModalManager { | ||
private static instance: ConnectModalManager | null = null; | ||
|
||
private constructor( | ||
private walletManager: WalletManager, | ||
options?: ConnectModalManagerOptions, | ||
) { | ||
createModalIfNotPresent(options); | ||
} | ||
|
||
public static getInstance( | ||
walletManager: WalletManager, | ||
options?: ConnectModalManagerOptions, | ||
): ConnectModalManager { | ||
if (!ConnectModalManager.instance) { | ||
ConnectModalManager.instance = new ConnectModalManager( | ||
walletManager, | ||
options, | ||
); | ||
} | ||
|
||
return ConnectModalManager.instance; | ||
} | ||
|
||
open(): void { | ||
DAppKitLogger.debug('ConnectModalManager', 'opening the modal'); | ||
dispatchCustomEvent('vdk-open-wallet-modal'); | ||
} | ||
|
||
close(): void { | ||
DAppKitLogger.debug('ConnectModalManager', 'closing the modal'); | ||
dispatchCustomEvent('vdk-close-wallet-modal'); | ||
} | ||
|
||
closeWalletConnect(): void { | ||
DAppKitLogger.debug('ConnectModalManager', 'closing wallet connect'); | ||
dispatchCustomEvent('vdk-close-wc-qrcode'); | ||
} | ||
|
||
closeConnectionCertificateRequest(): void { | ||
DAppKitLogger.debug( | ||
'ConnectModalManager', | ||
'closing connection certificate request', | ||
); | ||
dispatchCustomEvent('vdk-close-connection-certificate-request'); | ||
} | ||
|
||
onConnectionStatusChange( | ||
callback: (address: string | null) => void, | ||
): () => void { | ||
return subscribeKey(this.walletManager.state, 'address', (address) => { | ||
callback(address); | ||
}); | ||
} | ||
|
||
onWalletSelected( | ||
callback: (source: WalletSource | null) => void, | ||
): () => void { | ||
return subscribeKey(this.walletManager.state, 'source', (source) => { | ||
callback(source); | ||
}); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
packages/dapp-kit-ui/src/classes/custom-wallet-connect-modal.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,85 @@ | ||
import { EventEmitter } from 'events'; | ||
import type { | ||
OpenOptions, | ||
SubscribeModalState, | ||
WCModal, | ||
} from '@vechain/dapp-kit'; | ||
import { DAppKitLogger } from '@vechain/dapp-kit'; | ||
import { dispatchCustomEvent, subscribeToCustomEvent } from '../utils'; | ||
|
||
const MODAL_STATE_EVENT = 'vdk-modal-state-change'; | ||
|
||
export class CustomWalletConnectModal implements WCModal { | ||
private static instance: CustomWalletConnectModal | null = null; | ||
|
||
private eventEmitter = new EventEmitter(); | ||
|
||
private constructor() { | ||
subscribeToCustomEvent('vdk-close-wc-qrcode', () => { | ||
this.updateModalState({ open: false }); | ||
}); | ||
subscribeToCustomEvent('vdk-open-wc-qrcode', () => { | ||
this.updateModalState({ open: true }); | ||
}); | ||
} | ||
|
||
static getInstance(): CustomWalletConnectModal { | ||
if (!CustomWalletConnectModal.instance) { | ||
CustomWalletConnectModal.instance = new CustomWalletConnectModal(); | ||
} | ||
|
||
return CustomWalletConnectModal.instance; | ||
} | ||
|
||
/** | ||
* WalletConnect | ||
*/ | ||
openModal(options: OpenOptions): Promise<void> { | ||
DAppKitLogger.debug('CustomWalletConnectModal', 'opening the wc modal'); | ||
dispatchCustomEvent('vdk-open-wc-qrcode', options); | ||
return Promise.resolve(); | ||
} | ||
|
||
closeModal(): void { | ||
DAppKitLogger.debug('CustomWalletConnectModal', 'closing the modal'); | ||
dispatchCustomEvent('vdk-close-wc-qrcode'); | ||
} | ||
|
||
askForConnectionCertificate(): void { | ||
DAppKitLogger.debug( | ||
'CustomWalletConnectModal', | ||
'ask for connection certificate', | ||
); | ||
dispatchCustomEvent('vdk-close-wc-qrcode'); | ||
dispatchCustomEvent('vdk-request-connection-certificate'); | ||
} | ||
|
||
onConnectionCertificateSigned(): void { | ||
DAppKitLogger.debug( | ||
'CustomWalletConnectModal', | ||
'connection certificate signed', | ||
); | ||
dispatchCustomEvent('vdk-close-wallet-modal'); | ||
dispatchCustomEvent('vdk-close-wc-qrcode'); | ||
dispatchCustomEvent('vdk-close-connection-certificate-request'); | ||
} | ||
|
||
subscribeModal( | ||
callback: (newState: SubscribeModalState) => void, | ||
): () => void { | ||
DAppKitLogger.debug( | ||
'CustomWalletConnectModal', | ||
'subscribing to modal state', | ||
); | ||
|
||
this.eventEmitter.on(MODAL_STATE_EVENT, callback); | ||
|
||
return () => { | ||
this.eventEmitter.off(MODAL_STATE_EVENT, callback); | ||
}; | ||
} | ||
|
||
private updateModalState(state: SubscribeModalState): void { | ||
this.eventEmitter.emit(MODAL_STATE_EVENT, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './connect-modal-manager'; | ||
export * from './custom-wallet-connect-modal'; |
Oops, something went wrong.