Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Automated eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Sep 24, 2019
1 parent 528eef1 commit f7c9586
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 215 deletions.
8 changes: 4 additions & 4 deletions blank_project/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const gulp = require("gulp");
const nearUtils = require("near-shell/gulp-utils");
const gulp = require('gulp');
const nearUtils = require('near-shell/gulp-utils');

function build_wasm(done){
nearUtils.compile("./assembly/main.ts", "./out/main.wasm", done);
};
nearUtils.compile('./assembly/main.ts', './out/main.wasm', done);
}

const build = gulp.series(build_wasm);

Expand Down
106 changes: 53 additions & 53 deletions blank_project/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,59 @@
function getConfig(env) {
switch (env) {

case 'production':
case 'development':
return {
networkId: 'default',
nodeUrl: 'https://rpc.nearprotocol.com',
contractName: CONTRACT_NAME,
walletUrl: 'https://wallet.nearprotocol.com',
initialBalance: 100000000,
};
case 'staging':
return {
networkId: 'staging',
nodeUrl: 'https://staging-rpc.nearprotocol.com/',
contractName: CONTRACT_NAME,
walletUrl: 'https://near-wallet-staging.onrender.com',
initialBalance: 100000000,
};
case 'local':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
keyPath: `${process.env.HOME}/.near/validator_key.json`,
walletUrl: 'http://localhost:4000/wallet',
contractName: CONTRACT_NAME,
initialBalance: 100000000,
};
case 'test':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
case 'test-remote':
case 'ci':
return {
networkId: 'shared-test',
nodeUrl: 'http://shared-test.nearprotocol.com:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
case 'ci-staging':
return {
networkId: 'shared-test-staging',
nodeUrl: 'http://staging-shared-test.nearprotocol.com:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
default:
throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`);
case 'production':
case 'development':
return {
networkId: 'default',
nodeUrl: 'https://rpc.nearprotocol.com',
contractName: CONTRACT_NAME,
walletUrl: 'https://wallet.nearprotocol.com',
initialBalance: 100000000,
};
case 'staging':
return {
networkId: 'staging',
nodeUrl: 'https://staging-rpc.nearprotocol.com/',
contractName: CONTRACT_NAME,
walletUrl: 'https://near-wallet-staging.onrender.com',
initialBalance: 100000000,
};
case 'local':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
keyPath: `${process.env.HOME}/.near/validator_key.json`,
walletUrl: 'http://localhost:4000/wallet',
contractName: CONTRACT_NAME,
initialBalance: 100000000,
};
case 'test':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
case 'test-remote':
case 'ci':
return {
networkId: 'shared-test',
nodeUrl: 'http://shared-test.nearprotocol.com:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
case 'ci-staging':
return {
networkId: 'shared-test-staging',
nodeUrl: 'http://staging-shared-test.nearprotocol.com:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000000,
};
default:
throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`);
}
}

Expand Down
120 changes: 60 additions & 60 deletions blank_project/src/main.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
// Initializing contract
async function initContract() {
console.log("nearConfig", nearConfig);
console.log('nearConfig', nearConfig);

// Initializing connection to the NEAR DevNet.
window.near = await nearlib.connect(Object.assign({ deps: { keyStore: new nearlib.keyStores.BrowserLocalStorageKeyStore() } }, nearConfig));
// Initializing connection to the NEAR DevNet.
window.near = await nearlib.connect(Object.assign({ deps: { keyStore: new nearlib.keyStores.BrowserLocalStorageKeyStore() } }, nearConfig));

// Initializing Wallet based Account. It can work with NEAR DevNet wallet that
// is hosted at https://wallet.nearprotocol.com
window.walletAccount = new nearlib.WalletAccount(window.near);
// Initializing Wallet based Account. It can work with NEAR DevNet wallet that
// 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.
window.accountId = window.walletAccount.getAccountId();
// Getting the Account ID. If unauthorized yet, 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, {
// 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
// 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.
changeMethods: ["sayHi"],
// Sender is the account ID to initialize transactions.
sender: window.accountId,
});
viewMethods: ['whoSaidHi'],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: ['sayHi'],
// Sender is the account ID to initialize transactions.
sender: window.accountId,
});
}

