Skip to content

Commit

Permalink
add xalias support
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Oct 27, 2023
1 parent 1ea0b51 commit 8c3ff06
Show file tree
Hide file tree
Showing 17 changed files with 1,022 additions and 854 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [0.13.0](https://github.com/elven-js/elven.js/releases/tag/v0.13.0) (2023-10-27)
- add xAlias login support `ElvenJS.login('x-alias')` (check the [docs](https://www.elvenjs.com) and [demo example](/example/index.html))
- update dependencies

### [0.12.0](https://github.com/elven-js/elven.js/releases/tag/v0.12.0) (2023-08-05)
- improve guardian support (all providers)
- update dependencies
Expand Down
40 changes: 20 additions & 20 deletions build/elven.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/types/auth/login-with-web-wallet.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { WalletProvider } from '@multiversx/sdk-web-wallet-provider/out/walletProvider';
export declare const loginWithWebWallet: (webWalletAddress: string, loginToken: string, callbackRoute?: string) => Promise<WalletProvider | undefined>;
export declare const loginWithWebWallet: (urlAddress: string, loginToken: string, chainType: string, callbackRoute?: string) => Promise<WalletProvider | undefined>;
2 changes: 1 addition & 1 deletion build/types/interaction/web-wallet-tx-finalize.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { DappProvider } from '../types';
import { ApiNetworkProvider } from '../network-provider';
export declare const webWalletTxFinalize: (dappProvider: DappProvider, networkProvider: ApiNetworkProvider, walletUrlAddress: string, nonce: number) => Promise<void>;
export declare const webWalletTxFinalize: (dappProvider: DappProvider, networkProvider: ApiNetworkProvider, urlAddress: string, nonce: number) => Promise<void>;
3 changes: 2 additions & 1 deletion build/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export declare enum LoginMethodsEnum {
ledger = "ledger",
mobile = "mobile",
webWallet = "web-wallet",
browserExtension = "browser-extension"
browserExtension = "browser-extension",
xAlias = "x-alias"
}
export type DappProvider = ExtensionProvider | WalletConnectV2Provider | WalletProvider | undefined;
export interface LoginOptions {
Expand Down
1 change: 1 addition & 0 deletions build/types/utils/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface NetworkType {
decimals: string;
gasPerDataByte: string;
walletAddress: string;
xAliasAddress: string;
apiAddress: string;
explorerAddress: string;
apiTimeout: number;
Expand Down
3 changes: 3 additions & 0 deletions example/demo-ui-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const uiLoggedInState = (loggedIn) => {
);
const loginButton = document.getElementById('button-login-mobile');
const loginWebButton = document.getElementById('button-login-web');
const loginXaliasButton = document.getElementById('button-login-x-alias');
const logoutButton = document.getElementById('button-logout');
const txButton = document.getElementById('button-tx');
const txEsdtButton = document.getElementById('button-tx-esdt');
Expand All @@ -26,6 +27,7 @@ export const uiLoggedInState = (loggedIn) => {
loginExtensionButton.style.display = 'none';
loginButton.style.display = 'none';
loginWebButton.style.display = 'none';
loginXaliasButton.style.display = 'none';
logoutButton.style.display = 'block';
txButton.style.display = 'block';
txEsdtButton.style.display = 'block';
Expand All @@ -35,6 +37,7 @@ export const uiLoggedInState = (loggedIn) => {
loginExtensionButton.style.display = 'block';
loginButton.style.display = 'block';
loginWebButton.style.display = 'block';
loginXaliasButton.style.display = 'block';
logoutButton.style.display = 'none';
txButton.style.display = 'none';
txEsdtButton.style.display = 'none';
Expand Down
40 changes: 20 additions & 20 deletions example/elven.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
with xPortal</button>
<button class="button" id="button-login-web" style="display: block;">Login
with Web Wallet</button>
<button class="button" id="button-login-x-alias" style="display: block;">Login
with xAlias</button>

<button class="button" id="button-logout" style="display: none;">Logout</button>
<a class="button right" href="https://github.com/elven-js/elven.js" target="_blank"
Expand Down Expand Up @@ -221,6 +223,17 @@ <h3>Other demos:</h3>
}
});

document.getElementById('button-login-x-alias').addEventListener('click', async () => {
try {
clearQrCodeContainer();
await ElvenJS.login('x-alias', {
callbackRoute: '/',
});
} catch (e) {
console.log('Login: Something went wrong, try again!', e?.message);
}
});

document.getElementById('button-logout').addEventListener('click', async () => {
try {
const isLoggedOut = await ElvenJS.logout();
Expand All @@ -237,9 +250,10 @@ <h3>Other demos:</h3>
const demoMessage = 'Transaction demo from Elven.js!';

const isGuardian = ElvenJS.storage.get('activeGuardian');
const isXalias = ElvenJS.storage.get('loginMethod') === 'x-alias';
// Additional 50000 when there is an active guardian
// See more about gas limit calculation here: https://docs.multiversx.com/developers/gas-and-fees/overview/
const gasLimit = (isGuardian ? 100000 : 50000) + 1500 * demoMessage.length;
const gasLimit = ((isGuardian || isXalias) ? 100000 : 50000) + 1500 * demoMessage.length;

const tx = new Transaction({
nonce: ElvenJS.storage.get('nonce'),
Expand Down
Loading

0 comments on commit 8c3ff06

Please sign in to comment.