Skip to content

Commit

Permalink
Merge pull request #1996 from daostack/release
Browse files Browse the repository at this point in the history
Release 0.10.13
  • Loading branch information
dkent600 authored Jul 29, 2020
2 parents fdbd3b7 + 03cb27e commit 198520e
Show file tree
Hide file tree
Showing 9 changed files with 1,956 additions and 1,938 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.10.13
- Features Added
- added support for awarding the DMG token

- Bugs Fixed
- fixed issue with redemption of GEN for staking was gated by DAO GEN balance
- fixed that Plugin Proposals page crashed when there is no PluginManager registered to the DAO
- fixed Infura request limits being exceeded
- fix messaging about DXD token

## 0.10.12
- Features Added
- added custom landing page data for Venus Project
Expand Down
5 changes: 5 additions & 0 deletions data/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
"decimals": 18,
"name": "DXdao",
"symbol": "DXD"
},
"0xed91879919b71bb6905f23af0a68d231ecf87b14": {
"decimals": 18,
"name": "DMM: Governance",
"symbol": "DMG"
}
}
},
Expand Down
3,754 changes: 1,836 additions & 1,918 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alchemy-client",
"version": "0.10.12",
"version": "0.10.13",
"description": "An app for collaborative networks (DAOs), based on the DAO stack.",
"author": "DAOstack",
"license": "GPL-3.0",
Expand Down
18 changes: 6 additions & 12 deletions src/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,7 @@ async function enableWeb3Provider(): Promise<void> {
if (!web3Modal) {
_web3Modal = new Web3Modal({
cacheProvider: true,
providerOptions: Object.assign(
/**
* This will hide the web3connect fallback ("Web3") button which currently
* doesn't behave well when there is no available extension. The fallback is
* apparently "for injected providers that haven't been added to the library or
* that don't support the normal specification. Opera is an example of it."
*/
{ disableInjectedProvider: !((window as any).web3 || (window as any).ethereum) },
getArcSettings().web3ConnectProviderOptions) as any,
providerOptions: getArcSettings().web3ConnectProviderOptions,
});

// eslint-disable-next-line require-atomic-updates
Expand Down Expand Up @@ -477,10 +469,12 @@ export async function enableWalletProvider(options: IEnableWalletProviderParams)
return true;
}

// If not MetaMask or other injected web3 and on ganache then try to connect to local ganache directly
if (targetedNetwork() === "ganache" && !(window as any).web3 && !(window as any).ethereum) {
/**
* If not MetaMask or other injected web3 and on ganache then try to connect to local ganache directly.
* Note we're going to ignore any injected web3 in favor of using our own preferred version of Web3.
*/
if (!selectedProvider && (targetedNetwork() === "ganache" && !(window as any).ethereum)) {
selectedProvider = new Web3(settings.ganache.web3Provider);
return true;
}

if (!selectedProvider) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dao/DaoSchemesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DaoSchemesPage extends React.Component<IProps, null> {
const allKnownSchemes = [...contributionReward, ...knownSchemes];

const schemeManager = data[1];
const schemeManagerActive = getSchemeIsActive(schemeManager);
const schemeManagerActive = schemeManager ? getSchemeIsActive(schemeManager) : false;

const schemeCardsHTML = (
<TransitionGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class CreateContributionReward extends React.Component<IProps, IStateProps> {
</div>
</div>

<div className={css.reward}>
<div className={daoAvatarAddress === "0x519b70055af55a007110b4ff99b0ea33071c720a" ? css.hidden : css.reward}>
<label htmlFor="nativeTokenRewardInput">
DAO token ({dao.tokenSymbol}) Reward
<ErrorMessage name="nativeTokenReward">{(msg) => <span className={css.errorMessage}>{msg}</span>}</ErrorMessage>
Expand Down
10 changes: 10 additions & 0 deletions src/lib/schemeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,17 @@ const schemeActionPropNames = new Map<string, Map<GetSchemeIsActiveActions, stri
],
]);

/**
* Returns true or false indicating whether the scheme is active and thus can accept new proposals.
* @param scheme Required parameter that if undefined or null will cause this method to throw an exception.
* @param action For SchemeRegistrar where we are asking specifically about Add and Remove actions.
*/
export function getSchemeIsActive(scheme: ISchemeState, action?: GetSchemeIsActiveActions): boolean {

if (!scheme) {
throw new Error("getSchemeIsActive: scheme parameter is not set");
}

let votingMachineParamsPropertyName: string;
let schemeName = scheme.name ? `${scheme.name[0].toLowerCase()}${scheme.name.slice(1)}` : "";
if (schemeName === "genericScheme") {
Expand Down
91 changes: 86 additions & 5 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
IProposalState,
IRewardState,
} from "@daostack/arc.js";
import { of, Observable } from "rxjs";
import { catchError } from "rxjs/operators";
import { of, Observable, Observer } from "rxjs";
import { catchError, map } from "rxjs/operators";

import BN = require("bn.js");
/**
Expand Down Expand Up @@ -268,7 +268,7 @@ export async function getNetworkId(web3Provider?: any): Promise<string> {

try {
arc = getArc();
} catch (ex) {
} catch {
// Do nothing
}

Expand Down Expand Up @@ -367,7 +367,6 @@ export function getGpRewards(reward: IRewardState, daoBalances: { [key: string]:
* note the following assume that the GenesisProtocol is using GEN for staking
*/
if (reward.tokensForStaker.gt(new BN(0))
&& (daoBalances["GEN"] === undefined || daoBalances["GEN"].gte(reward.tokensForStaker))
&& (reward.tokensForStakerRedeemedAt === 0)) {
result.tokensForStaker = reward.tokensForStaker;
}
Expand Down Expand Up @@ -593,7 +592,89 @@ export function initializeUtils(options: IInitializeOptions) {
**/
export const splitCamelCase = (str: string): string => `${str[0].toUpperCase()}${str.slice(1).replace(/([a-z])([A-Z])/g, "$1 $2")}`;

interface IObservedAccounts {
[address: string]: {
observable?: Observable<BN>;
observer?: Observer<BN>;
lastBalance?: string;
subscriptionsCount: number;
};
}

const ethBalanceObservedAccounts: IObservedAccounts = {};
let ethBalancePollingInterval: any | undefined = undefined;

export function ethBalance(address: Address): Observable<BN> {

const arc = getArc();
return arc.ethBalance(address);

/**
* With a few minor enhancements, this code is virtually the same logic
* as arc.js uses when it creates a wss subscription to efficiently watch
* for changes in eth balances.
*/
if (!ethBalanceObservedAccounts[address]) {
ethBalanceObservedAccounts[address] = {
subscriptionsCount: 1,
};
}
/**
* don't poll more than once for any given address
*/
if (ethBalanceObservedAccounts[address].observable) {
++ethBalanceObservedAccounts[address].subscriptionsCount;
return ethBalanceObservedAccounts[address].observable as Observable<BN>;
}

const observable = Observable.create(async (observer: Observer<BN>) => {

ethBalanceObservedAccounts[address].observer = observer;

await arc.web3.eth.getBalance(address)
.then((currentBalance: string) => {
const accInfo = ethBalanceObservedAccounts[address];
(accInfo.observer as Observer<BN>).next(new BN(currentBalance));
accInfo.lastBalance = currentBalance;
})
.catch((err: Error) => observer.error(err));

if (!ethBalancePollingInterval) {
ethBalancePollingInterval = setInterval(async () => {
Object.keys(ethBalanceObservedAccounts).forEach(async (addr) => {
const accInfo = ethBalanceObservedAccounts[addr];
try {
const balance = await arc.web3.eth.getBalance(addr);
if (balance !== accInfo.lastBalance) {
(accInfo.observer as Observer<BN>).next(new BN(balance));
accInfo.lastBalance = balance;
}
} catch (err) {
observer.error(err);
}
});
}, 60000); // poll every 60 seconds
}
// unsubscribe
return () => {
/**
* What I find is that `unsubscribe` is never called on the observable.
* This might be a flaw in `withSubscription` which was designed to guarantee
* that `unsubscribe` would always be called on its observables.
* Or it may be a flaw in how we are using `combineLatest`.
* Either way, it is a memory/resource leak.
*/
--ethBalanceObservedAccounts[address].subscriptionsCount;
if (ethBalanceObservedAccounts[address].subscriptionsCount <= 0) {
delete ethBalanceObservedAccounts[address];
}
if (Object.keys(ethBalanceObservedAccounts).length === 0 && ethBalancePollingInterval) {
clearTimeout(ethBalancePollingInterval);
ethBalancePollingInterval = undefined;
}
};
});

ethBalanceObservedAccounts[address].observable = observable;

return observable.pipe(map((item: any) => new BN(item)));
}

0 comments on commit 198520e

Please sign in to comment.