Skip to content

Commit

Permalink
Merge pull request #518 from DemocracyEarth/graph
Browse files Browse the repository at this point in the history
Graph Protocol
  • Loading branch information
santisiri authored Jul 23, 2020
2 parents 061e6c1 + ea7a051 commit 4394e81
Show file tree
Hide file tree
Showing 36 changed files with 5,752 additions and 976 deletions.
5 changes: 4 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@
"blocks-compressed": "blocks",
"blocks-singular": "block",
"poll-closed-after-time": "Poll ended after {{days}}.",
"poll-ended-days-ago": "Poll ended {{days}} ago.",
"poll-never-ends": "This poll never ends (always on).",
"height-compressed": "blocks",
"height-singular": "block",
Expand Down Expand Up @@ -796,6 +797,7 @@
"moloch-period-complete": "Completed without outcome.",
"moloch-period-passed": "Approved Proposal 👍",
"moloch-period-rejected": "Rejected Proposal 👎",
"moloch-period-failed": "Rejected Proposal 👎",
"moloch-period-aborted": "Aborted proposal 🤦‍♂️",
"moloch-summoner-share": "Summoner Shares",
"syncing": "Syncing...",
Expand Down Expand Up @@ -881,5 +883,6 @@
"search-summon": "🔥 Summon of {{dao}}",
"search-ragequit": "💸 Ragequit of {{shares}} shares from {{dao}} by {{address}}",
"search-default": "🔍 {{searchTerm}}",
"search-dates": "📅 {{searchTerm}}"
"search-dates": "📅 {{searchTerm}}",
"moloch-unsponsored": "Unsponsored Proposal"
}
7 changes: 7 additions & 0 deletions imports/api/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ Meteor.methods({
return count;
},

/**
* @summary returns the last timestamp
*/
async getLastTimestamp() {
return await getLastTimestamp().then((resolved) => { return resolved; });
},

/**
* @summary get block timme
* @param {object} collective where to persist blocktime
Expand Down
40 changes: 39 additions & 1 deletion imports/startup/both/modules/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,43 @@ const _web3 = (activateModal) => {
return web3;
};


/**
* @summary check web3 plugin and connects to code obejct
*/
const _getWeb3Wallet = (activateModal) => {
let wallet;
if (!window.web3) {
wallet = setupWallet();
if (!wallet) {
if (activateModal) {
modal.message = TAPi18n.__('metamask-install');
displayModal(true, modal);
}
return false;
}
}
if (!wallet && window.web3) {
wallet = new Web3(window.web3.currentProvider);
}

if (!wallet.currentProvider.isFortmatic) {
wallet.eth.getCoinbase().then((coinbase) => {
if (!coinbase) {
if (activateModal) {
modal.message = TAPi18n.__('metamask-activate');
displayModal(true, modal);
return false;
}
}
return undefined;
});
}

return wallet;
};


/**
* @summary get the current status of an on chain transaction
* @param {string} hash of the ticket
Expand Down Expand Up @@ -912,7 +949,7 @@ if (Meteor.isServer) {
*/
const _shortenCryptoName = (publicAddress) => {
if (publicAddress.length === 42 && publicAddress.slice(0, 2) === '0x') {
return `${publicAddress.slice(2, 6)}...${publicAddress.slice(38, 42)}`.toLowerCase();
return `${publicAddress.slice(2, 6)}...${publicAddress.slice(38, 42)}`.toUpperCase();
}
return publicAddress;
};
Expand All @@ -928,3 +965,4 @@ export const getBlockHeight = _getBlockHeight;
export const verifyCoinVote = _verifyCoinVote;
export const submitVote = _submitVote;
export const hasRightToVote = _hasRightToVote;
export const getWeb3Wallet = _getWeb3Wallet;
4 changes: 3 additions & 1 deletion imports/startup/both/modules/oracles.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ const _setCollectiveReplicaScore = (collectiveId, height, valueRank) => {

if (!collective.profile.replica || (collective.profile.replica && collective.profile.replica.lastSyncedBlock < lastSyncedBlock)) {
log(`[oracle] Updating collective ${collective.uri} with replica: ${JSON.stringify(replica)}`);
Collectives.update({ _id: collectiveId }, { $set: { 'profile.replica': replica } });
if (typeof replica.ranking === 'number' && typeof replica.score === 'number') {
Collectives.update({ _id: collectiveId }, { $set: { 'profile.replica': replica } });
}
}
}
return replica;
Expand Down
113 changes: 113 additions & 0 deletions imports/ui/components/Account/Account.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { Meteor } from 'meteor/meteor';
import React from 'react';
import PropTypes from 'prop-types';
import { TAPi18n } from 'meteor/tap:i18n';

import ApolloClient, { gql, InMemoryCache } from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
import { useQuery } from '@apollo/react-hooks';

import { shortenCryptoName } from '/imports/startup/both/modules/metamask';


const makeBlockie = require('ethereum-blockies-base64');

const client = new ApolloClient({
uri: Meteor.settings.public.graph.ens,
cache: new InMemoryCache(),
});


const ENS_ACCOUNT = `
{
domains(where: { resolvedAddress: "{{ensAddress}}" }) {
id
name
labelName
labelhash
resolvedAddress {
id
}
}
}
`;

/**
* @summary writes name based on ENS settings
* @param {object} data obtained from graph protocol
* @param {string} publicAddress to parse
*/
const getENSName = (data, publicAddress) => {
if (data.domains.length > 0) {
return data.domains[0].name;
}
return shortenCryptoName(publicAddress);
};

/**
* @summary renders a post in the timeline
*/
const AccountQuery = ({ publicAddress, width, height }) => {
let label;

const image = makeBlockie(publicAddress);
const url = `/address/${publicAddress}`;
const finalWidth = width || '24px';
const finalHeight = height || '24px';

if (publicAddress !== '0x0000000000000000000000000000000000000000') {
const { loading, error, data } = useQuery(gql(ENS_ACCOUNT.replace('{{ensAddress}}', publicAddress)));

if (loading) {
return (
<div className="identity">
<div className="avatar-editor">
<img src={image} className="symbol profile-pic" role="presentation" style={{ width: finalWidth, height: finalHeight }} />
<div className="identity-peer">
<div className="option-placeholder identity-placeholder" />
</div>
</div>
</div>
);
}
if (error) return `Error! ${error}`;

label = getENSName(data, publicAddress);
} else {
label = '0x0';
}

return (
<div className="identity">
<div className="avatar-editor">
<img src={image} className="symbol profile-pic" role="presentation" style={{ width: finalWidth, height: finalHeight }} />
<div className="identity-peer">
<a href={url} title={publicAddress} className="identity-label identity-label-micro">
{label}
</a>
</div>
</div>
</div>
);
};

AccountQuery.propTypes = {
publicAddress: PropTypes.string,
width: PropTypes.string,
height: PropTypes.string,
};

/**
* @summary renders a post in the timeline
*/
const Account = (props) => {
return (
<ApolloProvider client={client}>
<AccountQuery publicAddress={props.publicAddress} width={props.width} height={props.height} />
</ApolloProvider>
);
};

Account.propTypes = AccountQuery.propTypes;

export default Account;
Loading

0 comments on commit 4394e81

Please sign in to comment.