Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Improve comments in template 01
Browse files Browse the repository at this point in the history
This fixes some typos and grammar mistakes and improves clarity of some
comments in templates/01-hello-username
  • Loading branch information
chadoh committed Jan 30, 2020
1 parent de7267c commit ac0dc07
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions templates/01-hello-username/assembly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export function sayHi(): void {
// context.sender is the account_id of the user who sent this call to the contract
// It's provided by the Blockchain runtime. For now we just store it in a local variable.
let sender = context.sender;
// `near` class contains some helper functions, e.g. logging.

// `near-runtime-ts` contains some helper classes, e.g. `logging`
// Logs are not persistently stored on the blockchain, but produced by the blockchain runtime.
// It's helpful to use logs for debugging your functions or when you need to get some info
// from the change methods (since change methods don't return values to the front-end).
logging.log(sender + " says \"Hi!\"");

// storage is a helper class that allows contracts to modify the persistent state
// and read from it. setString allows you to persitently store a string value for a given string key.
// We'll store the last sender of this contract who called this method.
storage.setString(LAST_SENDER_KEY, sender);
}

Expand Down
2 changes: 0 additions & 2 deletions templates/01-hello-username/assembly/model.ts

This file was deleted.

2 changes: 1 addition & 1 deletion templates/01-hello-username/src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
const CONTRACT_NAME = 'near-hello-devnet'; /* TODO: fill this in! */
const CONTRACT_NAME = 'near-hello-devnet';
const DEFAULT_ENV = 'development';

function getConfig(env) {
Expand Down
10 changes: 6 additions & 4 deletions templates/01-hello-username/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ async function initContract() {
// is hosted at https://wallet.nearprotocol.com
window.walletAccount = new nearlib.WalletAccount(window.near);

// Getting the Account ID. If unauthorized yet, it's just empty string.
// Getting the Account ID. If currently unauthorized, it's just empty string.
window.accountId = window.walletAccount.getAccountId();

// Initializing our contract APIs by contract name and configuration.
window.contract = await near.loadContract(nearConfig.contractName, {
// NOTE: This configuration only needed while NEAR is still in development
// TODO: what configuration?

// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ['whoSaidHi'],
// Change methods can modify the state. But you don't receive the returned value when called.
Expand All @@ -41,7 +43,7 @@ async function doWork() {
function signedOutFlow() {
// Displaying the signed out flow container.
document.getElementById('signed-out-flow').classList.remove('d-none');
// Adding an event to a sing-in button.
// Adding an event to a sign-in button.
document.getElementById('sign-in-button').addEventListener('click', () => {
window.walletAccount.requestSignIn(
// The contract name that would be authorized to be called by the user's account.
Expand All @@ -68,7 +70,7 @@ function signedInFlow() {
window.contract.sayHi().then(updateWhoSaidHi);
});

// Adding an event to a sing-out button.
// Adding an event to a sign-out button.
document.getElementById('sign-out-button').addEventListener('click', () => {
walletAccount.signOut();
// Forcing redirect.
Expand All @@ -91,4 +93,4 @@ function updateWhoSaidHi() {
// Loads nearlib and this contract into window scope.
window.nearInitPromise = initContract()
.then(doWork)
.catch(console.error);
.catch(console.error);

0 comments on commit ac0dc07

Please sign in to comment.