Skip to content

Commit

Permalink
Merge pull request #11 from useElven/migrate-sdk-core-13
Browse files Browse the repository at this point in the history
migrate to sdk core 13
  • Loading branch information
juliancwirko authored Apr 13, 2024
2 parents 1839545 + bff4f78 commit dc795e6
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 485 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### [0.19.0](https://github.com/useElven/core/releases/tag/v0.19.0) (2024-04-13)
- update @multiversx/sdk-core library (v13)
- **breaking**: with this version the @multiversx/sdk-core is now a peer dependency, you must have it in your project to work with useElven, at least v13.0.0. So, as always, freeze on 0.18.0 if you still need to use older sdk-core
- **breaking**: `useScDeploy` hook accepts different set of arguments
- **breaking**: `useMultiTokenTransfer` is renamed to `useTokenTransfer`. The old `useTokenTransfer` has been removed. You should use the same hook for single and multi-transfers. Now, gasLimit param is required when transferring to a smart contract using the provided endpoint name. For standard transfers, the gas limit isn't required
- added two simple utilities for parsing and formating amounts: `formatAmount` and `parseAmount`

### [0.18.0](https://github.com/useElven/core/releases/tag/v0.18.0) (2024-03-30)
- unify path calbacks for useLogin
- update dependencies
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const handleSendTx = () => {
address: 'erd123.....',
gasLimit: 50000 + 1500 * demoMessage.length, // When guarded additional 50000 will be added internally
data: new TransactionPayload(demoMessage),
value: TokenTransfer.egldFromBigInteger(1_000_000_000_000_000_000),
value: BigInt('1000000000000000000'),
});
};
```
Expand All @@ -85,6 +85,8 @@ See ready to use demo templates:
- [Next.js Dapp Template (App Router with Shadcn UI, Tailwind, Radix UI)](https://github.com/xdevguild/nextjs-dapp-template)
- [React + Vite Dapp Template (with Chakra UI)](https://github.com/useElven/react-vite)

Check [buildo.dev](https://www.buildo.dev) as a real world app that uses useElven lib.

### Development

- `npm install`
Expand Down
359 changes: 180 additions & 179 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@useelven/core",
"version": "0.18.0",
"version": "0.19.0",
"description": "Core React hooks for MultiversX DApps",
"license": "MIT",
"author": "Julian Ćwirko <julian.io>",
Expand Down Expand Up @@ -65,23 +65,24 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@multiversx/sdk-core": "12.19.1",
"@multiversx/sdk-extension-provider": "3.0.0",
"@multiversx/sdk-hw-provider": "6.4.0",
"@multiversx/sdk-native-auth-client": "1.0.8",
"@multiversx/sdk-network-providers": "2.4.3",
"@multiversx/sdk-wallet-connect-provider": "4.1.1",
"@multiversx/sdk-web-wallet-provider": "3.2.1",
"bignumber.js": "9.1.2",
"lodash.clonedeep": "4.5.0",
"swr": "2.2.5",
"valtio": "1.13.2"
},
"devDependencies": {
"@multiversx/sdk-core": "13.0.1",
"@types/lodash.clonedeep": "4.5.9",
"@types/node": "20.12.2",
"@types/react": "18.2.73",
"@typescript-eslint/eslint-plugin": "7.4.0",
"@typescript-eslint/parser": "7.4.0",
"@types/node": "20.12.7",
"@types/react": "18.2.78",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
Expand All @@ -90,9 +91,10 @@
"prettier": "3.2.5",
"rimraf": "5.0.5",
"tsup": "8.0.2",
"typescript": "5.4.3"
"typescript": "5.4.5"
},
"peerDependencies": {
"@multiversx/sdk-core": "^13.0.0",
"react": "^18.2.0"
}
}
4 changes: 3 additions & 1 deletion src/hooks/common-helpers/useDappProvidersSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export const useDappProvidersSync = (
}
}
};
askForDappProvider();
if (accountDone && loginInfoDone) {
askForDappProvider();
}
}, [accountDone, loginInfoDone]);
};
2 changes: 1 addition & 1 deletion src/hooks/useApiCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface FetcherArgs {
baseEndpoint?: string;
}

export async function apiCallFetcher({
async function apiCallFetcher({
url,
type,
payload,
Expand Down
159 changes: 0 additions & 159 deletions src/hooks/useMultiTokenTransfer.tsx

This file was deleted.

45 changes: 30 additions & 15 deletions src/hooks/useScDeploy.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Address,
Code,
SmartContract,
CodeMetadata,
TypedValue,
SmartContractTransactionsFactory,
TransactionsFactoryConfig,
Code,
} from '@multiversx/sdk-core';
import { useTransaction, TransactionArgs } from './useTransaction';
import { useAccount } from './useAccount';
Expand All @@ -19,7 +19,10 @@ export interface ScDeployHookProps {
export interface ScDeployArgs<T> {
source: Buffer | string;
gasLimit?: number;
codeMetadata?: [boolean, boolean, boolean, boolean];
isUpgradeable?: boolean;
isReadable?: boolean;
isPayable?: boolean;
isPayableBySmartContract?: boolean;
initArguments?: T[];
}

Expand All @@ -42,30 +45,42 @@ export const useScDeploy = (
const deploy = async function <T extends TypedValue>({
source,
gasLimit = 10_000_000,
codeMetadata = [true, false, false, false],
initArguments = [],
isUpgradeable = true,
isReadable = false,
isPayable = false,
isPayableBySmartContract = false,
}: ScDeployArgs<T>) {
try {
let code: Code;
let code: Uint8Array;

if (Buffer.isBuffer(source)) {
code = Code.fromBuffer(source);
code = Code.fromBuffer(source).valueOf();
} else {
const response = await fetch(source);
const bytes = await response.arrayBuffer();
code = Code.fromBuffer(Buffer.from(bytes));
code = Code.fromBuffer(Buffer.from(bytes)).valueOf();
}

const smartContract = new SmartContract();
const tx = smartContract.deploy({
deployer: new Address(accountAddress),
code,
codeMetadata: new CodeMetadata(...codeMetadata),
initArguments,
gasLimit,
const factoryConfig = new TransactionsFactoryConfig({
chainID: shortId || 'D',
});

const factory = new SmartContractTransactionsFactory({
config: factoryConfig,
});

const tx = factory.createTransactionForDeploy({
sender: new Address(accountAddress),
bytecode: code,
isUpgradeable,
isReadable,
isPayable,
isPayableBySmartContract,
arguments: initArguments,
gasLimit: BigInt(gasLimit),
});

tx.setNonce(nonce);

triggerTx({ tx });
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useScQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ interface FetcherArgs {
payload: Record<string, unknown> | undefined;
}

export interface VMOutput {
interface VMOutput {
data: { data: string | number };
error: string;
code: string;
}

export const scQueryFetcher: Fetcher<VMOutput, FetcherArgs> = async ({
const scQueryFetcher: Fetcher<VMOutput, FetcherArgs> = async ({
url,
payload,
}) => await apiCall.post(url, payload || {});
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useSignMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ export const useSignMessage = () => {

if (networkStateSnap.dappProvider instanceof ExtensionProvider) {
const signedMessage = await networkStateSnap.dappProvider.signMessage(
// TODO: SignableMessage is deprecated, replace when signing providers are ready
new SignableMessage({ message: Buffer.from(message) })
);

setSignature(signedMessage.getSignature().toString('hex'));
}
if (networkStateSnap.dappProvider instanceof WalletConnectV2Provider) {
const signedMessage = await networkStateSnap.dappProvider.signMessage(
// TODO: SignableMessage is deprecated, replace when signing providers are ready
new SignableMessage({ message: Buffer.from(message) })
);

setSignature(signedMessage.getSignature().toString('hex'));
}
if (networkStateSnap.dappProvider instanceof HWProvider) {
const signedMessage = await networkStateSnap.dappProvider.signMessage(
// TODO: SignableMessage is deprecated, replace when signing providers are ready
new SignableMessage({ message: Buffer.from(message) })
);

Expand All @@ -80,6 +83,7 @@ export const useSignMessage = () => {
`${window.location.origin}${options?.callbackUrl || ''}` ||
window?.location.href;
await networkStateSnap.dappProvider.signMessage(
// TODO: SignableMessage is deprecated, replace when signing providers are ready
new SignableMessage({ message: Buffer.from(message) }),
{
callbackUrl: encodeURIComponent(
Expand Down
Loading

0 comments on commit dc795e6

Please sign in to comment.