Skip to content

Commit

Permalink
Use Aragon Connect in dao apps command (#1731)
Browse files Browse the repository at this point in the history
* Use Aragon Connect to fetch apps when possible

* Remove ConnectorDeclaration array
  • Loading branch information
macor161 authored Jun 23, 2020
1 parent 035932f commit 651d688
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 43 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"homepage": "https://github.com/aragon/aragon-cli#readme",
"dependencies": {
"@aragon/apm": "^3.1.4",
"@aragon/connect": "^0.2.0",
"@aragon/toolkit": "^0.0.5",
"@aragon/truffle-config-v5": "^1.0.0",
"ajv": "^6.6.2",
Expand Down
32 changes: 30 additions & 2 deletions packages/cli/src/commands/dao_cmds/apps.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TaskList from 'listr'
import Table from 'cli-table'
import { blue, green, white } from 'chalk'
import { connect } from '@aragon/connect'
import Web3 from 'web3'
import {
getDaoAddress,
Expand Down Expand Up @@ -40,7 +41,9 @@ const printContent = (content) => {
return '(No UI available)'
}

return `${content.provider}:${content.location}`
return typeof content === 'string'
? content
: `${content.provider}:${content.location}`
}

const printApps = (apps) => {
Expand Down Expand Up @@ -79,6 +82,27 @@ const printPermissionlessApps = (apps) => {
}
}

/**
* Returns true if the provided Ethereum network id supports
* Aragon Connect. Currently `true` for mainnet and Rinkeby
* @param {number} Ethereum network id
*/
const supportsAragonConnect = (networkId) => {
return networkId === 1 || networkId === 4
}

const getAppsFromAragonConnect = async (dao, networkId) => {
const org = await connect(dao, 'thegraph', { chainId: networkId })

return (await org.apps()).map((app) => ({
appId: app.appId,
appName: app.appName,
proxyAddress: app.address,
version: app.version,
content: app.contentUri,
}))
}

export const handler = async function ({
reporter,
dao,
Expand Down Expand Up @@ -106,8 +130,12 @@ export const handler = async function ({
ipfs,
provider: wsProvider || web3.currentProvider,
}
apps = await getInstalledApps(dao, options)

daoAddress = await getDaoAddress(dao, options)

apps = supportsAragonConnect(network.network_id)
? await getAppsFromAragonConnect(dao, network.network_id)
: await getInstalledApps(dao, options)
},
},
{
Expand Down
Loading

0 comments on commit 651d688

Please sign in to comment.