// Using initialized contract
async function doWork() {
// Setting up refresh button
document.getElementById('refresh-button').addEventListener('click', updateWhoSaidHi);
// Setting up refresh button
document.getElementById('refresh-button').addEventListener('click', updateWhoSaidHi);

// Based on whether you've authorized, checking which flow we should go.
if (!window.walletAccount.isSignedIn()) {
signedOutFlow();
} else {
signedInFlow();
}
// Based on whether you've authorized, checking which flow we should go.
if (!window.walletAccount.isSignedIn()) {
signedOutFlow();
} else {
signedInFlow();
}
}

// Function that initializes the signIn button using WalletAccount
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.
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.
window.nearConfig.contractName,
// This is the app name. It can be anything.
'Who was the last person to say "Hi!"?',
// We can also provide URLs to redirect on success and failure.
// The current URL is used by default.
);
});
// Displaying the signed out flow container.
document.getElementById('signed-out-flow').classList.remove('d-none');
// Adding an event to a sing-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.
window.nearConfig.contractName,
// This is the app name. It can be anything.
'Who was the last person to say "Hi!"?',
// We can also provide URLs to redirect on success and failure.
// The current URL is used by default.
);
});
}

// Main function for the signed-in flow (already authorized by the wallet).
function signedInFlow() {
// Displaying the signed in flow container.
document.getElementById('signed-in-flow').classList.remove('d-none');
// Displaying the signed in flow container.
document.getElementById('signed-in-flow').classList.remove('d-none');

// Displaying current account name.
document.getElementById('account-id').innerText = window.accountId;
// Displaying current account name.
document.getElementById('account-id').innerText = window.accountId;

// Adding an event to a say-hi button.
document.getElementById('say-hi').addEventListener('click', () => {
// Adding an event to a say-hi button.
document.getElementById('say-hi').addEventListener('click', () => {
// We call say Hi and then update who said Hi last.
window.contract.sayHi().then(updateWhoSaidHi);
});
window.contract.sayHi().then(updateWhoSaidHi);
});

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

// Function to update who said hi
function updateWhoSaidHi() {
// JavaScript tip:
// This is another example of how to use promises. Since this function is not async,
// we can't await for `contract.whoSaidHi()`, instead we attaching a callback function
// usin `.then()`.
contract.whoSaidHi().then((who) => {
// JavaScript tip:
// This is another example of how to use promises. Since this function is not async,
// we can't await for `contract.whoSaidHi()`, instead we attaching a callback function
// usin `.then()`.
contract.whoSaidHi().then((who) => {
// If the result doesn't have a value we fallback to the text
document.getElementById('who').innerText = who || "Nobody (but you can be the first)";
});
document.getElementById('who').innerText = who || 'Nobody (but you can be the first)';
});
}

// Loads nearlib and this contract into window scope.
window.nearInitPromise = initContract()
.then(doWork)
.catch(console.error);
.then(doWork)
.catch(console.error);
46 changes: 23 additions & 23 deletions blank_project/src/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// >> tests-snippet
describe("Greeter", function() {
describe('Greeter', function() {
let near;
let contract;
let accountId;
Expand All @@ -8,34 +8,34 @@ describe("Greeter", function() {

// Common setup below
beforeAll(async function() {
if (window.testSettings === undefined) {
window.testSettings = {};
}
near = await nearlib.connect(testSettings);
accountId = testSettings.accountId;
const contractName = testSettings.contractName ?
testSettings.contractName :
(new URL(window.location.href)).searchParams.get("contractName");
contract = await near.loadContract(contractName, {
if (window.testSettings === undefined) {
window.testSettings = {};
}
near = await nearlib.connect(testSettings);
accountId = testSettings.accountId;
const contractName = testSettings.contractName ?
testSettings.contractName :
(new URL(window.location.href)).searchParams.get('contractName');
contract = await near.loadContract(contractName, {
// NOTE: This configuration only needed while NEAR is still in development
// 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.
changeMethods: [],
sender: accountId
});
viewMethods: ['whoSaidHi'],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: [],
sender: accountId
});
});

// Multiple tests can be described below. Search Jasmine JS for documentation.
describe("simple", function() {
beforeAll(async function() {
describe('simple', function() {
beforeAll(async function() {
// There can be some common setup for each test.
});
});

it("get hello message", async function() {
const result = await contract.whoSaidHi();
expect(result).toBeNull();
});
});
it('get hello message', async function() {
const result = await contract.whoSaidHi();
expect(result).toBeNull();
});
});
});
// << tests-snippet
2 changes: 1 addition & 1 deletion get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ module.exports = function getConfig() {
}
throw e;
}
}
};
Loading

0 comments on commit f7c9586

Please sign in to comment.