-
Notifications
You must be signed in to change notification settings - Fork 82
Upgrade to 📦 sdk-dapp v.5 #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0e2331a
Sdk-dapp-core migration (#264)
razvantomegea 38430fa
Update imports (#341)
mgavrila cca5c98
Add unlock and logout route (#340)
mgavrila 15e16ee
Update Home.tsx
arhtudormorar d69d513
Merge pull request #344 from multiversx/arhtudormorar-patch-1
arhtudormorar 07cd8bf
Update routes.ts
arhtudormorar 9b5c3e3
Merge branch 'main' into development
arhtudormorar 43456e0
Remove token from requests (#346)
mgavrila 1603a7f
Update routeNames.enums.ts
arhtudormorar b23453e
Minor renamings (#347)
arhtudormorar a98cadf
Merge branch 'main' into development
arhtudormorar 0eb7bc6
Migration guide update (#349)
arhtudormorar 66fa5ac
Update packages
arhtudormorar d18ac84
Fixed types (#350)
arhtudormorar 4947eb7
Fix inMemoryProvider signature (#351)
mgavrila 01cec26
Test callbacks
arhtudormorar b25fa98
Simplify initApp
arhtudormorar 8034f43
Upgrade sdk-dapp
arhtudormorar 83f9233
Remove unused
arhtudormorar 6d4161c
Remove unused
arhtudormorar a145e7e
Merge pull request #353 from multiversx/tm/feature/session-callbacks
arhtudormorar 423e782
Upgraded packages. (#354)
iuliacimpeanu 51dada6
Upgrade migration guide
arhtudormorar d116ee3
Merge pull request #355 from multiversx/tm/feature/update-migration-g…
arhtudormorar 6a5117a
Remove unused
arhtudormorar fa28a5f
Upgrade packages
arhtudormorar 1ea30e9
Updates on components (#356)
iuliacimpeanu 0ea442d
Update yarn lock
arhtudormorar 7ce16e2
Merge branch 'main' into development
arhtudormorar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # @multiversx/template-dapp | ||
|
|
||
| Migrating your application to the new SDK will probably require more code removal than insertion. Of course, each application is different, so this guide will have a generic character, pointing to you the main areas where you might need to change your code. | ||
| The main areas that might need code restructuring are: | ||
|
|
||
| - package.json library dependencies | ||
| - index.tsx file where the app bootstraps | ||
| - App.tsx, the main file of your application | ||
| - logging in and out | ||
| - sending and signing transactions | ||
| - component imports related to displaying data | ||
| - types | ||
|
|
||
| A typical migration can be seen in this [pull request](https://github.com/multiversx/mx-template-dapp/pull/264). | ||
|
|
||
| Next, we will make a brief overview of the main changes required. | ||
|
|
||
| ## 1. Changes in [`package.json`](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519) | ||
|
|
||
| #### Dependencies | ||
|
|
||
| - Removed: | ||
| - `@multiversx/sdk-dapp` | ||
| - Added: | ||
| - `@multiversx/sdk-dapp-core` (version `0.0.0-alpha.12`) | ||
| - `@multiversx/sdk-dapp-core-ui` (version `0.0.0-alpha.2`) | ||
| - `@multiversx/sdk-dapp-utils` (version `1.0.5`) | ||
|
|
||
| ## 2. Changes in [`index.tsx`](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-0b5adbfe7b36e4ae2f479291e20152e33e940f7f265162d77f40f6bdb5da7405) | ||
|
|
||
| You will need to wrap your application in a call to `initApp`: | ||
|
|
||
| ```tsx | ||
| initApp(config).then(() => { | ||
| ReactDOM.createRoot(document.getElementById('root')!).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode> | ||
| ); | ||
| }); | ||
| ``` | ||
|
|
||
| ## 2. Summary of Changes in [`App.tsx`](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-26ad4b834941d9b19ebf9db8082bd202aaf72ea0ddea85f5a8a0cb3c729cc6f2) | ||
|
|
||
| - AxiosInterceptorContext is now created as a local component | ||
| - DappProvider was removed and initialization is now made in initApp | ||
| - NotificationModal, SignTransactionsModals and TransactionsToastList are removed and functionality is handled under the hood | ||
|
|
||
| ## 3. Logging in and out: | ||
|
|
||
| Login buttons have been removed and there is a universal Unlock side panel, which can be inserted in the DOM at a desired location. | ||
|
|
||
| Example of how to use the Unlock side panel: | ||
|
|
||
| ```tsx | ||
| import { Button } from 'components'; | ||
| import { useState } from 'react'; | ||
| import { ProviderFactory } from 'lib'; | ||
| export { UnlockPanel, UnlockButton } from '@multiversx/sdk-dapp-core-ui/react'; | ||
| import { ExtendedProviders } from 'initConfig'; | ||
| import { IProviderFactory } from '@multiversx/sdk-dapp-core/out/providers/types/providerFactory.types'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { RouteNamesEnum } from 'localConstants'; | ||
|
|
||
| export const ConnectButton = () => { | ||
| const [open, setOpen] = useState(false); | ||
| const navigate = useNavigate(); | ||
|
|
||
| const handleLogin = async ({ type, anchor }: IProviderFactory) => { | ||
| const provider = await ProviderFactory.create({ | ||
| type, | ||
| anchor | ||
| }); | ||
| await provider?.login(); | ||
| navigate(RouteNamesEnum.dashboard); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <Button onClick={() => setOpen(true)}>Connect</Button> | ||
| <UnlockPanel | ||
| open={open} | ||
| onLogin={(options) => | ||
| handleLogin({ | ||
| type: options.detail.provider, | ||
| anchor: options.detail.anchor | ||
| }) | ||
| } | ||
| onClose={() => { | ||
| setOpen(false); | ||
| }} | ||
| > | ||
| <UnlockButton | ||
| label='In Memory Provider' | ||
| onClick={() => | ||
| handleLogin({ | ||
| type: ExtendedProviders.inMemoryProvider | ||
| }) | ||
| } | ||
| /> | ||
| </UnlockButton> | ||
| </> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| ## 4. [Sending transactions](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-1eadd6ccf43da9c2a8c30f5dfddbb56f3daeec28f04e43b41c134811bec478fb) | ||
|
|
||
| - `sendTransactions` has been replaced by `provider.signTransactions`, `txManager.send` and `txManager.track` | ||
| - `newTransaction` function has been removed and you need to create `Transaction` objects directly | ||
|
|
||
| ## 5. [UI components get imported from sdk-dapp-core-ui](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-e07cb98fcda2927e31f2a0f6cc5db5cb9a364c8da43d8df70597321bb1558336) | ||
|
|
||
| - see `src/lib/sdkDapp/components/CopyButton/CopyButton.tsx` | ||
|
|
||
| ### URL login is no longer supported | ||
|
|
||
| - see TODO how to login with PostMessage | ||
|
|
||
| ## 6. [Types](https://github.com/multiversx/mx-template-dapp/pull/264/files#diff-bd634780b000031ebfffb83de483b66a93ed12fde321950128e31a794ce96057) | ||
|
|
||
| - `LoginMethodsEnum` is replaced by `ProviderTypeEnum` | ||
| - `RawTransactionType` was removed | ||
| - some new types were added, related to UI elements, like `FormatAmountControllerPropsType` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| module.exports = { | ||
| plugins: { | ||
| tailwindcss: {}, | ||
| // '@tailwindcss/postcss': {} // NOTE: This is the new way to include Tailwind CSS V4.0.0+ | ||
| autoprefixer: {} | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,28 @@ | ||
| import { Route, BrowserRouter as Router, Routes } from 'react-router-dom'; | ||
| import { Layout } from 'components'; | ||
| import { | ||
| apiTimeout, | ||
| environment, | ||
| sampleAuthenticatedDomains, | ||
| walletConnectV2ProjectId | ||
| } from 'config'; | ||
| import { | ||
| AxiosInterceptorContext, // using this is optional | ||
| DappProvider, | ||
| NotificationModal, | ||
| SignTransactionsModals, | ||
| TransactionsToastList | ||
| // uncomment this to use the custom transaction tracker | ||
| // TransactionsTracker | ||
| } from 'lib'; | ||
| import { RouteNamesEnum } from 'localConstants'; | ||
| import { PageNotFound } from 'pages'; | ||
| import { PageNotFound } from 'pages/PageNotFound/PageNotFound'; | ||
| import { routes } from 'routes'; | ||
| import { BatchTransactionsContextProvider } from 'wrappers'; | ||
|
|
||
| const AppContent = () => { | ||
| return ( | ||
| <DappProvider | ||
| environment={environment} | ||
| customNetworkConfig={{ | ||
| name: 'customConfig', | ||
| apiTimeout, | ||
| walletConnectV2ProjectId | ||
| }} | ||
| dappConfig={{ | ||
| shouldUseWebViewProvider: true, | ||
| logoutRoute: RouteNamesEnum.unlock | ||
| }} | ||
| customComponents={{ | ||
| transactionTracker: { | ||
| // uncomment this to use the custom transaction tracker | ||
| // component: TransactionsTracker, | ||
| props: { | ||
| onSuccess: (sessionId: string) => { | ||
| console.log(`Session ${sessionId} successfully completed`); | ||
| }, | ||
| onFail: (sessionId: string, errorMessage: string) => { | ||
| console.log(`Session ${sessionId} failed. ${errorMessage ?? ''}`); | ||
| } | ||
| } | ||
| } | ||
| }} | ||
| > | ||
| <AxiosInterceptorContext.Listener> | ||
| <Layout> | ||
| <TransactionsToastList /> | ||
| <NotificationModal /> | ||
| <SignTransactionsModals /> | ||
| <Routes> | ||
| {routes.map((route) => ( | ||
| <Route | ||
| path={route.path} | ||
| key={`route-key-'${route.path}`} | ||
| element={<route.component />} | ||
| /> | ||
| ))} | ||
| <Route path='*' element={<PageNotFound />} /> | ||
| </Routes> | ||
| </Layout> | ||
| </AxiosInterceptorContext.Listener> | ||
| </DappProvider> | ||
| ); | ||
| }; | ||
| import { AxiosInterceptors, BatchTransactionsContextProvider } from 'wrappers'; | ||
| import { Layout } from './components'; | ||
|
|
||
| export const App = () => { | ||
| return ( | ||
| <AxiosInterceptorContext.Provider> | ||
| <AxiosInterceptorContext.Interceptor | ||
| authenticatedDomains={sampleAuthenticatedDomains} | ||
| > | ||
| <Router> | ||
| <BatchTransactionsContextProvider> | ||
| <AppContent /> | ||
| </BatchTransactionsContextProvider> | ||
| </Router> | ||
| </AxiosInterceptorContext.Interceptor> | ||
| </AxiosInterceptorContext.Provider> | ||
| <Router> | ||
| <AxiosInterceptors> | ||
| <BatchTransactionsContextProvider> | ||
| <Layout> | ||
| <Routes> | ||
| {routes.map((route) => ( | ||
| <Route | ||
| key={`route-key-'${route.path}`} | ||
| path={route.path} | ||
| element={<route.component />} | ||
| /> | ||
| ))} | ||
| <Route path='*' element={<PageNotFound />} /> | ||
| </Routes> | ||
| </Layout> | ||
| </BatchTransactionsContextProvider> | ||
| </AxiosInterceptors> | ||
| </Router> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.