Skip to content

Commit 48aa498

Browse files
committed
add txResults in hooks, other improvements
1 parent 5a4035d commit 48aa498

20 files changed

+1075
-919
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ API_ALLOWED_DAPP_HOST = http://localhost:3000
5454
NEXT_PUBLIC_EGLD_TRANSFER_ADDRESS = erd17a4wydhhd6t3hhssvcp9g23ppn7lgkk4g2tww3eqzx4mlq95dukss0g50f
5555

5656
# The smart contract address used for minting the NFT token (as example deployed Elven Tools Smart Contract)
57-
NEXT_PUBLIC_MINT_SMART_CONTRACT_ADDRESS = erd1qqqqqqqqqqqqqpgq5za2pty2tlfqhj20z9qmrrpjmyt6advcgtkscm7xep
57+
NEXT_PUBLIC_MINT_SMART_CONTRACT_ADDRESS = erd1qqqqqqqqqqqqqpgqztp5vpqrxe2tha224jwsa3sv2800a88zgtksar2kc8
5858

5959
# The function/endpoint name for minting on the smart contract
6060
NEXT_PUBLIC_MINT_FUNCTION_NAME = mint

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### [4.3.0](https://github.com/xdevguild/nextjs-dapp-template/releases/tag/v4.3.0) (2023-01-28)
2+
- `txResults` is now returned in `useTransaction` and `useScTransaction` hooks (it is ITransactionOnNetwork in sdk-core)
3+
- dependencies updates
4+
15
### [4.2.0](https://github.com/xdevguild/nextjs-dapp-template/releases/tag/v4.2.0) (2023-01-14)
26
- rebrand to multiversx (continuation)
37
- npm packages are replaced

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It has straightforward and complete functionality.
1111
### Main assumption for the dapp:
1212

