Skip to content

Commit

Permalink
Create component dynamically (#106)
Browse files Browse the repository at this point in the history
* fix: create component dynamically

* fix: default WC modal never used

* fix: default WC modal never used
  • Loading branch information
darrenvechain authored Nov 27, 2023
1 parent 92a0f00 commit 2e75994
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/sample-angular-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const vechainWalletKitOptions = {
nodeUrl: 'https://testnet.vechain.org/',
network: 'test',
walletConnectOptions,
useWalletKitModal: true,
};

DAppKit.configure(vechainWalletKitOptions);
1 change: 1 addition & 0 deletions apps/sample-svelte-app/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const vechainWalletKitOptions = {
nodeUrl: 'https://testnet.vechain.org/',
network: 'test',
walletConnectOptions,
useWalletKitModal: true,
};

DAppKit.configure(vechainWalletKitOptions);
1 change: 1 addition & 0 deletions apps/sample-vanilla-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const vechainWalletKitOptions = {
node: 'https://testnet.vechain.org/',
network: 'test',
walletConnectOptions,
useWalletKitModal: true,
};

const connex = DAppKit.configure(vechainWalletKitOptions);
Expand Down
1 change: 1 addition & 0 deletions apps/sample-vue-app/src/connex/ConnexProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default defineComponent({
const connex = DAppKit.configure({
nodeUrl: 'https://mainnet.vechain.org/',
walletConnectOptions,
useWalletKitModal: true,
});
const onDisconnected = () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/dapp-kit-react/src/ConnexProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const ConnexProvider: React.FC<ConnexProviderOptions> = ({
nodeOptions,
walletConnectOptions,
persistState = false,
useWalletKitModal = false,
}): React.ReactElement => {
const [account, setAccount] = useState<string | null>(
persistState ? retrieve('account') : null,
Expand All @@ -49,8 +50,14 @@ export const ConnexProvider: React.FC<ConnexProviderOptions> = ({
nodeUrl: nodeOptions.node,
genesis: nodeOptions.network,
walletConnectOptions,
useWalletKitModal,
}),
[nodeOptions.network, nodeOptions.node, walletConnectOptions],
[
useWalletKitModal,
nodeOptions.network,
nodeOptions.node,
walletConnectOptions,
],
);

/**
Expand Down
1 change: 1 addition & 0 deletions packages/dapp-kit-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ConnexProviderOptions {
nodeOptions: Omit<Options, 'signer'>;
walletConnectOptions?: WalletConnectOptions;
persistState?: boolean;
useWalletKitModal?: boolean;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/dapp-kit-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const vechainWalletKitOptions = {
node: 'https://testnet.vechain.org/',
network: 'test',
walletConnectOptions,
useWalletKitModal: true,
};

DAppKit.configure(vechainWalletKitOptions);
15 changes: 11 additions & 4 deletions packages/dapp-kit-ui/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { CustomWalletConnectModal, DAppKitModal } from './modal';

let connex: MultiWalletConnex | null = null;

type DAppKitOptions = Omit<ConnexOptions, 'customWcModal'> & {
useWalletKitModal?: boolean;
};

const DAppKit = {
configure(options: ConnexOptions): MultiWalletConnex {
if (!options.customWcModal) {
options.customWcModal = CustomWalletConnectModal.getInstance();
configure(options: DAppKitOptions): MultiWalletConnex {
const connexOptions: ConnexOptions = options;

if (options.useWalletKitModal) {
connexOptions.customWcModal =
CustomWalletConnectModal.getInstance();
}

connex = new MultiWalletConnex(options);
connex = new MultiWalletConnex(connexOptions);

return connex;
},
Expand Down

0 comments on commit 2e75994

Please sign in to comment.