-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillermo Alejandro Gallardo Diez
authored and
Guillermo Alejandro Gallardo Diez
committed
Jan 29, 2025
1 parent
4ce1feb
commit 7fd782f
Showing
3 changed files
with
22 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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,59 +1,31 @@ | ||
import '@/styles/globals.css'; | ||
import '@near-wallet-selector/modal-ui/styles.css'; | ||
|
||
import { createContext, useEffect, useState } from 'react'; | ||
import { useEffect } from 'react'; | ||
|
||
import '@/styles/globals.css'; | ||
import { Navigation } from '@/components/navigation'; | ||
import { setupWalletSelector } from '@near-wallet-selector/core'; | ||
import { setupModal } from '@near-wallet-selector/modal-ui'; | ||
|
||
import '@near-wallet-selector/modal-ui/styles.css'; | ||
import { useWalletSelector } from '@near-wallet-selector/react-hook' | ||
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet'; | ||
import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet'; | ||
|
||
import { HelloNearContract, NetworkId } from '@/config'; | ||
|
||
/** | ||
* @typedef NearContext | ||
* @property {import('@near-wallet-selector/core').WalletSelector} selector The wallet selector | ||
* @property {string} signedAccountId The AccountId of the signed user | ||
* @property {import('@near-wallet-selector/modal-ui').Modal} modal The modal to show | ||
*/ | ||
|
||
/** @type {import ('react').Context<NearContext>} */ | ||
export const NearContext = createContext({ | ||
walletSelector: undefined, | ||
signedAccountId: '', | ||
modal: undefined, | ||
}); | ||
|
||
// Optional: Create an access key so the user does not need to sign transactions. Read more about access keys here: https://docs.near.org/concepts/protocol/access-keys | ||
//const wallet = new Wallet({ networkId: NetworkId, createAccessKeyFor: HelloNearContract }); | ||
|
||
export default function MyApp({ Component, pageProps }) { | ||
const [signedAccountId, setSignedAccountId] = useState(''); | ||
const [walletSelector, setSelector] = useState(null); | ||
const [modal, setModal] = useState(null); | ||
|
||
const { setupWalletSelector } = useWalletSelector(); | ||
|
||
useEffect(() => { | ||
setupWalletSelector({ | ||
network: NetworkId, | ||
createAccessKeyFor: HelloNearContract, | ||
modules: [ | ||
setupMyNearWallet(), | ||
setupMeteorWallet(), | ||
], | ||
}).then( | ||
walletSelector => { | ||
const modal = setupModal(walletSelector, { contractId: '' }); | ||
walletSelector.subscribeOnAccountChange((accountId) => setSignedAccountId(accountId)); | ||
setSelector(walletSelector); | ||
setModal(modal); | ||
} | ||
) | ||
}) | ||
}, []); | ||
|
||
return ( | ||
<NearContext.Provider value={{ walletSelector, modal, signedAccountId }}> | ||
return (<> | ||
<Navigation /> | ||
<Component {...pageProps} /> | ||
</NearContext.Provider> | ||
</> | ||
); | ||
} |
This file contains 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