Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forked to chatter.cheddar.near #45

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Community Voice
This project uses [bos-loader](https://github.com/near/bos-loader) v0.10.0 to keep track of the widgets required to implement Community Voice on BOS.

This project uses [bos-loader](https://github.com/near/bos-loader) v0.10.0 to keep track of the widgets required to implement Community Voice on BOS.

# How to use
To use it, download bos-loader as [instructed](https://github.com/near/bos-loader/releases/tag/v0.10.0) and run `npm start`. Then, open https://near.org/flags and paste the following: `http://127.0.0.1:3030` and save flags. Then go to the desired widget, assuming user communityvoice.ndctools.near. As an example, https://near.org/communityvoice.ndctools.near/widget/HelloCV should work, printing `Hello Community Voice`

To use it, download bos-loader as [instructed](https://github.com/near/bos-loader/releases/tag/v0.10.0) and run `npm start`. Then, open https://near.org/flags and paste the following: `http://127.0.0.1:3030` and save flags. Then go to the desired widget, assuming user chatter.cheddar.near. As an example, https://near.org/chatter.cheddar.near/widget/HelloCV should work, printing `Hello Community Voice`
6 changes: 5 additions & 1 deletion context.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{"wrapperSrc":"near/widget/DIG.Theme","wrapperProps":{},"networkId":"mainnet"}
{
"wrapperSrc": "near/widget/DIG.Theme",
"wrapperProps": {},
"networkId": "mainnet"
}
119 changes: 63 additions & 56 deletions deploy.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
const path = require("path");
const { readdirSync, readFileSync, writeFileSync } = require("fs");
const { keyStores, connect, Contract } = require("near-api-js");
const { homedir } = require("os");
const path = require('path')
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const { keyStores, connect, Contract } = require('near-api-js')
const { homedir } = require('os')

const ACCOUNT = "communityvoice.ndctools.near"
const ACCOUNT = 'chatter.cheddar.near'
// const ACCOUNT = "silkking.near"

function getAllFilesNames(addedPath = "") {
const pathToSearch = path.join("./src", addedPath)
const foldersToExclude = ["bosTests", "testingWidgets", "tests"]
const filesToExclude = ["HelloCV.jsx"]
function getAllFilesNames(addedPath = '') {
const pathToSearch = path.join('./src', addedPath)
const foldersToExclude = ['bosTests', 'testingWidgets', 'tests']
const filesToExclude = ['HelloCV.jsx']

const files = []

readdirSync(pathToSearch).forEach(file => {
if(filesToExclude.includes(file) || foldersToExclude.includes(file)) return
readdirSync(pathToSearch).forEach((file) => {
if (filesToExclude.includes(file) || foldersToExclude.includes(file))
return

const isFile = file.endsWith(".jsx")
if(isFile) {
const isFile = file.endsWith('.jsx')
if (isFile) {
files.push(path.join(addedPath, file))
} else {
files.push(...getAllFilesNames(path.join(addedPath, file)))
Expand All @@ -27,87 +28,93 @@ function getAllFilesNames(addedPath = "") {
}

async function getContract() {
const CREDENTIALS_DIR = ".near-credentials";
const credentialsPath = path.join(homedir(), CREDENTIALS_DIR);
console.log("credentialsPath", credentialsPath )
const myKeyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);
const CREDENTIALS_DIR = '.near-credentials'
const credentialsPath = path.join(homedir(), CREDENTIALS_DIR)
console.log('credentialsPath', credentialsPath)
const myKeyStore = new keyStores.UnencryptedFileSystemKeyStore(
credentialsPath
)

const connectionConfig = {
networkId: "mainnet",
networkId: 'mainnet',
keyStore: myKeyStore, // first create a key store
nodeUrl: "https://rpc.mainnet.near.org",
walletUrl: "https://wallet.mainnet.near.org",
helperUrl: "https://helper.mainnet.near.org",
explorerUrl: "https://nearblocks.io",
};
const nearConnection = await connect(connectionConfig);
nodeUrl: 'https://rpc.mainnet.near.org',
walletUrl: 'https://wallet.mainnet.near.org',
helperUrl: 'https://helper.mainnet.near.org',
explorerUrl: 'https://nearblocks.io',
}
const nearConnection = await connect(connectionConfig)
// const walletConnection = new WalletConnection(nearConnection);
const account = await nearConnection.account(ACCOUNT);
const account = await nearConnection.account(ACCOUNT)

const contract = new Contract(
account , // the account object that is connecting
"social.near",
account, // the account object that is connecting
'social.near',
{
// name of contract you're connecting to
viewMethods: [], // view methods do not change state but usually return a value
changeMethods: ["set"], // change methods modify state
changeMethods: ['set'], // change methods modify state
}
);
)

return contract
}

function getWidgetsJsons(files) {
return files.map(file => {
const fileContent = readFileSync(path.join("./src", file), "utf-8").toString()

const widgetName = file.replace(".jsx", "").split("/").join(".")
return files.map((file) => {
const fileContent = readFileSync(
path.join('./src', file),
'utf-8'
).toString()

const widgetName = file.replace('.jsx', '').split('/').join('.')
return {
[ACCOUNT]: {
widget: {
[widgetName]: {
"": fileContent
}
}
}
'': fileContent,
},
},
},
}
})
}

function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
};
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

async function run() {
const indexesToDeploy = []
const indexesWithError = []
const files = getAllFilesNames()

const widgetJsons = getWidgetsJsons(files)

const socialContract = await getContract()
for(let i = 29; i < widgetJsons.length; i++) {
if(indexesToDeploy.length > 0 && !indexesToDeploy.includes(i)) continue
for (let i = 0; i < widgetJsons.length; i++) {
if (indexesToDeploy.length > 0 && !indexesToDeploy.includes(i)) continue
const json = widgetJsons[i]
const widgetName = Object.keys(json[ACCOUNT].widget)[0]
console.log("Deploying widget with index", i, widgetName)
console.log('Deploying widget with index', i, widgetName)
try {
await socialContract.set({
data: json
},
"300000000000000",
"1" + "0".repeat(21))
console.log("Deployed", widgetName)
} catch(err) {
console.log("Error deploying widget with index", i)
await socialContract.set(
{
data: json,
},
'300000000000000',
'1' + '0'.repeat(21)
)
console.log('Deployed', widgetName)
} catch (err) {
console.log('Error deploying widget with index', i)
console.log(err)
indexesWithError.push(i)
} finally {
await sleep(1521)
}
}
console.log("Indexes with error", indexesWithError)

console.log('Indexes with error', indexesWithError)
}

run()
run()
2 changes: 1 addition & 1 deletion flags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"components":{}}
{ "components": {} }
Loading