Skip to content

Commit

Permalink
Merge branch 'main' into walletconnect-v2
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	build/elven.js
#	build/types/auth/init-maiar-mobile-provider.d.ts
#	build/types/types.d.ts
#	build/types/utils/constants.d.ts
#	example/elven.js
#	example/index.html
#	package.json
#	src/auth/init-maiar-mobile-provider.ts
#	src/auth/login-with-mobile.ts
#	src/types.ts
#	src/utils/constants.ts
  • Loading branch information
juliancwirko committed Nov 6, 2022
2 parents 768c409 + 94f6bb2 commit e36ebbd
Show file tree
Hide file tree
Showing 31 changed files with 34 additions and 336 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### [0.7.0](https://github.com/juliancwirko/elven.js/releases/tag/v0.7.0) (2022-10-19)
### [0.7.0](https://github.com/juliancwirko/elven.js/releases/tag/v0.7.0) (2022-11-...)
- WalletConnect 2 integration through new version of `@elrondnetwork/erdjs-wallet-connect-provider` - let's you use 'Maiar Login 2.0'. No fallback for the old method. We'll see if it is needed.

### [0.6.1](https://github.com/juliancwirko/elven.js/releases/tag/v0.6.1) (2022-10-31)
- make the WalletConnect bridge addresses configurable. You can use `ElvenJS.init({ walletConnectBridgeAddresses: ['https://...'], })` to overwrite the default ones.

### [0.6.0](https://github.com/juliancwirko/elven.js/releases/tag/v0.6.0) (2022-10-16)
- Elrond Web Wallet support
- new way of getting the last transaction status, you can now use a callback function defined when initializing the ElvenJS: `onTxFinalized: (tx) => { ... }`. Check for more info in the docs. You can still use the return value from `await ElvenJS.signAndSendTransaction(tx)`, but it won't work for the Web Wallet (because of its redirections and different flow).
Expand Down
55 changes: 0 additions & 55 deletions build/elven.js

This file was deleted.

1 change: 0 additions & 1 deletion build/types/auth/account-sync.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/expires-at.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/init-extension-provider.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/init-maiar-mobile-provider.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/init-web-wallet-provider.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/auth/login-with-extension.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/login-with-mobile.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions build/types/auth/login-with-web-wallet.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/auth/logout.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/auth/qr-code-builder.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions build/types/elven.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions build/types/events-store.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions build/types/interaction/post-send-tx.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions build/types/interaction/web-wallet-tx-finalize.d.ts

This file was deleted.

40 changes: 0 additions & 40 deletions build/types/main.d.ts

This file was deleted.

61 changes: 0 additions & 61 deletions build/types/network-provider.d.ts

This file was deleted.

30 changes: 0 additions & 30 deletions build/types/types.d.ts

This file was deleted.

24 changes: 0 additions & 24 deletions build/types/utils/constants.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/utils/error-parse.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/utils/get-param-from-url.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion build/types/utils/get-random-address-from-network.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions build/types/utils/ls-helpers.d.ts

This file was deleted.

55 changes: 0 additions & 55 deletions example/elven.js

This file was deleted.

6 changes: 5 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ <h3>Other demos:</h3>
AddressValue,
} from './elven.js';

