forked from near/create-near-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated frontend with latest examples version
- Loading branch information
Showing
8 changed files
with
78 additions
and
65 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,21 +1,25 @@ | ||
// React | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
// NEAR | ||
import { HelloNEAR } from './near-interface'; | ||
import { Wallet } from './near-wallet'; | ||
import { Contract } from './near-interface'; | ||
|
||
const reactRoot = createRoot(document.querySelector('#root')); | ||
// When creating the wallet you can optionally ask to create an access key | ||
// Having the key enables to call non-payable methods without interrupting the user to sign | ||
const wallet = new Wallet({ createAccessKeyFor: process.env.CONTRACT_NAME }) | ||
|
||
// create the Wallet and the Contract | ||
const contractId = process.env.CONTRACT_NAME; | ||
const wallet = new Wallet({contractId: contractId}); | ||
const contract = new Contract({wallet: wallet}); | ||
// Abstract the logic of interacting with the contract to simplify your flow | ||
const helloNEAR = new HelloNEAR({ contractId: process.env.CONTRACT_NAME, walletToUse: wallet }); | ||
|
||
window.onload = wallet.startUp() | ||
.then((isSignedIn) => { | ||
reactRoot.render(<App isSignedIn={isSignedIn} contract={contract} wallet={wallet} />); | ||
}) | ||
.catch(e => { | ||
reactRoot.render(<div style={{color: 'red'}}>Error: <code>{e.message}</code></div>); | ||
console.error(e); | ||
}); | ||
// Setup on page load | ||
window.onload = async () => { | ||
const isSignedIn = await wallet.startUp() | ||
|
||
ReactDOM.render( | ||
<App isSignedIn={isSignedIn} helloNEAR={helloNEAR} wallet={wallet} />, | ||
document.getElementById('root') | ||
); | ||
} |
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,15 +1,16 @@ | ||
export class Contract{ | ||
wallet; | ||
/* Talking with a contract often involves transforming data, we recommend you to encapsulate that logic into a class */ | ||
|
||
constructor({wallet}){ | ||
this.wallet = wallet; | ||
export class HelloNEAR { | ||
constructor({ contractId, walletToUse }) { | ||
this.contractId = contractId; | ||
this.wallet = walletToUse; | ||
} | ||
|
||
async getGreeting(){ | ||
return await this.wallet.viewMethod({method: 'get_greeting'}); | ||
async getGreeting() { | ||
return await this.wallet.viewMethod({ contractId: this.contractId, method: 'get_greeting' }); | ||
} | ||
async setGreeting(greeting){ | ||
return await this.wallet.callMethod({method: 'set_greeting', args:{message: greeting}}); | ||
|
||
async setGreeting(greeting) { | ||
return await this.wallet.callMethod({ contractId: this.contractId, method: 'set_greeting', args: { message: greeting } }); | ||
} | ||
} |
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
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