Skip to content

Commit

Permalink
Merge pull request #36 from marcuspuchalla/issues/34_and_35
Browse files Browse the repository at this point in the history
Fix wallet info in autoconnect + allow to set wallet discovery seed
  • Loading branch information
fabianbormann authored Mar 28, 2023
2 parents 5ff469a + ff815a7 commit 113e340
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/CardanoPeerConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export default abstract class CardanoPeerConnect {
this.DAppDiscoveryMeerkat = new Meerkat({
announce: this.announceEndpoints,
seed:
this.discoverySeed ??
AutoConnectHelper.getWalletAutoDiscoverySeed() ??
undefined,
this.discoverySeed ? this.discoverySeed : undefined,
loggingEnabled: true,
}).setMaxListeners(20);

Expand Down
20 changes: 12 additions & 8 deletions src/DAppPeerConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class DAppPeerConnect {

protected identicon: string | null = null;

protected onConnect?: (address: string) => void;
protected onConnect?: (address: string, walletInfo?: IWalletInfo) => void;
protected onDisconnect?: (address: string) => void;
protected onApiEject?: (name: string, address: string) => void;
protected onApiInject?: (name: string, address: string) => void;
Expand Down Expand Up @@ -204,7 +204,8 @@ export default class DAppPeerConnect {
if (!this.connectedWallet) {
const connectWallet = (
granted: boolean,
allowAutoConnect: boolean = false
allowAutoConnect: boolean = false,
connectedWalletInfo?: IWalletInfo
) => {
if (walletInfo.requestAutoconnect && granted && allowAutoConnect) {
AutoConnectHelper.addAutoConnectId(address);
Expand All @@ -227,7 +228,7 @@ export default class DAppPeerConnect {
this.generateIdenticon();

if (this.onConnect) {
this.onConnect(address);
this.onConnect(address, connectedWalletInfo);
}
} else {
callback({
Expand All @@ -245,13 +246,10 @@ export default class DAppPeerConnect {

if (typeof verifyConnection !== 'undefined') {
if (AutoConnectHelper.isAutoConnectId(address)) {
connectWallet(true);
connectWallet(true, true, walletInfo);
} else {
verifyConnection(
{
...walletInfo,
address: address,
},
walletInfo,
connectWallet
);
}
Expand Down Expand Up @@ -452,6 +450,12 @@ export default class DAppPeerConnect {
`injected api of ${args.api.name} into window.cardano`
);

callback({
dApp: this.dAppInfo,
connected: true,
error: false
});

if (onApiInject) {
onApiInject(args.api.name, address);
}
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export interface DAppPeerConnectParameters {
loggingEnabled?: boolean;
verifyConnection?: (
walletInfo: IWalletInfo,
callback: (granted: boolean, allowAutoConnect: boolean) => void
callback: (granted: boolean, allowAutoConnect: boolean, walletInfo?: IWalletInfo) => void
) => void;
onConnect?: (address: string) => void;
onConnect?: (address: string, walletInfo?: IWalletInfo) => void;
onDisconnect?: (address: string) => void;
onApiEject?: (name: string, address: string) => void;
onApiInject?: (name: string, address: string) => void;
Expand Down

0 comments on commit 113e340

Please sign in to comment.