// Options are the defaults
// Options are the defaults and here only to show all of them
// You don't have to add them if you want to use default setup
// You can only add your custom callbacks
const initElven = async () => {
await ElvenJS.init(
{
apiUrl: 'https://devnet-api.elrond.com',
chainType: 'devnet',
apiTimeout: 10000,
walletConnectV2ProjectId: 'f502675c63610bfe4454080ac86d70e6',
WalletConnectV2RelayAddresses: ['wss://relay.walletconnect.com'],
onLoginPending: () => { uiPending(true) },
onLoggedIn: () => { uiLoggedInState(true); uiPending(false); },
onLogout: () => { uiLoggedInState(false); },
Expand All @@ -181,6 +184,7 @@ <h3>Other demos:</h3>
});

document.getElementById('button-login-mobile').addEventListener('click', async () => {
clearQrCodeContainer();
try {
await ElvenJS.login('maiar-mobile', {
// You can also use the DOM element here:
Expand Down
7 changes: 2 additions & 5 deletions src/auth/init-maiar-mobile-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import {
SessionEventTypes,
WalletConnectV2Provider,
} from '@elrondnetwork/erdjs-wallet-connect-provider/out/walletConnectV2Provider';
import {
walletConnectV2RelayAddresses,
networkConfig,
} from '../utils/constants';
import { networkConfig } from '../utils/constants';
import { logout } from './logout';
import { accountSync } from './account-sync';
import { EventsStore } from '../events-store';
Expand All @@ -30,7 +27,7 @@ export const initMaiarMobileProvider = async (elven: any) => {
};

const relayAddress = getRandomAddressFromNetwork(
walletConnectV2RelayAddresses
elven.initOptions.walletConnectV2RelayAddresses
);

const dappProviderInstance = new WalletConnectV2Provider(
Expand Down
7 changes: 2 additions & 5 deletions src/auth/login-with-mobile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { errorParse } from '../utils/error-parse';
import { qrCodeBuilder } from './qr-code-builder';
import {
walletConnectV2RelayAddresses,
networkConfig,
} from '../utils/constants';
import { networkConfig } from '../utils/constants';
import { getRandomAddressFromNetwork } from '../utils/get-random-address-from-network';
import {
WalletConnectV2Provider,
Expand All @@ -29,7 +26,7 @@ export const loginWithMobile = async (
}

const relayAddress = getRandomAddressFromNetwork(
walletConnectV2RelayAddresses
elven.initOptions.walletConnectV2RelayAddresses
);

if (!relayAddress || !elven.networkProvider) {
Expand Down
17 changes: 14 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
networkConfig,
defaultApiEndpoint,
defaultChainTypeConfig,
defaultWalletConnectV2RelayAddresses,
} from './utils/constants';
import { getParamFromUrl } from './utils/get-param-from-url';
import { initWebWalletProvider } from './auth/init-web-wallet-provider';
Expand All @@ -47,9 +48,13 @@ export class ElvenJS {
return;
}

this.initOptions = options || {
this.initOptions = {
chainType: defaultChainTypeConfig,
apiUrl: defaultApiEndpoint,
apiTimeout: 10000,
walletConnectV2ProjectId: '',
walletConnectV2RelayAddresses: defaultWalletConnectV2RelayAddresses,
...options,
};

this.networkProvider = new ApiNetworkProvider(this.initOptions);
Expand Down Expand Up @@ -84,7 +89,10 @@ export class ElvenJS {
if (state.loginMethod === LoginMethodsEnum.maiarMobile) {
this.dappProvider = await initMaiarMobileProvider(this);
}
if (state.loginMethod === LoginMethodsEnum.webWallet) {
if (
state.loginMethod === LoginMethodsEnum.webWallet &&
this.initOptions.chainType
) {
this.dappProvider = await initWebWalletProvider(
networkConfig[this.initOptions.chainType].walletAddress
);
Expand Down Expand Up @@ -139,7 +147,10 @@ export class ElvenJS {
}

// Login with Web Wallet
if (loginMethod === LoginMethodsEnum.webWallet && this.initOptions) {
if (
loginMethod === LoginMethodsEnum.webWallet &&
this.initOptions?.chainType
) {
const dappProvider = await loginWithWebWallet(
networkConfig[this.initOptions.chainType].walletAddress,
options?.callbackRoute,
Expand Down
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { WalletConnectV2Provider } from '@elrondnetwork/erdjs-wallet-connect-pro
import { WalletProvider } from '@elrondnetwork/erdjs-web-wallet-provider/out/walletProvider';

export interface InitOptions {
apiUrl: string;
chainType: string;
apiTimeout: number;
apiUrl?: string;
chainType?: string;
apiTimeout?: number;
walletConnectV2ProjectId?: string;
walletConnectV2RelayAddresses?: string[];
onLoginPending?: () => void;
onLoggedIn?: () => void;
onLogout?: () => void;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const defaultChainTypeConfig = 'devnet';
export const walletConnectDeepLink =
'https://maiar.page.link/?apn=com.elrond.maiar.wallet&isi=1519405832&ibi=com.elrond.maiar.wallet&link=https://maiar.com/';

export const walletConnectV2RelayAddresses = ['wss://relay.walletconnect.com'];
export const defaultWalletConnectV2RelayAddresses = [
'wss://relay.walletconnect.com',
];

export const networkConfig: Record<string, NetworkType> = {
devnet: {
Expand Down

0 comments on commit e36ebbd

Please sign in to comment.