Skip to content

Commit

Permalink
Merge pull request #10 from elven-js/adjust-callbacks
Browse files Browse the repository at this point in the history
adjust callbacks
  • Loading branch information
juliancwirko authored Jan 29, 2024
2 parents 953aaf6 + 8f5b2f1 commit d5f15a2
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 132 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [0.17.0](https://github.com/elven-js/elven.js/releases/tag/v0.17.0) (2024-01-29)
- remove onLoginEnd and onLogoutEnd callbacks. With success and failure callbacks, they are not needed
- fix duplicate callbacks calls

### [0.16.0](https://github.com/elven-js/elven.js/releases/tag/v0.16.0) (2024-01-28)
- rename and add more login callbacks (breaking)
- rename some of the transaction and message signing callbacks (breaking)
Expand Down
40 changes: 20 additions & 20 deletions build/elven.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions build/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export interface InitOptions {
walletConnectV2ProjectId?: string;
walletConnectV2RelayAddresses?: string[];
onLoginStart?: () => void;
onLoginEnd?: () => void;
onLoginSuccess?: () => void;
onLoginFailure?: (error: string) => void;
onLogoutStart?: () => void;
onLogoutEnd?: () => void;
onLogoutSuccess?: () => void;
onLogoutFailure?: (error: string) => void;
onQrPending?: () => void;
Expand All @@ -34,11 +32,9 @@ export interface InitOptions {
}
export declare enum EventStoreEvents {
onLoginStart = "onLoginStart",
onLoginEnd = "onLoginEnd",
onLoginSuccess = "onLoginSuccess",
onLoginFailure = "onLoginFailure",
onLogoutStart = "onLogoutStart",
onLogoutEnd = "onLogoutEnd",
onLogoutSuccess = "onLogoutSuccess",
onLogoutFailure = "onLogoutFailure",
onQrPending = "onQrPending",
Expand Down
40 changes: 20 additions & 20 deletions example/elven.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,10 @@ <h3>Other demos:</h3>
// You could also rely on try catch to some extent, but callbacks in one place seems convenient
// Login callbacks:
onLoginStart: () => { uiPending(true) },
onLoginEnd: () => { uiPending(false) },
onLoginSuccess: () => { uiLoggedInState(true); },
onLoginFailure: (error) => { displayError(error); },
// Logout callbacks:
onLogoutStart: () => { uiPending(true) },
onLogoutEnd: () => { uiPending(false) },
onLogoutSuccess: () => { uiLoggedInState(false); },
onLogoutFailure: (error) => { displayError(error); },
// Transaction callbacks
Expand Down
92 changes: 46 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elven.js",
"version": "0.16.0",
"version": "0.17.0",
"description": "Authenticate, sign and send transactions on the MultiversX blockchain in the browser.",
"type": "module",
"module": "build/elven.js",
Expand Down Expand Up @@ -49,8 +49,8 @@
"@multiversx/sdk-web-wallet-provider": "3.2.0",
"@types/qrcode": "1.5.5",
"@types/serve-handler": "6.1.4",
"@typescript-eslint/eslint-plugin": "6.19.1",
"@typescript-eslint/parser": "6.19.1",
"@typescript-eslint/eslint-plugin": "6.20.0",
"@typescript-eslint/parser": "6.20.0",
"esbuild": "0.20.0",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
Expand Down
7 changes: 1 addition & 6 deletions src/auth/init-mobile-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
} from '@multiversx/sdk-wallet-connect-provider/out/walletConnectV2Provider';
import { networkConfig } from '../utils/constants';
import { logout } from './logout';
import { accountSync } from './account-sync';
import { EventsStore } from '../events-store';
import { getRandomAddressFromNetwork } from '../utils/get-random-address-from-network';
import { EventStoreEvents } from '../types';

export const initMobileProvider = async (elven: any) => {
if (
Expand All @@ -18,9 +15,7 @@ export const initMobileProvider = async (elven: any) => {
}

const providerHandlers = {
onClientLogin: () => {
accountSync(elven), EventsStore.run(EventStoreEvents.onLoginSuccess);
},
onClientLogin: () => {},
onClientLogout: () => logout(elven),
onClientEvent: (event: SessionEventTypes['event']) => {
console.log('wc2 session event: ', event);
Expand Down
8 changes: 3 additions & 5 deletions src/auth/login-with-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export const loginWithExtension = async (
try {
if (dappProvider) {
const address = await dappProvider.login(providerLoginData);
if (address) {
EventsStore.run(EventStoreEvents.onLoginStart);
} else {
if (!address) {
throw new Error('There were problems while logging in!');
}
}
Expand Down Expand Up @@ -63,15 +61,15 @@ export const loginWithExtension = async (

await accountSync(elven);

EventsStore.run(EventStoreEvents.onLoginSuccess);

const accessToken = nativeAuthClient.getToken(
address,
loginToken,
signature
);
ls.set('accessToken', accessToken);

EventsStore.run(EventStoreEvents.onLoginSuccess);

return dappProvider;
} catch (e: any) {
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion src/auth/login-with-mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const loginWithMobile = async (
const providerHandlers = {
onClientLogin: async () => {
if (elven.dappProvider instanceof WalletConnectV2Provider) {
EventsStore.run(EventStoreEvents.onLoginStart);
const address = await elven.dappProvider.getAddress();
const signature = await elven.dappProvider.getSignature();

Expand Down
1 change: 0 additions & 1 deletion src/auth/login-with-web-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const loginWithWebWallet = async (
};

try {
EventsStore.run(EventStoreEvents.onLoginStart);
ls.set(
'loginMethod',
networkConfig[chainType].xAliasAddress === urlAddress
Expand Down
2 changes: 0 additions & 2 deletions src/auth/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ export const logout = async (elven: any) => {
const err = errorParse(e);
console.warn(`Something went wrong trying to logout the user: ${err}`);
EventsStore.run(EventStoreEvents.onLogoutFailure, err);
} finally {
EventsStore.run(EventStoreEvents.onLogoutEnd);
}
};
6 changes: 0 additions & 6 deletions src/initialize-events-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export const initializeEventsStore = (initOptions: InitOptions) => {
initOptions.onLoginFailure
);
}
if (initOptions.onLoginEnd) {
EventsStore.set(EventStoreEvents.onLoginEnd, initOptions.onLoginEnd);
}

// Logout initialiation
if (initOptions.onLogoutStart) {
Expand All @@ -38,9 +35,6 @@ export const initializeEventsStore = (initOptions: InitOptions) => {
initOptions.onLogoutFailure
);
}
if (initOptions.onLogoutEnd) {
EventsStore.set(EventStoreEvents.onLogoutEnd, initOptions.onLogoutEnd);
}

// Qr code initialization
if (initOptions.onQrPending) {
Expand Down
Loading

0 comments on commit d5f15a2

Please sign in to comment.