Skip to content

Commit

Permalink
Adding a send txn in example rust app.
Browse files Browse the repository at this point in the history
  • Loading branch information
janedegtiareva committed Feb 25, 2020
1 parent 5a5b99a commit 8dcf56d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions blank_rust_project/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
font-size: 1rem;
color: #25282A;
text-align: center;
padding:2%;
padding:2%;
}
.image-wrapper {
display: flex;
Expand Down Expand Up @@ -51,7 +51,7 @@
cursor: pointer;
color: white;
background: #0072CE;
}
}

.speech {
font-size: 1.5rem;
Expand All @@ -74,7 +74,8 @@
</div>
<div id="signed-in-flow" class="d-none">
<button id="sign-out-button" >Sign-out</button>
</div>
<button id="change-greeting">Change greeting</button>
</div>
</div>
<script src="./main.js"></script>
</body>
Expand Down
18 changes: 16 additions & 2 deletions blank_rust_project/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function InitContract() {
// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ['welcome'],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: [],
changeMethods: ['set_greeting'],
// Sender is the account ID to initialize transactions.
sender: window.accountId,
});
Expand Down Expand Up @@ -62,14 +62,28 @@ function signedInFlow() {
// Displaying the signed in flow container.
document.getElementById('signed-in-flow').classList.remove('d-none');

window.contract.welcome({account_id:window.accountId}).then(response => document.getElementById('speech').innerText = response.text);
getGreeting();

// Adding an event to a sign-out button.
document.getElementById('sign-out-button').addEventListener('click', () => {
walletAccount.signOut();
// Forcing redirect.
window.location.replace(window.location.origin + window.location.pathname);
});

// Adding an event to a sign-out button.
document.getElementById('change-greeting').addEventListener('click', () => {
setGreeting();
});
}

async function setGreeting() {
await window.contract.set_greeting({message:'Howdy'});
getGreeting();
}

function getGreeting() {
window.contract.welcome({account_id:window.accountId}).then(response => document.getElementById('speech').innerText = response.text);
}

// Loads nearlib and this contract into window scope.
Expand Down

0 comments on commit 8dcf56d

Please sign in to comment.