Skip to content

Commit

Permalink
Snapshot Merge (#1253)
Browse files Browse the repository at this point in the history
* Add Test Community Migrations and Modify Chain Model (#1150)

* add yearn and fei as chains
* modify chain model
* add migration
* add icons

* add snapshot to chainInfo class (#1155)

* Add yearn and fei migrations and controllers (#1156)

I'm going to merge this in so your most recent PR can be merged in post-review. But the controllers will be removed when the ETH-Token Forum PR gets merged into master upstream. We can sync over this later.

* Add boilerplate for snapshot proposal page and controller (#1167)

* fetch all proposals using snapshot (#1169)

* fetch all proposals using snapshot

* add date time fixes

Co-authored-by: dillchen <dillon@commonwealth.im>

* Add View snapshot proposal (#1178)

* add view snapshot proposal

* add viewVote component

* Add Snapshot Creation (#1216)

* update snapshot proposal page

* create snpashot proposal workflow

* update UI

* utilize snapshot js

* add snapshot create proposal

* add sushi token for testing purpose

* correct wrong code

* complete creating snapshot proposal

* update manage community form

* Hector.vote snapshot proposal (#1226)

* update snapshot proposal page

* create snpashot proposal workflow

* update UI

* utilize snapshot js

* add snapshot create proposal

* add sushi token for testing purpose

* correct wrong code

* complete creating snapshot proposal

* Handle proposals missing Passed and Executed events

* Add debug trace when Substrate proposals fail to load

* Show missing PROP/MOTs

* Reduce data passed in bulkEntities

* Include chain entities on getThread

* Remove extra sanitize pass

* Ensure treasury proposals are always created

* Add missing data tag for tres proposals

* Adjust mobile header

* Enforce DISTINCT when query for collaborators and chain entities with ARRAY_AGG

* Minor copy

* Integrate github actions. (#1219)

* Migrate CI to github actions.

* Add NO_CLIENT env for test suite.

* Map postgres port to localhost.

* Offchain Community Creation (site-admin only) (#1204)

* create an offchain community(site admin only)

* Remove commented code

* Route to the newly created community

Co-authored-by: zakhap <zhs2104@columbia.edu>

* update manage community form

* Fixed README.md to properly display instructions (#1215)

* fixed README.md to properly display instructions

* fixed connect address instructions using substrate cmd line

* Remove token balance requirement for creating threads (#1220)

* remove token balance requirement

* allow commenting as well

* Fix createReaction and remove dead code.

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>
Co-authored-by: Jake Naviasky <jake@commonwealth.im>

* Skip token holder test cases.

* add confirm vote modal

* Fix hydradx spec and disable bounties page.

* add snapshot util functions for voting

* Fix completion hack in referendum.

* Invite Flow Fixes, Stage 1 (#1212)

* Add invite count pip

* Reinit app on private community invite acceptance

* Remove logs, remove svg work

* Conditionally close modal if no remaining invites

* Refactor Community Options Popover (#1214)

* Small Invite Flow Bug Fixes (#1213)

* small bugs for invite flow

* Get Invite Link Section updated

* button label update

* add strategies from snapshot.js to fix ts errors

* remove warnings

* Add underline to Quill Editor links

* Fix Comma/Semicolon Bug (#1224)

* Serve Substrate specs from DB. (#1223)

* Store substrate specs in db.

* Add spec_settings page.

* Remove plasm switch in substrate controller.

* Attempt CSS.

* style update

* Permit community admin to edit spec and QA.

Co-authored-by: James Truong <jamestruong.consult@gmail.com>

* complete voting

* utilize snapshotjs npm package

* fix linting test

* test linting

* fix lint error and update code

* Tips UI (#1221)

* Remove puppeteer.

* Add tip controllers.

* Add tentative view.

* Comment out tx success callbacks.

* tips ui integration first pass

* tips ui done

* changed tip value from sum to median

* changed tip value display style to match design

* Bump CW version and fix migrations.

* fix responsive design issue, show contribute only for council members and tip reason in listing page

* minor styling change

* Fix tip view page error.

Co-authored-by: Jake Naviasky <jake@commonwealth.im>
Co-authored-by: zakhap <zhs2104@columbia.edu>

* Added Google Tag Manager Script (#1233)

* Offchain Polls v2 (#1240)

* motions wip

* sidebar wip

* sidebar modules

* hierarchical sidebar

* move poll, style revs

* Add offchain voting options json blob to backend

* offchain vote options

* Add form, update JSON field names, revs on poll creation flow

* Bug fixes and styling

* More bugs and style fixes

* Hide motions for now

* Minor fixes: Update copy for offchain communities, update styling

* Minor fixes: topic selector dropdown arrow

* Fix allowNull requirement for threads

* Update user address styling

* Adjust discussion row tag styling

* Fix responsive new thread form, mobile header glitch

* Fix notifications menu overflow text

* Use formatter on notification rows

* Reset app.chain when chain initialization was aborted, to prevent infinite spinner race condition

* Manage community modal styling

* Tips "Reason" fix (#1242)

* tips reason fix: commonwealth links open in the same tab

* changes based on Zak's review

* update getVotes from snapshot.js

* Optimization: Load bulkOffchain in parallel with proposal comments and chain entities (#1243)

* Bump typescript dependency version.

* fix ajv issue

* Remove global and cleanup lint and add redraw.

* Lint fixes.

* Add another demo community

* Add new snapshot space id to fei

* Add voting buffer style

* Fix voter addresses to be User objects and the snapshot author to be User object with link

* Fix header spacing issues

* Unlink the Created and Updated at metadata, date calculation still wrong

* Add spinner while proposals load from snapshot api

* Make the proposal form look nicer, oddly thin?, removed the weird date-pickers.

* Remove evidence of DatePicker from form

* Add spinner for when callout is loading on new proposal form

* Add margin to the bottom of voting actions so they don't touch the bottom

* Add comment on VotingAction buttons where they're hardcoded to always be clickable.

* Comment out SnapshotProposalStagesBar because it has no logic to do anything and the proposal rows do not have attributes for filtering yet.

* Add fei.eth back to migration

* Fix ending/ended ago bug

* Add 'in' to timestamp interpretation

* resetServer.ts demos community, broken

* Add generic snapshot adapter and use it for all snapshot communities

* Add demo community to migration and ChainNetwork, probably wrong contract address on chainnode"

* Add demo to down migration and add TEST token contract to node

* Make hub.snapshot default, add demo community.

* Default apollo to hub.snapshot as well

* Add demo to address model

* The changes to run the demo, not generalized

* Make snapshot pages mobile friendly

* add snapshot filtering

* Clean up proposal listing UI

* UI tweaks for snapshot proposal pages

* Catch voting errors

* Switch off oninit lifecycle; move submit proposal button to new proposal button

Co-authored-by: Raymond Zhong <raykyri@gmail.com>
Co-authored-by: Jake Naviasky <jake@commonwealth.im>
Co-authored-by: rakeshup <parthiban.rakesh95@gmail.com>
Co-authored-by: zakhap <zhs2104@columbia.edu>
Co-authored-by: Timothee Legros <62490329+timolegros@users.noreply.github.com>
Co-authored-by: maxwellfoley3 <maxwellsfoley@gmail.com>
Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>
Co-authored-by: gdjohnson <graham@commonwealth.im>
Co-authored-by: true-eye <jamestruong.consult@gmail.com>
Co-authored-by: Raymond Zhong <raykyri@users.noreply.github.com>

* Clean up copy in review

* add option to autofill snapshot proposal from existing thread (#1250)

* add option to autofill snapshot proposal from existing thread

* remove code accidentally added in merge

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>

* Add Test Community Migrations and Modify Chain Model (#1150)

* add yearn and fei as chains
* modify chain model
* add migration
* add icons

* add snapshot to chainInfo class (#1155)

* Add yearn and fei migrations and controllers (#1156)

I'm going to merge this in so your most recent PR can be merged in post-review. But the controllers will be removed when the ETH-Token Forum PR gets merged into master upstream. We can sync over this later.

* Add boilerplate for snapshot proposal page and controller (#1167)

* fetch all proposals using snapshot (#1169)

* fetch all proposals using snapshot

* add date time fixes

Co-authored-by: dillchen <dillon@commonwealth.im>

* Add View snapshot proposal (#1178)

* add view snapshot proposal

* add viewVote component

* Add Snapshot Creation (#1216)

* update snapshot proposal page

* create snpashot proposal workflow

* update UI

* utilize snapshot js

* add snapshot create proposal

* add sushi token for testing purpose

* correct wrong code

* complete creating snapshot proposal

* update manage community form

* Hector.vote snapshot proposal (#1226)

* update snapshot proposal page

* create snpashot proposal workflow

* update UI

* utilize snapshot js

* add snapshot create proposal

* add sushi token for testing purpose

* correct wrong code

* complete creating snapshot proposal

* Handle proposals missing Passed and Executed events

* Add debug trace when Substrate proposals fail to load

* Show missing PROP/MOTs

* Reduce data passed in bulkEntities

* Include chain entities on getThread

* Remove extra sanitize pass

* Ensure treasury proposals are always created

* Add missing data tag for tres proposals

* Adjust mobile header

* Enforce DISTINCT when query for collaborators and chain entities with ARRAY_AGG

* Minor copy

* Integrate github actions. (#1219)

* Migrate CI to github actions.

* Add NO_CLIENT env for test suite.

* Map postgres port to localhost.

* Offchain Community Creation (site-admin only) (#1204)

* create an offchain community(site admin only)

* Remove commented code

* Route to the newly created community

Co-authored-by: zakhap <zhs2104@columbia.edu>

* update manage community form

* Fixed README.md to properly display instructions (#1215)

* fixed README.md to properly display instructions

* fixed connect address instructions using substrate cmd line

* Remove token balance requirement for creating threads (#1220)

* remove token balance requirement

* allow commenting as well

* Fix createReaction and remove dead code.

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>
Co-authored-by: Jake Naviasky <jake@commonwealth.im>

* Skip token holder test cases.

* add confirm vote modal

* Fix hydradx spec and disable bounties page.

* add snapshot util functions for voting

* Fix completion hack in referendum.

* Invite Flow Fixes, Stage 1 (#1212)

* Add invite count pip

* Reinit app on private community invite acceptance

* Remove logs, remove svg work

* Conditionally close modal if no remaining invites

* Refactor Community Options Popover (#1214)

* Small Invite Flow Bug Fixes (#1213)

* small bugs for invite flow

* Get Invite Link Section updated

* button label update

* add strategies from snapshot.js to fix ts errors

* remove warnings

* Add underline to Quill Editor links

* Fix Comma/Semicolon Bug (#1224)

* Serve Substrate specs from DB. (#1223)

* Store substrate specs in db.

* Add spec_settings page.

* Remove plasm switch in substrate controller.

* Attempt CSS.

* style update

* Permit community admin to edit spec and QA.

Co-authored-by: James Truong <jamestruong.consult@gmail.com>

* complete voting

* utilize snapshotjs npm package

* fix linting test

* test linting

* fix lint error and update code

* Tips UI (#1221)

* Remove puppeteer.

* Add tip controllers.

* Add tentative view.

* Comment out tx success callbacks.

* tips ui integration first pass

* tips ui done

* changed tip value from sum to median

* changed tip value display style to match design

* Bump CW version and fix migrations.

* fix responsive design issue, show contribute only for council members and tip reason in listing page

* minor styling change

* Fix tip view page error.

Co-authored-by: Jake Naviasky <jake@commonwealth.im>
Co-authored-by: zakhap <zhs2104@columbia.edu>

* Added Google Tag Manager Script (#1233)

* Offchain Polls v2 (#1240)

* motions wip

* sidebar wip

* sidebar modules

* hierarchical sidebar

* move poll, style revs

* Add offchain voting options json blob to backend

* offchain vote options

* Add form, update JSON field names, revs on poll creation flow

* Bug fixes and styling

* More bugs and style fixes

* Hide motions for now

* Minor fixes: Update copy for offchain communities, update styling

* Minor fixes: topic selector dropdown arrow

* Fix allowNull requirement for threads

* Update user address styling

* Adjust discussion row tag styling

* Fix responsive new thread form, mobile header glitch

* Fix notifications menu overflow text

* Use formatter on notification rows

* Reset app.chain when chain initialization was aborted, to prevent infinite spinner race condition

* Manage community modal styling

* Tips "Reason" fix (#1242)

* tips reason fix: commonwealth links open in the same tab

* changes based on Zak's review

* update getVotes from snapshot.js

* Optimization: Load bulkOffchain in parallel with proposal comments and chain entities (#1243)

* Bump typescript dependency version.

* fix ajv issue

* Remove global and cleanup lint and add redraw.

* Lint fixes.

* Add another demo community

* Add new snapshot space id to fei

* Add voting buffer style

* Fix voter addresses to be User objects and the snapshot author to be User object with link

* Fix header spacing issues

* Unlink the Created and Updated at metadata, date calculation still wrong

* Add spinner while proposals load from snapshot api

* Make the proposal form look nicer, oddly thin?, removed the weird date-pickers.

* Remove evidence of DatePicker from form

* Add spinner for when callout is loading on new proposal form

* Add margin to the bottom of voting actions so they don't touch the bottom

* Add comment on VotingAction buttons where they're hardcoded to always be clickable.

* Comment out SnapshotProposalStagesBar because it has no logic to do anything and the proposal rows do not have attributes for filtering yet.

* Add fei.eth back to migration

* Fix ending/ended ago bug

* Add 'in' to timestamp interpretation

* resetServer.ts demos community, broken

* Add generic snapshot adapter and use it for all snapshot communities

* Add demo community to migration and ChainNetwork, probably wrong contract address on chainnode"

* Add demo to down migration and add TEST token contract to node

* Make hub.snapshot default, add demo community.

* Default apollo to hub.snapshot as well

* Add demo to address model

* The changes to run the demo, not generalized

* Make snapshot pages mobile friendly

* add snapshot filtering

* Clean up proposal listing UI

* UI tweaks for snapshot proposal pages

* Catch voting errors

* Switch off oninit lifecycle; move submit proposal button to new proposal button

Co-authored-by: Raymond Zhong <raykyri@gmail.com>
Co-authored-by: Jake Naviasky <jake@commonwealth.im>
Co-authored-by: rakeshup <parthiban.rakesh95@gmail.com>
Co-authored-by: zakhap <zhs2104@columbia.edu>
Co-authored-by: Timothee Legros <62490329+timolegros@users.noreply.github.com>
Co-authored-by: maxwellfoley3 <maxwellsfoley@gmail.com>
Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>
Co-authored-by: gdjohnson <graham@commonwealth.im>
Co-authored-by: true-eye <jamestruong.consult@gmail.com>
Co-authored-by: Raymond Zhong <raykyri@users.noreply.github.com>

* Clean up copy in review

* add option to autofill snapshot proposal from existing thread (#1250)

* add option to autofill snapshot proposal from existing thread

* remove code accidentally added in merge

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>

* merge master

* Removing fei/sushi/yearn adapters, unnecessary with token/snapshot adapters

* Show admin snapshot (ETH only) and validate inputs (#1257)

* show snapshot field only on tokens, and check input

* delete unnecessary page

* do extra input checking on back end for snapshot info

* formatting

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>

* Add create proposal button back with cherry-pick from private repo

* Fix snapshot update check in updateChain route

* Change fei et al to type token

* Remove old adapter stuff, unnecessary for snapshot

* Fix issue #1 from Max's QA list

* Assorted bug fixes for snapshot (#1258)

* Assorted bug fixes for snapshot

- voting modal now properly loads
- 'Load more' on list of voters
- Ended and active proposals is now accurate
- Voting buttons only display on active proposals
- 'Last edited' changed to 'Ended'

* remove console log

* fix name change

Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>

* New Snapshot DatePicker

* Core Community pending

* use existing webwalletcontroller to sign the snapshot proposal message

* Fix imports and finish implementing webwallet over window.ethereum

* Remove sushi migration and add loading spinners.

* remove simplepicker and add radio buttons (#1271)

* Add simplepicker.

* prompt enable wallet if disabled

* format snapshot form properly for API

* assorted minor bug fixes

* Fix sidebar conditionals and remove unused migration.

* Proposal queries now via apollo.

* Controllers refactor.

* Small style changes.

* Reenable callout warning.

* get rid of spinner state on new proposal creation snapshot page

* fix voting

* minor display fixes

* Fix snapshot proposal page loading.

* Cleanup getPower init.

* Fix proposal creation redirect and add walletconnect.

Co-authored-by: fstar1129 <41280117+fstar1129@users.noreply.github.com>
Co-authored-by: fstar1129 <hector1990112950@hotmail.com>
Co-authored-by: zakhap <zhs2104@columbia.edu>
Co-authored-by: Raymond Zhong <raykyri@gmail.com>
Co-authored-by: Jake Naviasky <jake@commonwealth.im>
Co-authored-by: rakeshup <parthiban.rakesh95@gmail.com>
Co-authored-by: Timothee Legros <62490329+timolegros@users.noreply.github.com>
Co-authored-by: maxwellfoley3 <maxwellsfoley@gmail.com>
Co-authored-by: Maxwell Foley <maxwell.foley@certik.org>
Co-authored-by: gdjohnson <graham@commonwealth.im>
Co-authored-by: true-eye <jamestruong.consult@gmail.com>
Co-authored-by: Raymond Zhong <raykyri@users.noreply.github.com>
  • Loading branch information
13 people authored Aug 13, 2021
1 parent 5e81d79 commit cf600cc
Show file tree
Hide file tree
Showing 31 changed files with 1,648 additions and 48 deletions.
41 changes: 38 additions & 3 deletions client/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'construct.scss';
// import 'tailwindcss/tailwind.css';
import '../styles/style.css';
import '../styles/lib/style.css';
import 'simplepicker/dist/simplepicker.css';

import m from 'mithril';
import $ from 'jquery';
Expand All @@ -13,6 +14,7 @@ import moment from 'moment';
import mixpanel from 'mixpanel-browser';
import _ from 'underscore';

import { AaveTypes, MarlinTypes, MolochTypes } from '@commonwealth/chain-events';
import app, { ApiStatus, LoginState } from 'state';
import {
ChainInfo,
Expand All @@ -34,14 +36,14 @@ import { Layout } from 'views/layout';
import ConfirmInviteModal from 'views/modals/confirm_invite_modal';
import LoginModal from 'views/modals/login_modal';
import { alertModalWithText } from 'views/modals/alert_modal';
import { AaveTypes, MarlinTypes, MolochTypes } from '@commonwealth/chain-events';

// Prefetch commonly used pages
import(/* webpackPrefetch: true */ 'views/pages/landing');
import(/* webpackPrefetch: true */ 'views/pages/commonwealth');
import(/* webpackPrefetch: true */ 'views/pages/discussions');
import(/* webpackPrefetch: true */ 'views/pages/view_proposal');

// eslint-disable-next-line max-len
const APPLICATION_UPDATE_MESSAGE = 'A new version of the application has been released. Please save your work and refresh.';
const APPLICATION_UPDATE_ACTION = 'Okay';

Expand Down Expand Up @@ -508,6 +510,7 @@ Promise.all([
alertModalWithText(APPLICATION_UPDATE_MESSAGE, APPLICATION_UPDATE_ACTION)();
}
// return to the last page, if it was on commonwealth
// eslint-disable-next-line no-restricted-globals
if (hasCompletedSuccessfulPageLoad) history.back();
});
},
Expand Down Expand Up @@ -535,7 +538,6 @@ Promise.all([
}
}


// Special case to defer chain loading specifically for viewing an offchain thread. We need
// a special case because OffchainThreads and on-chain proposals are all viewed through the
// same "/:scope/proposal/:type/:id" route.
Expand Down Expand Up @@ -603,6 +605,17 @@ Promise.all([
'/spec_settings': importRoute('views/pages/spec_settings', { scoped: true, deferChain: true }),
'/settings': importRoute('views/pages/settings', { scoped: true }),
'/analytics': importRoute('views/pages/stats', { scoped: true, deferChain: true }),

'/snapshot-proposals/:snapshotId': importRoute(
'views/pages/snapshot_proposals', { scoped: true, deferChain: true }
),
'/snapshot-proposal/:snapshotId/:identifier': importRoute(
'views/pages/view_snapshot_proposal', { scoped: true }
),
'/new/snapshot-proposal/:snapshotId': importRoute(
'views/pages/new_snapshot_proposal', { scoped: true, deferChain: true }
),

// Redirects
'/:scope/notifications': redirectRoute(() => '/notifications'),
'/:scope/notificationsList': redirectRoute(() => '/notificationsList'),
Expand Down Expand Up @@ -636,6 +649,15 @@ Promise.all([
'/:scope/admin': redirectRoute(() => '/admin'),
'/:scope/spec_settings': redirectRoute(() => '/spec_settings'),
'/:scope/analytics': redirectRoute(() => '/analytics'),
'/:scope/snapshot-proposals/:snapshotId':redirectRoute(
(attrs) => `/snapshot-proposals/${attrs.snapshotId}`
),
'/:scope/snapshot-proposal/:snapshotId/:identifier': redirectRoute(
(attrs) => `/snapshot-proposal/${attrs.snapshotId}/${attrs.identifier}`
),
'/:scope/new/snapshot-proposal/:snapshotId':redirectRoute(
(attrs) => `/new/snapshot-proposal/${attrs.snapshotId}`
),
} : {
//
// Scoped routes
Expand Down Expand Up @@ -667,7 +689,9 @@ Promise.all([
'/:scope/new/thread': importRoute('views/pages/new_thread', { scoped: true, deferChain: true }),
// Profiles
'/:scope/account/:address': importRoute('views/pages/profile', { scoped: true, deferChain: true }),
'/:scope/account': redirectRoute((a) => activeAcct ? `/${a.scope}/account/${activeAcct.address}` : `/${a.scope}/`),
'/:scope/account': redirectRoute(
(a) => activeAcct ? `/${a.scope}/account/${activeAcct.address}` : `/${a.scope}/`
),
// Governance
'/:scope/referenda': importRoute('views/pages/referenda', { scoped: true }),
'/:scope/proposals': importRoute('views/pages/proposals', { scoped: true }),
Expand All @@ -691,10 +715,21 @@ Promise.all([
'/:scope/admin': importRoute('views/pages/admin', { scoped: true }),
'/:scope/spec_settings': importRoute('views/pages/spec_settings', { scoped: true, deferChain: true }),
'/:scope/analytics': importRoute('views/pages/stats', { scoped: true, deferChain: true }),

'/:scope/snapshot-proposals/:snapshotId': importRoute(
'views/pages/snapshot_proposals', { scoped: true, deferChain: true }
),
'/:scope/snapshot-proposal/:snapshotId/:identifier': importRoute(
'views/pages/view_snapshot_proposal', { scoped: true }
),
'/:scope/new/snapshot-proposal/:snapshotId': importRoute(
'views/pages/new_snapshot_proposal', { scoped: true, deferChain: true }
),
}),
});

const script = document.createElement('noscript');
// eslint-disable-next-line max-len
m.render(script, m.trust('<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KRWH69V" height="0" width="0" style="display:none;visibility:hidden"></iframe>'));
document.body.insertBefore(script, document.body.firstChild);

Expand Down
23 changes: 23 additions & 0 deletions client/scripts/controllers/app/web_wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ export default class WebWalletController {
return this._wallets.find((w) => w.name === name);
}

public async locateWallet(address: string, chain?: ChainBase): Promise<IWebWallet<any>> {
const availableWallets = this.availableWallets(chain);
if (availableWallets.length === 0) {
throw new Error('No wallet available');
}

let foundWallet: IWebWallet<string>;
for (const wallet of availableWallets) {
if (!wallet.enabled) {
await wallet.enable();
}
// TODO: ensure that we can find any wallet, even if non-string accounts
if (wallet.accounts.find((acc) => acc === address)) {
foundWallet = wallet;
}
// TODO: disable if not found
}
if (!foundWallet) {
throw new Error(`No wallet found for ${address}`);
}
return foundWallet;
}

constructor() {
this._wallets = [
new PolkadotWebWalletController(),
Expand Down
20 changes: 1 addition & 19 deletions client/scripts/controllers/chain/ethereum/contractApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ export async function attachSigner<CT extends Contract>(
sender: string,
contract: CT
): Promise<CT> {
const availableWallets = wallets.availableWallets(ChainBase.Ethereum);
if (availableWallets.length === 0) {
throw new Error('No wallet available');
}

let signingWallet: IWebWallet<string>;
for (const wallet of availableWallets) {
if (!wallet.enabled) {
await wallet.enable();
}
// TODO: ensure that we can find any wallet, even if non-string accounts
if (wallet.accounts.find((acc) => acc === sender)) {
signingWallet = wallet;
}
}
if (!signingWallet) {
throw new Error('TX sender not found in wallet');
}

const signingWallet = await wallets.locateWallet(sender, ChainBase.Ethereum);
let signer: JsonRpcSigner;
if (signingWallet instanceof MetamaskWebWalletController
|| signingWallet instanceof WalletConnectWebWalletController) {
Expand Down
40 changes: 40 additions & 0 deletions client/scripts/controllers/chain/snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
getProposals,
getSpace,
SnapshotProposal,
SnapshotSpace,
} from 'helpers/snapshot_utils';

class SnapshotController {
private _space: SnapshotSpace;
public get space() { return this._space; }

private _proposals: SnapshotProposal[];
public get proposals() { return this._proposals; }

private _initializing: boolean = false;
private _initialized: boolean = false;
public get initialized() { return this._initialized; }

// private _votes = new Store<SnapshotVote>();

public async refreshProposals() {
const newProposals = await getProposals(this.space.id);
this._proposals = newProposals;
}

public async init(space: string) {
if (this._initializing) return;
this._initializing = true;
try {
this._space = await getSpace(space);
this._proposals = await getProposals(space);
} catch (e) {
console.error(`Failed to fetch snapshot proposals: ${e.message}`);
}
this._initializing = false;
this._initialized = true;
}
}

export default SnapshotController;
102 changes: 102 additions & 0 deletions client/scripts/helpers/apollo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
ApolloClient,
createHttpLink,
InMemoryCache
} from '@apollo/client/core';
import gql from 'graphql-tag';

// HTTP connection to the API
const httpLink = createHttpLink({
// You should use an absolute URL here
uri: `${process.env.SNAPSHOT_HUB_URL || 'https://hub.snapshot.org'}/graphql`
});

// Create the apollo client
export const apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
defaultOptions: {
query: {
fetchPolicy: 'no-cache'
}
}
});

export const SPACE_QUERY = gql`
query Space(
$space: String
) {
space(id: $space) {
id
name
about
symbol
private
network
filters {
minScore
onlyMembers
}
strategies {
name
params
}
members
}
}
`;

export const PROPOSALS_QUERY = gql`
query Proposals(
$first: Int!
$skip: Int!
$state: String!
$space: String
$space_in: [String]
$author_in: [String]
) {
proposals(
first: $first
skip: $skip
where: {
space: $space
state: $state
space_in: $space_in
author_in: $author_in
}
) {
id
ipfs
title
body
choices
start
end
snapshot
state
author
created
}
}
`;

export const PROPOSAL_VOTES_QUERY = gql`
query Votes(
$proposalHash: String!
) {
votes (
first: 10000
skip: 0
where: {
proposal: $proposalHash
}
orderBy: "created",
orderDirection: desc
) {
id
voter
created
choice
}
}
`;
Loading

0 comments on commit cf600cc

Please sign in to comment.