Skip to content

Commit

Permalink
add query callbacks and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Jan 28, 2024
1 parent 8eddaf6 commit 16ca4db
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 362 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### [0.16.0](https://github.com/elven-js/elven.js/releases/tag/v0.16.0) (2024-01-...)
- rename and add more login callbacks (breaking) (check [docs](https://www.elvenjs.com/docs/sdk-reference.html#login))
- add callbacks for logout (check [docs](https://www.elvenjs.com/docs/sdk-reference.html#logout))
- add callbacks for `queryContract` (check [docs](https://www.elvenjs.com/docs/sdk-reference.html#querying-a-smart-contract))
- rename and add more login callbacks (breaking)
- rename some of the transaction and message signing callbacks (breaking)
- add callbacks for logout
- add callbacks for `queryContract`
- check [docs](https://www.elvenjs.com/docs/sdk-reference.html#initialization) and [example demo](/example/index.html) for more information

### [0.15.0](https://github.com/elven-js/elven.js/releases/tag/v0.15.0) (2024-01-13)
- add webview provider (based on sdk-dapp), required for xPortal Hub integration (experimental, need more tests and rewrites, it will probably land in a separate package in the following updates)
Expand Down
38 changes: 19 additions & 19 deletions build/elven.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions build/types/network-provider.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference types="node" />
import BigNumber from 'bignumber.js';
import { Address } from '@multiversx/sdk-core/out/address';
import { TransactionStatus } from '@multiversx/sdk-network-providers/out/transactionStatus';
import { TransactionReceipt } from '@multiversx/sdk-network-providers/out/transactionReceipt';
Expand All @@ -18,7 +17,7 @@ export type NetworkProviderOptions = Pick<InitOptions, 'apiUrl' | 'chainType' |
export interface AccountOnNetwork {
address: IAddress;
nonce: number;
balance: BigNumber;
balance: bigint;
code: string;
userName: string;
}
Expand Down
24 changes: 16 additions & 8 deletions build/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Transaction } from '@multiversx/sdk-core/out/transaction';
import { WalletConnectV2Provider } from '@multiversx/sdk-wallet-connect-provider/out/walletConnectV2Provider';
import { WalletProvider } from '@multiversx/sdk-web-wallet-provider/out/walletProvider';
import { WebviewProvider } from './webview-provider/webview-provider';
import { QueryArguments } from '@multiversx/sdk-core/out/smartcontracts';
import { ContractQueryResponse } from '@multiversx/sdk-network-providers/out/contractQueryResponse';
export interface InitOptions {
apiUrl?: string;
chainType?: string;
Expand All @@ -19,13 +21,16 @@ export interface InitOptions {
onLogoutFailure?: (error: string) => void;
onQrPending?: () => void;
onQrLoaded?: () => void;
onTxStarted?: (transaction: Transaction) => void;
onTxStart?: (transaction: Transaction) => void;
onTxSent?: (transaction: Transaction) => void;
onTxFinalized?: (transaction: Transaction) => void;
onTxError?: (transaction: Transaction, error: string) => void;
onSignMsgStarted?: (message: string) => void;
onTxFailure?: (transaction: Transaction, error: string) => void;
onSignMsgStart?: (message: string) => void;
onSignMsgFinalized?: (messageSignature: string) => void;
onSignMsgError?: (message: string, error: string) => void;
onSignMsgFailure?: (message: string, error: string) => void;
onQueryStart?: (queryArgs: QueryArguments) => void;
onQueryFinalized?: (queryResponse: ContractQueryResponse) => void;
onQueryFailure?: (queryArgs: QueryArguments, error: string) => void;
}
export declare enum EventStoreEvents {
onLoginStart = "onLoginStart",
Expand All @@ -38,13 +43,16 @@ export declare enum EventStoreEvents {
onLogoutFailure = "onLogoutFailure",
onQrPending = "onQrPending",
onQrLoaded = "onQrLoaded",
onTxStarted = "onTxStarted",
onTxStart = "onTxStart",
onTxSent = "onTxSent",
onTxFinalized = "onTxFinalized",
onTxError = "onTxError",
onSignMsgStarted = "onSignMsgStarted",
onTxFailure = "onTxFailure",
onSignMsgStart = "onSignMsgStart",
onSignMsgFinalized = "onSignMsgFinalized",
onSignMsgError = "onSignMsgError"
onSignMsgFailure = "onSignMsgFailure",
onQueryStart = "onQueryStart",
onQueryFinalized = "onQueryFinalized",
onQueryFailure = "onQueryFailure"
}
export declare enum LoginMethodsEnum {
ledger = "ledger",
Expand Down
2 changes: 1 addition & 1 deletion build/types/utils/with-login-events.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const withLoginEvents: (fn: () => Promise<void>) => Promise<void>;
export declare const withLoginEvents: (fn: (onLoginSuccess: () => void) => Promise<void>) => Promise<void>;
2 changes: 1 addition & 1 deletion build/types/webview-provider/webview-provider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Based on sdk-dapp webview provider implementation
* It will probably be replaced with separate library in the future
*/
import { Transaction } from '@multiversx/sdk-core';
import { Transaction } from '@multiversx/sdk-core/out/transaction';
export declare class WebviewProvider {
constructor();
logout(): Promise<unknown>;
Expand Down
6 changes: 0 additions & 6 deletions esbuild.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ const fs = require('fs');
esbuild
.build({
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer',
'process.env.NODE_ENV': '"production"',
},
format: 'esm',
entryPoints: ['./src/elven.ts'],
bundle: true,
Expand Down
38 changes: 19 additions & 19 deletions example/elven.js

Large diffs are not rendered by default.

58 changes: 26 additions & 32 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,34 +188,45 @@ <h3>Other demos:</h3>
// Remember to change it. Get yours here: https://cloud.walletconnect.com/sign-in
walletConnectV2ProjectId: 'f502675c63610bfe4454080ac86d70e6',
walletConnectV2RelayAddresses: ['wss://relay.walletconnect.com'],
// Login callbacks
// All callbacks are optional
// 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
// Logout callbacks:
onLogoutStart: () => { uiPending(true) },
onLogoutEnd: () => { uiPending(false) },
onLogoutSuccess: () => { uiLoggedInState(false); },
onLogoutFailure: (error) => { displayError(error); },
// Query callbacks
// TODO:
// onQueryStart
// onQueryEnd
// onQuerySuccess
// onQueryFailure
// Transaction callbacks
onTxStarted: (tx) => { uiPending(true); },
onTxStart: (tx) => { uiPending(true); },
onTxSent: (tx) => { const hash = tx.getHash().toString(); hash && updateTxHashContainer(hash, true); },
onTxFinalized: (tx) => { tx?.hash && updateTxHashContainer(tx.hash); uiPending(false); },
onTxError: (tx, error) => { displayError(error); uiPending(false); },
// Qr callbacks
onTxFailure: (tx, error) => { displayError(error); uiPending(false); },
// Qr code callbacks:
onQrPending: () => { uiPending(true); },
onQrLoaded: () => { uiPending(false); },
// Signing callbacks
onSignMsgStarted: () => { uiPending(true); },
// Signing callbacks:
onSignMsgStart: (message) => { uiPending(true); },
onSignMsgFinalized: (message, messageSignature) => { messageSignature && updateOperationResultContainer(`➡️ The signature for "${message}" message:\n${messageSignature}`); uiPending(false); },
onSignMsgError: (message, error) => { displayError(error); uiPending(false); },
onSignMsgFailure: (message, error) => { displayError(error); uiPending(false); },
// Query callbacks:
onQueryStart: (queryArgs) => { uiPending(true); },
onQueryFinalized: (queryResponse) => {
// Manual decoding of a simple type (number here), there will be additional tools for that using ABI
// For now please check data converter in Buildo.dev:
// https://github.com/xdevguild/buildo.dev/blob/main/components/operations/utils-operations/data-converters.tsx#L103
const hexVal = base64ToDecimalHex(queryResponse?.returnData?.[0]);
let intVal = 0;
if (hexVal) {
intVal = parseInt(hexVal, 16);
}
updateOperationResultContainer(`➡️ The result of the query is: ${intVal}`);
uiPending(false);
},
onQueryFailure: (queryArgs, error) => { displayError(error); uiPending(false); }
}
);
}
Expand Down Expand Up @@ -368,28 +379,12 @@ <h3>Other demos:</h3>
// Read more about the Elven Tools Smart Contract here: https://www.elven.tools/docs/sc-endpoints.html
document.getElementById('button-query').addEventListener('click', async () => {
try {
updateOperationResultContainer();
uiPending(true);

const results = await ElvenJS.queryContract({
await ElvenJS.queryContract({
address: new Address(nftMinterSmartContract),
func: new ContractFunction('getMintedPerAddressTotal'),
args: [new AddressValue(new Address(ElvenJS.storage.get('address')))]
});

uiPending(false);

// Manual decoding of a simple type (number here), there will be additional tools for that using ABI
// For now please check data converter in Buildo.dev:
// https://github.com/xdevguild/buildo.dev/blob/main/components/operations/utils-operations/data-converters.tsx#L103
const hexVal = base64ToDecimalHex(results?.returnData?.[0]);
let intVal = 0;
if (hexVal) {
intVal = parseInt(hexVal, 16);
}
updateOperationResultContainer(`➡️ The result of the query is: ${intVal}`);
} catch (e) {
uiPending(false);
throw new Error(e?.message);
}
});
Expand All @@ -401,7 +396,6 @@ <h3>Other demos:</h3>
try {
await ElvenJS.signMessage('Elven Family is awesome!');
} catch (e) {
uiPending(false);
throw new Error(e?.message);
}
});
Expand Down
Loading

0 comments on commit 16ca4db

Please sign in to comment.