1313
- it works on Nextjs
14-
- it uses erdjs 11.* without the dapp-core library.
14+
- it uses sdk-core 11.* without the dapp-core library.
1515
it uses backed-side redirections to hide the API endpoint. The only exposed one is `/api/multiversx` and it is used only by the dapp internally
1616
- it uses the .env file - there is an example in the repo (for all configurations, also for the demo config)
1717
- it uses chakra-ui
@@ -58,7 +58,7 @@ const NextJSDappTemplate = ({ Component, pageProps }: AppProps) => {
5858

5959
#### LoginModalButton
6060

61-
The component provides the `Connect` button with the modal, which will contain another three buttons for four different authentication possibilities (Maiar Mobile App, Maiar Defi Wallet - browser extension, MultiversX Web Wallet). You should be able to use it in any place on the website.
61+
The component provides the `Connect` button with the modal, which will contain another three buttons for four different authentication possibilities (xPortal Mobile App, MultiversX Defi Wallet - browser extension, MultiversX Web Wallet). You should be able to use it in any place on the website.
6262

6363
```jsx
6464
import { LoginModalButton } from '../tools/LoginModalButton';
@@ -107,7 +107,7 @@ It can display the spinner and also the fallback React element.
107107
The hook provides all that is required for triggering transactions. useTransaction can also take a callback function as an argument.
108108

109109
```jsx
110-
const { pending, triggerTx, transaction, error } = useTransaction({ cb });
110+
const { pending, triggerTx, transaction, txResult, error } = useTransaction({ cb });
111111

112112
const handleSendTx = useCallback(() => {
113113
const demoMessage = 'Transaction demo!';
@@ -125,7 +125,7 @@ const handleSendTx = useCallback(() => {
125125
The hook provides all that is required for triggering smart contract transactions. useScTransaction can also take a callback function as an argument.
126126

127127
```jsx
128-
const { pending, triggerTx, transaction, error } = useScTransaction({ cb });
128+
const { pending, triggerTx, transaction, txResult, error } = useScTransaction({ cb });
129129

130130
const handleSendTx = useCallback(() => {
131131
triggerTx({
@@ -154,7 +154,7 @@ const {
154154
payload: {
155155
scAddress: process.env.NEXT_PUBLIC_MINT_SMART_CONTRACT_ADDRESS,
156156
funcName: process.env.NEXT_PUBLIC_QUERY_FUNCTION_NAME,
157-
args: [], // arguments for the query in hex format, you can use erdjs for that, for example: args: [ new Address('erd1....').hex() ] etc. It will be also simplified in the future.
157+
args: [], // arguments for the query in hex format, you can use sdk-core for that, for example: args: [ new Address('erd1....').hex() ] etc. It will be also simplified in the future.
158158
},
159159
autoInit: false, // you can enable or disable the trigger of the query on the component mount
160160
abiJSON: yourImportedAbiJSONObject // required for SCQueryType.COMPLEX type
@@ -172,7 +172,7 @@ const { data } = useScQuery<TypedOutcomeBundle>({
172172
payload: {
173173
scAddress: 'erd1qqq...',
174174
funcName: 'yourScFunction',
175-
args: [], // args in hex format, use erdjs for conversion, see above
175+
args: [], // args in hex format, use sdk-core for conversion, see above
176176
},
177177
autoInit: true,
178178
abiJSON,
@@ -193,7 +193,7 @@ interface TypedOutcomeBundle {
193193
}
194194
```
195195

196-
You can then process the data. For example `data.firstValue.valueOf()` or `data.firstValue.toString()` if applicable. The returned type can be further processed using erdjs.
196+
You can then process the data. For example `data.firstValue.valueOf()` or `data.firstValue.toString()` if applicable. The returned type can be further processed using sdk-core.
197197

198198
#### useLoggingIn()
199199

components/demo/SimpleDemo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const SimpleDemo = () => {
100100
</Box>
101101
{loginMethod === LoginMethodsEnum.walletconnect && (
102102
<Box>
103-
Confirm it on the Maiar mobile app and wait till it finishes.
103+
Confirm it on the xPortal mobile app and wait till it finishes.
104104
</Box>
105105
)}
106106
{loginMethod === LoginMethodsEnum.ledger && (
@@ -143,7 +143,7 @@ export const SimpleDemo = () => {
143143
<Text fontWeight="black" fontSize="xl" display="inline-block">
144144
{result.content}
145145
</Text>{' '}
146-
NFTs to mint left!
146+
NFTs left to mint!
147147
</Box>
148148
</>
149149
)}

components/tools/ActionButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const ActionButton: FC<PropsWithChildren<ActionButtonProps>> = ({
1616
}) => {
1717
const handleClick = useCallback(() => {
1818
if (!disabled) {
19-
onClick?.();
19+
onClick();
2020
}
2121
}, [disabled, onClick]);
2222

components/tools/MobileLoginQR.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const MobileLoginQR: FunctionComponent<MobileLoginQRProps> = ({
6464
rel="noopener noreferrer nofollow"
6565
target="_blank"
6666
>
67-
Maiar Login
67+
xPortal Login
6868
</Box>
6969
</Flex>
7070
) : null}

config/network.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const networkConfig: Record<string, NetworkType> = {
2424
walletConnectBridgeAddresses: ['https://bridge.walletconnect.org'],
2525
walletAddress: 'https://devnet-wallet.multiversx.com',
2626
apiAddress:
27-
process.env.NEXT_PUBLIC_MULTIVERSX_API || 'https://devnet-api.multiversx.com',
27+
process.env.NEXT_PUBLIC_MULTIVERSX_API ||
28+
'https://devnet-api.multiversx.com',
2829
explorerAddress: 'https://devnet-explorer.multiversx.com',
2930
apiTimeout: '4000',
3031
},

hooks/auth/useNetworkSync.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const useNetworkSync = () => {
135135
if (!dappProvider) {
136136
const networkConfiguration = getActiveNetworkConfiguration();
137137
switch (loginMethod) {
138-
// Browser extension auth (Maiar defi wallet)
138+
// Browser extension auth (MultiversX defi wallet)
139139
case LoginMethodsEnum.extension:
140140
dappProvider = ExtensionProvider.getInstance();
141141
try {
@@ -154,7 +154,7 @@ export const useNetworkSync = () => {
154154
console.warn("Can't initialize the Dapp Provider!");
155155
}
156156
break;
157-
// Maiar mobile app auth
157+
// xPortal mobile app auth
158158
case LoginMethodsEnum.walletconnect:
159159
const providerHandlers = {
160160
onClientLogin: () =>
@@ -178,7 +178,7 @@ export const useNetworkSync = () => {
178178
await dappProvider.init();
179179
if (!dappProvider.isInitialized()) {
180180
console.warn(
181-
'Something went wrong trying to sync with the Maiar app!'
181+
'Something went wrong trying to sync with the xPortal app!'
182182
);
183183
} else {
184184
network.setNetworkState('dappProvider', dappProvider);

hooks/core/common-helpers/sendTxOperations.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Tools used internally by sent transactions hooks
2-
import { Account, TransactionWatcher, Transaction } from '@multiversx/sdk-core';
2+
import {
3+
Account,
4+
TransactionWatcher,
5+
Transaction,
6+
ITransactionOnNetwork,
7+
} from '@multiversx/sdk-core';
38
import { ExtensionProvider } from '@multiversx/sdk-extension-provider';
49
import { WalletConnectProvider } from '@multiversx/sdk-wallet-connect-provider';
510
import { HWProvider } from '@multiversx/sdk-hw-provider';
@@ -15,18 +20,21 @@ export interface TransactionCb {
1520
transaction?: Transaction | null;
1621
error?: string;
1722
pending?: boolean;
23+
txResult?: ITransactionOnNetwork | null;
1824
}
1925

2026
export const postSendTxOperations = async (
2127
tx: Transaction,
2228
setTransaction: Dispatch<SetStateAction<Transaction | null>>,
29+
setTxResult: Dispatch<SetStateAction<ITransactionOnNetwork | null>>,
2330
apiNetworkProvider: ApiNetworkProvider,
2431
cb?: (params: TransactionCb) => void
2532
) => {
2633
const transactionWatcher = new TransactionWatcher(apiNetworkProvider);
27-
await transactionWatcher.awaitCompleted(tx);
34+
const txResult = await transactionWatcher.awaitCompleted(tx);
2835
setTransaction(tx);
29-
cb?.({ transaction: tx, pending: false });
36+
setTxResult(txResult);
37+
cb?.({ transaction: tx, pending: false, txResult });
3038
const sender = tx.getSender();
3139
const senderAccount = new Account(sender);
3240
const userAccountOnNetwork = await apiNetworkProvider.getAccount(sender);
@@ -42,6 +50,7 @@ export const sendTxOperations = async (
4250
loginInfoSnap: LoginInfoState,
4351
apiNetworkProvider: ApiNetworkProvider,
4452
setTransaction: Dispatch<SetStateAction<Transaction | null>>,
53+
setTxResult: Dispatch<SetStateAction<ITransactionOnNetwork | null>>,
4554
setError: Dispatch<SetStateAction<string>>,
4655
setPending: Dispatch<SetStateAction<boolean>>,
4756
webWalletRedirectUrl?: string,
@@ -65,7 +74,13 @@ export const sendTxOperations = async (
6574
}
6675
if (loginInfoSnap.loginMethod !== LoginMethodsEnum.wallet) {
6776
await apiNetworkProvider.sendTransaction(tx);
68-
await postSendTxOperations(tx, setTransaction, apiNetworkProvider, cb);
77+
await postSendTxOperations(
78+
tx,
79+
setTransaction,
80+
setTxResult,
81+
apiNetworkProvider,
82+
cb
83+
);
6984
}
7085
} catch (e) {
7186
const err = errorParse(e);

hooks/core/common-helpers/useWebWalletTxSend.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
WALLET_PROVIDER_CALLBACK_PARAM,
44
WALLET_PROVIDER_CALLBACK_PARAM_TX_SIGNED,
55
} from '@multiversx/sdk-web-wallet-provider';
6-
import { Transaction } from '@multiversx/sdk-core';
6+
import { Transaction, ITransactionOnNetwork } from '@multiversx/sdk-core';
77
import { useSnapshot } from 'valtio';
88
import { getParamFromUrl } from '../../../utils/getParamFromUrl';
99
import { getNetworkState } from '../../../store/network';
@@ -16,13 +16,15 @@ import { errorParse } from '../../../utils/errorParse';
1616
interface UseWebWalletTxSendProps {
1717
setPending: Dispatch<SetStateAction<boolean>>;
1818
setTransaction: Dispatch<SetStateAction<Transaction | null>>;
19+
setTxResult: Dispatch<SetStateAction<ITransactionOnNetwork | null>>;
1920
setError: Dispatch<SetStateAction<string>>;
2021
cb?: (params: TransactionCb) => void;
2122
}
2223

2324
export const useWebWalletTxSend = ({
2425
setPending,
2526
setTransaction,
27+
setTxResult,
2628
cb,
2729
setError,
2830
}: UseWebWalletTxSendProps) => {
@@ -56,6 +58,7 @@ export const useWebWalletTxSend = ({
5658
await postSendTxOperations(
5759
transaction,
5860
setTransaction,
61+
setTxResult,
5962
apiNetworkProvider,
6063
cb
6164
);

0 commit comments

Comments
 (0)