From eca7c7ef77fad446b983df360f6ab2eef9c8abcc Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Mon, 11 May 2020 12:54:57 -0400 Subject: [PATCH 1/6] init --- src/components/Members.tsx | 1 + src/runtime/Component.tsx | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/Members.tsx b/src/components/Members.tsx index 90e6446..4839908 100644 --- a/src/components/Members.tsx +++ b/src/components/Members.tsx @@ -59,6 +59,7 @@ class InferredMembers extends ComponentList { address={entity.coreState!.address} dao={entity.coreState!.dao.entity} config={config} + entity={entity} > {children} diff --git a/src/runtime/Component.tsx b/src/runtime/Component.tsx index 1358d26..4508e52 100644 --- a/src/runtime/Component.tsx +++ b/src/runtime/Component.tsx @@ -15,12 +15,16 @@ export interface State { logs: ComponentLogs; } -export interface ComponentProps { +export interface ComponentProps< + Entity extends StatefulEntity, + Data extends IStatefulEntityData +> { noSub?: boolean; + entity?: Entity; } export abstract class Component< - Props extends ComponentProps, + Props extends ComponentProps, Entity extends StatefulEntity, Data extends IStatefulEntityData > extends React.Component> { @@ -134,6 +138,7 @@ export abstract class Component< props: Props ): Promise { const { logs } = this.state; + const { entity } = this.props; logs.entityCreated(); @@ -142,8 +147,12 @@ export abstract class Component< this.clearPrevState(); try { - const asyncFunction = this.createEntity.bind(this); - this._entity = await executeMaybeAsyncFunction(asyncFunction); + if (entity !== undefined) { + this._entity = entity; + } else { + const asyncFunction = this.createEntity.bind(this); + this._entity = await executeMaybeAsyncFunction(asyncFunction); + } logs.dataQueryStarted(); await this.initialize(this._entity); From 527b20b28acf903981e2f21f99627da1a154ba39 Mon Sep 17 00:00:00 2001 From: cbrzn Date: Tue, 12 May 2020 16:32:28 +0200 Subject: [PATCH 2/6] [WIP] implementing in every component --- src/components/DAO.tsx | 2 +- src/components/Member.tsx | 2 +- src/components/Queue.tsx | 2 +- src/components/Reputation.tsx | 2 +- src/components/Reward.tsx | 2 +- src/components/Stake.tsx | 2 +- src/components/Tag.tsx | 2 +- src/components/Token.tsx | 2 +- src/components/Vote.tsx | 2 +- src/components/plugins/Competition/Plugin.tsx | 2 +- src/components/plugins/Competition/Proposal.tsx | 2 +- src/components/plugins/ContributionReward/Plugin.tsx | 2 +- src/components/plugins/ContributionReward/Proposal.tsx | 2 +- .../plugins/ContributionRewardExt/Plugin.tsx | 2 +- .../plugins/ContributionRewardExt/Proposal.tsx | 2 +- src/components/plugins/GenericPlugin/Plugin.tsx | 2 +- src/components/plugins/GenericPlugin/Proposal.tsx | 2 +- src/components/plugins/Plugin.tsx | 2 +- src/components/plugins/Proposal.tsx | 2 +- src/components/plugins/ReputationFromToken/Plugin.tsx | 2 +- src/components/plugins/SchemeRegistrar/Plugin.tsx | 2 +- src/components/plugins/SchemeRegistrar/Proposal.tsx | 2 +- src/runtime/Component.tsx | 10 ++++++---- 23 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/components/DAO.tsx b/src/components/DAO.tsx index d3e4e50..2dc2391 100644 --- a/src/components/DAO.tsx +++ b/src/components/DAO.tsx @@ -9,7 +9,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the DAO Avatar address: string; } diff --git a/src/components/Member.tsx b/src/components/Member.tsx index dd6a34c..cb26fa1 100644 --- a/src/components/Member.tsx +++ b/src/components/Member.tsx @@ -11,7 +11,7 @@ import { import { CreateContextFeed } from "../runtime/ContextFeed"; import { Member as Entity, IMemberState as Data } from "@dorgtech/arc.js"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the member address: string; dao?: string | DAOEntity; diff --git a/src/components/Queue.tsx b/src/components/Queue.tsx index 6d41880..d40eb5b 100644 --- a/src/components/Queue.tsx +++ b/src/components/Queue.tsx @@ -11,7 +11,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the Queue Avatar id: string; dao?: string | DAOEntity; diff --git a/src/components/Reputation.tsx b/src/components/Reputation.tsx index ba7c5fe..01d916b 100644 --- a/src/components/Reputation.tsx +++ b/src/components/Reputation.tsx @@ -14,7 +14,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the Reputation Token address?: string; } diff --git a/src/components/Reward.tsx b/src/components/Reward.tsx index 880f3f8..bf8b3dc 100644 --- a/src/components/Reward.tsx +++ b/src/components/Reward.tsx @@ -9,7 +9,7 @@ import { ComponentProps, } from "../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Reward ID id: string; } diff --git a/src/components/Stake.tsx b/src/components/Stake.tsx index 5bd0715..aaf2330 100644 --- a/src/components/Stake.tsx +++ b/src/components/Stake.tsx @@ -9,7 +9,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Stake ID id: string; } diff --git a/src/components/Tag.tsx b/src/components/Tag.tsx index 07bd52c..00d985c 100644 --- a/src/components/Tag.tsx +++ b/src/components/Tag.tsx @@ -9,7 +9,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the Tag Avatar id: string; } diff --git a/src/components/Token.tsx b/src/components/Token.tsx index 764eee5..bd703e0 100644 --- a/src/components/Token.tsx +++ b/src/components/Token.tsx @@ -11,7 +11,7 @@ import { } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Address of the Token address?: string; } diff --git a/src/components/Vote.tsx b/src/components/Vote.tsx index 9774510..95ced27 100644 --- a/src/components/Vote.tsx +++ b/src/components/Vote.tsx @@ -4,7 +4,7 @@ import { CreateContextFeed } from "../runtime/ContextFeed"; import { Arc as Protocol, ArcConfig as ProtocolConfig } from "../protocol"; import { Vote as Entity, IVoteState as Data } from "@dorgtech/arc.js"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Vote ID id: string; } diff --git a/src/components/plugins/Competition/Plugin.tsx b/src/components/plugins/Competition/Plugin.tsx index ada49ce..f192da2 100644 --- a/src/components/plugins/Competition/Plugin.tsx +++ b/src/components/plugins/Competition/Plugin.tsx @@ -12,7 +12,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/Competition/Proposal.tsx b/src/components/plugins/Competition/Proposal.tsx index a1d5a9c..b333665 100644 --- a/src/components/plugins/Competition/Proposal.tsx +++ b/src/components/plugins/Competition/Proposal.tsx @@ -12,7 +12,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } diff --git a/src/components/plugins/ContributionReward/Plugin.tsx b/src/components/plugins/ContributionReward/Plugin.tsx index 877714f..6214946 100644 --- a/src/components/plugins/ContributionReward/Plugin.tsx +++ b/src/components/plugins/ContributionReward/Plugin.tsx @@ -17,7 +17,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/ContributionReward/Proposal.tsx b/src/components/plugins/ContributionReward/Proposal.tsx index a7736bf..7822003 100644 --- a/src/components/plugins/ContributionReward/Proposal.tsx +++ b/src/components/plugins/ContributionReward/Proposal.tsx @@ -12,7 +12,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } diff --git a/src/components/plugins/ContributionRewardExt/Plugin.tsx b/src/components/plugins/ContributionRewardExt/Plugin.tsx index 4ab17f6..3a07146 100644 --- a/src/components/plugins/ContributionRewardExt/Plugin.tsx +++ b/src/components/plugins/ContributionRewardExt/Plugin.tsx @@ -12,7 +12,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/ContributionRewardExt/Proposal.tsx b/src/components/plugins/ContributionRewardExt/Proposal.tsx index 0073cb9..53fce27 100644 --- a/src/components/plugins/ContributionRewardExt/Proposal.tsx +++ b/src/components/plugins/ContributionRewardExt/Proposal.tsx @@ -12,7 +12,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } diff --git a/src/components/plugins/GenericPlugin/Plugin.tsx b/src/components/plugins/GenericPlugin/Plugin.tsx index a228231..a199a6a 100644 --- a/src/components/plugins/GenericPlugin/Plugin.tsx +++ b/src/components/plugins/GenericPlugin/Plugin.tsx @@ -12,7 +12,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/GenericPlugin/Proposal.tsx b/src/components/plugins/GenericPlugin/Proposal.tsx index e5e560f..1299109 100644 --- a/src/components/plugins/GenericPlugin/Proposal.tsx +++ b/src/components/plugins/GenericPlugin/Proposal.tsx @@ -12,7 +12,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } diff --git a/src/components/plugins/Plugin.tsx b/src/components/plugins/Plugin.tsx index c879e97..f11d7e5 100644 --- a/src/components/plugins/Plugin.tsx +++ b/src/components/plugins/Plugin.tsx @@ -17,7 +17,7 @@ import { CreateContextFeed } from "../../runtime/ContextFeed"; abstract class Entity extends BaseEntity {} type Data = BaseData; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id: Entity | string; } diff --git a/src/components/plugins/Proposal.tsx b/src/components/plugins/Proposal.tsx index 5f688ba..305255c 100644 --- a/src/components/plugins/Proposal.tsx +++ b/src/components/plugins/Proposal.tsx @@ -16,7 +16,7 @@ import { CreateContextFeed } from "../../runtime/ContextFeed"; abstract class Entity extends BaseEntity {} type Data = BaseData; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id: Entity | string; } diff --git a/src/components/plugins/ReputationFromToken/Plugin.tsx b/src/components/plugins/ReputationFromToken/Plugin.tsx index b32e808..ecfb33f 100644 --- a/src/components/plugins/ReputationFromToken/Plugin.tsx +++ b/src/components/plugins/ReputationFromToken/Plugin.tsx @@ -12,7 +12,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/SchemeRegistrar/Plugin.tsx b/src/components/plugins/SchemeRegistrar/Plugin.tsx index faabece..46613eb 100644 --- a/src/components/plugins/SchemeRegistrar/Plugin.tsx +++ b/src/components/plugins/SchemeRegistrar/Plugin.tsx @@ -12,7 +12,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } diff --git a/src/components/plugins/SchemeRegistrar/Proposal.tsx b/src/components/plugins/SchemeRegistrar/Proposal.tsx index cb57f14..587ced3 100644 --- a/src/components/plugins/SchemeRegistrar/Proposal.tsx +++ b/src/components/plugins/SchemeRegistrar/Proposal.tsx @@ -12,7 +12,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } diff --git a/src/runtime/Component.tsx b/src/runtime/Component.tsx index 4508e52..c70290d 100644 --- a/src/runtime/Component.tsx +++ b/src/runtime/Component.tsx @@ -155,7 +155,7 @@ export abstract class Component< } logs.dataQueryStarted(); - await this.initialize(this._entity); + await this.initialize(this._entity!); this._initialized = true; if (this._subscription) { @@ -164,9 +164,11 @@ export abstract class Component< // by default we subscribe to this entity's state changes if (!props.noSub) { - this._subscription = this._entity - .state({}) - .subscribe(this.onQueryData, this.onQueryError, this.onQueryComplete); + this._subscription = this._entity!.state({}).subscribe( + this.onQueryData, + this.onQueryError, + this.onQueryComplete + ); } this.forceUpdate(); From 24c961f85f007fb20b0dffc1e199ee6f42abb728 Mon Sep 17 00:00:00 2001 From: cbrzn Date: Tue, 12 May 2020 17:15:55 +0200 Subject: [PATCH 3/6] no more double fetch --- src/components/DAOs.tsx | 1 + src/components/Queues.tsx | 1 + src/components/Reputations.tsx | 1 + src/components/Rewards.tsx | 7 ++++++- src/components/Stakes.tsx | 7 ++++++- src/components/Tags.tsx | 7 ++++++- src/components/Tokens.tsx | 1 + src/components/Votes.tsx | 7 ++++++- .../plugins/FundingRequest/Plugin.tsx | 8 ++++---- .../plugins/FundingRequest/Proposal.tsx | 8 ++++---- src/components/plugins/JoinAndQuit/Plugin.tsx | 15 +++++++-------- .../plugins/JoinAndQuit/Proposal.tsx | 8 ++++---- test/dao.spec.tsx | 18 +++++++++++++++--- test/member.spec.tsx | 12 ++++++++++-- test/reward.spec.tsx | 3 --- test/stake.spec.tsx | 3 --- test/vote.spec.tsx | 3 --- 17 files changed, 72 insertions(+), 38 deletions(-) diff --git a/src/components/DAOs.tsx b/src/components/DAOs.tsx index 3edbf70..f3eafc7 100644 --- a/src/components/DAOs.tsx +++ b/src/components/DAOs.tsx @@ -43,6 +43,7 @@ class InferredDAOs extends ComponentList { key={`${entity.id}_${index}`} address={entity.id} config={config} + entity={entity} > {children} diff --git a/src/components/Queues.tsx b/src/components/Queues.tsx index 0e32c42..2c26f80 100644 --- a/src/components/Queues.tsx +++ b/src/components/Queues.tsx @@ -57,6 +57,7 @@ class InferredQueues extends ComponentList { dao={dao} id={entity.id} config={config} + entity={entity} > {children} diff --git a/src/components/Reputations.tsx b/src/components/Reputations.tsx index 5324585..7f81c8c 100644 --- a/src/components/Reputations.tsx +++ b/src/components/Reputations.tsx @@ -44,6 +44,7 @@ class InferredReputations extends ComponentList { key={`${entity.id}_${index}`} address={entity.address} config={config} + entity={entity} > {children} diff --git a/src/components/Rewards.tsx b/src/components/Rewards.tsx index 349ca82..089740c 100644 --- a/src/components/Rewards.tsx +++ b/src/components/Rewards.tsx @@ -66,7 +66,12 @@ class InferredRewards extends ComponentList { const { config } = this.props; return ( - + {children} ); diff --git a/src/components/Stakes.tsx b/src/components/Stakes.tsx index d1fe041..e69f83f 100644 --- a/src/components/Stakes.tsx +++ b/src/components/Stakes.tsx @@ -67,7 +67,12 @@ class InferredStakes extends ComponentList { } return ( - + {children} ); diff --git a/src/components/Tags.tsx b/src/components/Tags.tsx index 066ab3a..c6e875c 100644 --- a/src/components/Tags.tsx +++ b/src/components/Tags.tsx @@ -39,7 +39,12 @@ class InferredTags extends ComponentList { const { config } = this.props; return ( - + {children} ); diff --git a/src/components/Tokens.tsx b/src/components/Tokens.tsx index 6014f8d..1828f57 100644 --- a/src/components/Tokens.tsx +++ b/src/components/Tokens.tsx @@ -43,6 +43,7 @@ class InferredTokens extends ComponentList { key={`${entity.id}_${index}`} address={entity.address} config={config} + entity={entity} > {children} diff --git a/src/components/Votes.tsx b/src/components/Votes.tsx index ed32e44..49f7bfd 100644 --- a/src/components/Votes.tsx +++ b/src/components/Votes.tsx @@ -66,7 +66,12 @@ class InferredVotes extends ComponentList { } return ( - + {children} ); diff --git a/src/components/plugins/FundingRequest/Plugin.tsx b/src/components/plugins/FundingRequest/Plugin.tsx index 7c5cfc0..86f7991 100644 --- a/src/components/plugins/FundingRequest/Plugin.tsx +++ b/src/components/plugins/FundingRequest/Plugin.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import { +import { FundingRequest as Entity, - IFundingRequestState as Data + IFundingRequestState as Data, } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; import { @@ -13,7 +13,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } @@ -120,5 +120,5 @@ export { FundingRequestPlugin, InferredFundingRequestPlugin, Entity as FundingRequestPluginEntity, - Data as FundingRequestPluginData + Data as FundingRequestPluginData, }; diff --git a/src/components/plugins/FundingRequest/Proposal.tsx b/src/components/plugins/FundingRequest/Proposal.tsx index e57c36a..8f08484 100644 --- a/src/components/plugins/FundingRequest/Proposal.tsx +++ b/src/components/plugins/FundingRequest/Proposal.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import { +import { FundingRequestProposal as Entity, - IFundingRequestProposalState as Data + IFundingRequestProposalState as Data, } from "@dorgtech/arc.js"; import { Arc as Protocol, @@ -13,7 +13,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } @@ -119,5 +119,5 @@ export { InferredFundingRequestProposal, FundingRequestProposal, Entity as FundingRequestProposalEntity, - Data as FundingRequestProposalData + Data as FundingRequestProposalData, }; diff --git a/src/components/plugins/JoinAndQuit/Plugin.tsx b/src/components/plugins/JoinAndQuit/Plugin.tsx index 4e8e840..8ac3941 100644 --- a/src/components/plugins/JoinAndQuit/Plugin.tsx +++ b/src/components/plugins/JoinAndQuit/Plugin.tsx @@ -1,5 +1,8 @@ import * as React from "react"; -import { JoinAndQuit as Entity, IJoinAndQuitState as Data } from "@dorgtech/arc.js"; +import { + JoinAndQuit as Entity, + IJoinAndQuitState as Data, +} from "@dorgtech/arc.js"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; import { Arc as Protocol, @@ -10,7 +13,7 @@ import { Plugin, } from "../../../"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Plugin ID id?: string | Entity; } @@ -20,11 +23,7 @@ interface InferredProps extends RequiredProps { id: string | Entity; } -class InferredJoinAndQuitPlugin extends Component< - InferredProps, - Entity, - Data -> { +class InferredJoinAndQuitPlugin extends Component { protected createEntity(): Entity { const { config, id } = this.props; @@ -117,5 +116,5 @@ export { JoinAndQuitPlugin, InferredJoinAndQuitPlugin, Entity as JoinAndQuitPluginEntity, - Data as JoinAndQuitPluginData + Data as JoinAndQuitPluginData, }; diff --git a/src/components/plugins/JoinAndQuit/Proposal.tsx b/src/components/plugins/JoinAndQuit/Proposal.tsx index 4df9013..b6b3227 100644 --- a/src/components/plugins/JoinAndQuit/Proposal.tsx +++ b/src/components/plugins/JoinAndQuit/Proposal.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import { +import { JoinAndQuitProposal as Entity, - IJoinAndQuitProposalState as Data + IJoinAndQuitProposalState as Data, } from "@dorgtech/arc.js"; import { Arc as Protocol, @@ -13,7 +13,7 @@ import { } from "../../../"; import { CreateContextFeed } from "../../../runtime/ContextFeed"; -interface RequiredProps extends ComponentProps { +interface RequiredProps extends ComponentProps { // Proposal ID id?: string | Entity; } @@ -119,5 +119,5 @@ export { InferredJoinAndQuitProposal, JoinAndQuitProposal, Entity as JoinAndQuitProposalEntity, - Data as JoinAndQuitProposalData + Data as JoinAndQuitProposalData, }; diff --git a/test/dao.spec.tsx b/test/dao.spec.tsx index f8683f6..c67d2e9 100644 --- a/test/dao.spec.tsx +++ b/test/dao.spec.tsx @@ -1,4 +1,11 @@ import React from "react"; +import { + render, + screen, + cleanup, + waitFor, + waitForElementToBeRemoved, +} from "@testing-library/react"; import { Arc, ArcConfig, @@ -9,7 +16,6 @@ import { Member, MemberData, } from "../src"; -import { render, screen, cleanup } from "@testing-library/react"; const daoAddress = "0x666a6eb4618d0438511c8206df4d5b142837eb0d"; const arcConfig = new ArcConfig("private"); @@ -56,7 +62,10 @@ describe("DAO List", () => { } it("Show list of DAOS ", async () => { - const { findAllByText } = render(); + const { findAllByText, queryAllByTestId } = render(); + await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { + timeout: 8000, + }); const daos = await findAllByText(/DAO address:/); expect(daos.length).toBeGreaterThan(1); }); @@ -83,7 +92,10 @@ describe("DAO List", () => { ); } } - const { findAllByText } = render(); + const { findAllByText, queryAllByTestId } = render(); + await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { + timeout: 8000, + }); const members = await findAllByText(/Member address:/); expect(members.length).toBeGreaterThan(1); }); diff --git a/test/member.spec.tsx b/test/member.spec.tsx index 1c64bfb..ad9d442 100644 --- a/test/member.spec.tsx +++ b/test/member.spec.tsx @@ -8,7 +8,12 @@ import { DAOData, Members, } from "../src"; -import { render, screen, cleanup } from "@testing-library/react"; +import { + render, + screen, + cleanup, + waitForElementToBeRemoved, +} from "@testing-library/react"; const daoAddress = "0x666a6eb4618d0438511c8206df4d5b142837eb0d"; const memberAddress = "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1"; @@ -108,7 +113,10 @@ describe("Member List", () => { } it("Show list of member ", async () => { - const { findAllByText } = render(); + const { findAllByText, queryAllByTestId } = render(); + await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { + timeout: 8000, + }); const members = await findAllByText(/Member address:/); expect(members.length).toBeGreaterThan(1); }); diff --git a/test/reward.spec.tsx b/test/reward.spec.tsx index 0da0334..1867161 100644 --- a/test/reward.spec.tsx +++ b/test/reward.spec.tsx @@ -58,9 +58,6 @@ describe("Reward List", () => { const { findAllByText, queryAllByTestId, findByText } = render( ); - await waitFor(() => findByText(/Reward id:/), { - timeout: 8000, - }); await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 8000, }); diff --git a/test/stake.spec.tsx b/test/stake.spec.tsx index 91e4bd6..6b80ef2 100644 --- a/test/stake.spec.tsx +++ b/test/stake.spec.tsx @@ -59,9 +59,6 @@ describe("Stake List", () => { const { findAllByText, queryAllByTestId, findByText } = render( ); - await waitFor(() => findByText(/Stake id:/), { - timeout: 8000, - }); await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 8000, }); diff --git a/test/vote.spec.tsx b/test/vote.spec.tsx index 1589c7e..88fc3b8 100644 --- a/test/vote.spec.tsx +++ b/test/vote.spec.tsx @@ -58,9 +58,6 @@ describe("Vote List", () => { const { findAllByText, queryAllByTestId, findByText } = render( ); - await waitFor(() => findByText(/Vote id/), { - timeout: 8000, - }); await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 8000, }); From 3faee2f462ac0bf3e6245890c238f6bea5cdfe65 Mon Sep 17 00:00:00 2001 From: cbrzn Date: Tue, 12 May 2020 17:31:22 +0200 Subject: [PATCH 4/6] import order fixed --- src/components/Member.tsx | 2 +- src/components/Members.tsx | 2 +- src/components/Queues.tsx | 2 +- src/components/Reputations.tsx | 3 +-- src/components/Rewards.tsx | 2 +- src/components/Tokens.tsx | 2 +- src/components/Vote.tsx | 2 +- src/components/Votes.tsx | 2 +- test/customLoader.spec.tsx | 2 +- test/dao.spec.tsx | 1 - test/member.spec.tsx | 12 ++++++------ test/plugin.spec.tsx | 2 +- test/proposal.spec.tsx | 2 +- test/queue.spec.tsx | 2 +- test/reputation.spec.tsx | 14 +++++++------- test/reward.spec.tsx | 7 ++----- 16 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/components/Member.tsx b/src/components/Member.tsx index cb26fa1..db1203b 100644 --- a/src/components/Member.tsx +++ b/src/components/Member.tsx @@ -1,4 +1,5 @@ import * as React from "react"; +import { Member as Entity, IMemberState as Data } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -9,7 +10,6 @@ import { ComponentProps, } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -import { Member as Entity, IMemberState as Data } from "@dorgtech/arc.js"; interface RequiredProps extends ComponentProps { // Address of the member diff --git a/src/components/Members.tsx b/src/components/Members.tsx index 4839908..f8ae9fc 100644 --- a/src/components/Members.tsx +++ b/src/components/Members.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { IMemberQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -14,7 +15,6 @@ import { ComponentListProps, createFilterFromScope, } from "../"; -import { IMemberQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../runtime/ContextFeed"; type Scopes = "DAO"; diff --git a/src/components/Queues.tsx b/src/components/Queues.tsx index 2c26f80..c42c9d3 100644 --- a/src/components/Queues.tsx +++ b/src/components/Queues.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { IQueueQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -14,7 +15,6 @@ import { ComponentListProps, createFilterFromScope, } from "../"; -import { IQueueQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../runtime/ContextFeed"; type Scopes = "DAO"; diff --git a/src/components/Reputations.tsx b/src/components/Reputations.tsx index 7f81c8c..0001b64 100644 --- a/src/components/Reputations.tsx +++ b/src/components/Reputations.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { IReputationQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -11,8 +12,6 @@ import { ComponentListLogs, ComponentListProps, } from "../"; - -import { IReputationQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../runtime/ContextFeed"; type RequiredProps = ComponentListProps; diff --git a/src/components/Rewards.tsx b/src/components/Rewards.tsx index 089740c..d966536 100644 --- a/src/components/Rewards.tsx +++ b/src/components/Rewards.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { IRewardQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -21,7 +22,6 @@ import { createFilterFromScope, } from "../"; import { CreateContextFeed } from "../runtime/ContextFeed"; -import { IRewardQueryOptions as FilterOptions } from "@dorgtech/arc.js"; type Scopes = "DAO" | "Member as beneficiary" | "Proposal" | "Token"; diff --git a/src/components/Tokens.tsx b/src/components/Tokens.tsx index 1828f57..e00e671 100644 --- a/src/components/Tokens.tsx +++ b/src/components/Tokens.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { ITokenQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -11,7 +12,6 @@ import { ComponentListLogs, ComponentListProps, } from "../"; -import { ITokenQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../runtime/ContextFeed"; type RequiredProps = ComponentListProps; diff --git a/src/components/Vote.tsx b/src/components/Vote.tsx index 95ced27..67aa960 100644 --- a/src/components/Vote.tsx +++ b/src/components/Vote.tsx @@ -1,8 +1,8 @@ import * as React from "react"; +import { Vote as Entity, IVoteState as Data } from "@dorgtech/arc.js"; import { Component, ComponentLogs, ComponentProps } from "../runtime"; import { CreateContextFeed } from "../runtime/ContextFeed"; import { Arc as Protocol, ArcConfig as ProtocolConfig } from "../protocol"; -import { Vote as Entity, IVoteState as Data } from "@dorgtech/arc.js"; interface RequiredProps extends ComponentProps { // Vote ID diff --git a/src/components/Votes.tsx b/src/components/Votes.tsx index 49f7bfd..d858b5c 100644 --- a/src/components/Votes.tsx +++ b/src/components/Votes.tsx @@ -1,5 +1,6 @@ import * as React from "react"; import { Observable } from "rxjs"; +import { IVoteQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { Arc as Protocol, ArcConfig as ProtocolConfig, @@ -18,7 +19,6 @@ import { ComponentListProps, createFilterFromScope, } from "../"; -import { IVoteQueryOptions as FilterOptions } from "@dorgtech/arc.js"; import { CreateContextFeed } from "../runtime/ContextFeed"; type Scopes = "DAO" | "Member as voter" | "Proposal"; diff --git a/test/customLoader.spec.tsx b/test/customLoader.spec.tsx index fd2a4cc..f2325c1 100644 --- a/test/customLoader.spec.tsx +++ b/test/customLoader.spec.tsx @@ -1,4 +1,5 @@ import React from "react"; +import { render, screen, cleanup } from "@testing-library/react"; import { Arc, ArcConfig, @@ -7,7 +8,6 @@ import { LoadingRenderProps, DAOData, } from "../src"; -import { render, screen, cleanup } from "@testing-library/react"; describe("Custom loader ", () => { afterEach(() => cleanup()); diff --git a/test/dao.spec.tsx b/test/dao.spec.tsx index c67d2e9..f887ddb 100644 --- a/test/dao.spec.tsx +++ b/test/dao.spec.tsx @@ -3,7 +3,6 @@ import { render, screen, cleanup, - waitFor, waitForElementToBeRemoved, } from "@testing-library/react"; import { diff --git a/test/member.spec.tsx b/test/member.spec.tsx index ad9d442..ecbe15b 100644 --- a/test/member.spec.tsx +++ b/test/member.spec.tsx @@ -1,4 +1,10 @@ import React from "react"; +import { + render, + screen, + cleanup, + waitForElementToBeRemoved, +} from "@testing-library/react"; import { Arc, ArcConfig, @@ -8,12 +14,6 @@ import { DAOData, Members, } from "../src"; -import { - render, - screen, - cleanup, - waitForElementToBeRemoved, -} from "@testing-library/react"; const daoAddress = "0x666a6eb4618d0438511c8206df4d5b142837eb0d"; const memberAddress = "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1"; diff --git a/test/plugin.spec.tsx b/test/plugin.spec.tsx index a335819..ca1c4b4 100644 --- a/test/plugin.spec.tsx +++ b/test/plugin.spec.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { Arc, ArcConfig, PluginData, Plugin, Plugins } from "../src"; import { render, screen, @@ -7,6 +6,7 @@ import { waitFor, cleanup, } from "@testing-library/react"; +import { Arc, ArcConfig, PluginData, Plugin, Plugins } from "../src"; const arcConfig = new ArcConfig("private"); diff --git a/test/proposal.spec.tsx b/test/proposal.spec.tsx index 505bfd9..a0b480b 100644 --- a/test/proposal.spec.tsx +++ b/test/proposal.spec.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { Arc, ArcConfig, ProposalData, Proposal, Proposals, DAO } from "../src"; import { render, screen, @@ -7,6 +6,7 @@ import { waitFor, cleanup, } from "@testing-library/react"; +import { Arc, ArcConfig, ProposalData, Proposal, Proposals, DAO } from "../src"; const arcConfig = new ArcConfig("private"); diff --git a/test/queue.spec.tsx b/test/queue.spec.tsx index 1b2f570..8459d4f 100644 --- a/test/queue.spec.tsx +++ b/test/queue.spec.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { Arc, ArcConfig, Queue, QueueData, Queues, DAO } from "../src"; import { render, screen, @@ -7,6 +6,7 @@ import { waitFor, waitForElementToBeRemoved, } from "@testing-library/react"; +import { Arc, ArcConfig, Queue, QueueData, Queues, DAO } from "../src"; const daoAddress = "0x666a6eb4618d0438511c8206df4d5b142837eb0d"; const queueId = diff --git a/test/reputation.spec.tsx b/test/reputation.spec.tsx index 3a2d2f2..e09833b 100644 --- a/test/reputation.spec.tsx +++ b/test/reputation.spec.tsx @@ -1,4 +1,11 @@ import React from "react"; +import { + render, + screen, + waitForElementToBeRemoved, + waitFor, + cleanup, +} from "@testing-library/react"; import { Arc, ArcConfig, @@ -7,13 +14,6 @@ import { Reputations, DAO, } from "../src"; -import { - render, - screen, - waitForElementToBeRemoved, - waitFor, - cleanup, -} from "@testing-library/react"; const arcConfig = new ArcConfig("private"); const reputationAddress = "0xebbe3726558bea9869d397505c9dec2a6fb9a433"; diff --git a/test/reward.spec.tsx b/test/reward.spec.tsx index 1867161..a8eed8f 100644 --- a/test/reward.spec.tsx +++ b/test/reward.spec.tsx @@ -1,12 +1,11 @@ import React from "react"; -import { Arc, ArcConfig, RewardData, Reward, Rewards } from "../src"; import { render, screen, waitForElementToBeRemoved, - waitFor, cleanup, } from "@testing-library/react"; +import { Arc, ArcConfig, RewardData, Reward, Rewards } from "../src"; const arcConfig = new ArcConfig("private"); const rewardId = @@ -55,9 +54,7 @@ describe("Reward List", () => { } it("Show list of reward ", async () => { - const { findAllByText, queryAllByTestId, findByText } = render( - - ); + const { findAllByText, queryAllByTestId } = render(); await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 8000, }); From aae0d41977cff6d29a5e4511a7f526a64d5212e7 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 21 May 2020 22:15:06 -0400 Subject: [PATCH 5/6] fixes --- src/components/plugins/Plugins.tsx | 7 ++++++- src/components/plugins/Proposals.tsx | 1 + src/runtime/Component.tsx | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/plugins/Plugins.tsx b/src/components/plugins/Plugins.tsx index ae00387..2d476a8 100644 --- a/src/components/plugins/Plugins.tsx +++ b/src/components/plugins/Plugins.tsx @@ -53,7 +53,12 @@ class InferredPlugins extends ComponentList { const { config } = this.props; return ( - + {children} ); diff --git a/src/components/plugins/Proposals.tsx b/src/components/plugins/Proposals.tsx index de03a6a..90e22f3 100644 --- a/src/components/plugins/Proposals.tsx +++ b/src/components/plugins/Proposals.tsx @@ -61,6 +61,7 @@ class InferredProposals extends ComponentList { key={`${entity.id}_${index}`} id={entity.id} config={this.props.config} + entity={entity} > {children} diff --git a/src/runtime/Component.tsx b/src/runtime/Component.tsx index c70290d..0bfb840 100644 --- a/src/runtime/Component.tsx +++ b/src/runtime/Component.tsx @@ -150,12 +150,16 @@ export abstract class Component< if (entity !== undefined) { this._entity = entity; } else { - const asyncFunction = this.createEntity.bind(this); - this._entity = await executeMaybeAsyncFunction(asyncFunction); + const func = this.createEntity.bind(this); + this._entity = await executeMaybeAsyncFunction(func); + } + + if (!this._entity) { + throw Error(`This should never happen, Entity undefined.`); } logs.dataQueryStarted(); - await this.initialize(this._entity!); + await this.initialize(this._entity); this._initialized = true; if (this._subscription) { @@ -164,11 +168,9 @@ export abstract class Component< // by default we subscribe to this entity's state changes if (!props.noSub) { - this._subscription = this._entity!.state({}).subscribe( - this.onQueryData, - this.onQueryError, - this.onQueryComplete - ); + this._subscription = this._entity + .state({}) + .subscribe(this.onQueryData, this.onQueryError, this.onQueryComplete); } this.forceUpdate(); From ce00c57f42d40c6672a1d728f3a8ba1e7847482a Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 21 May 2020 22:34:54 -0400 Subject: [PATCH 6/6] test fixes --- test/plugin.spec.tsx | 8 ++++---- test/proposal.spec.tsx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/plugin.spec.tsx b/test/plugin.spec.tsx index ca1c4b4..25c890a 100644 --- a/test/plugin.spec.tsx +++ b/test/plugin.spec.tsx @@ -9,13 +9,13 @@ import { import { Arc, ArcConfig, PluginData, Plugin, Plugins } from "../src"; const arcConfig = new ArcConfig("private"); +const pluginId = + "0x3687cd051fa5d1da87b25fe33a68bedfbe70f57a781336b48392e4b0fa93f4ce"; describe("Plugin component ", () => { afterEach(() => cleanup()); it("Shows plugin name", async () => { - const pluginId = - "0x3687cd051fa5d1da87b25fe33a68bedfbe70f57a781336b48392e4b0fa93f4ce"; const { container } = render( @@ -57,10 +57,10 @@ describe("Plugin List", () => { const { findAllByText, queryAllByTestId, findByText } = render( ); - await waitFor(() => findByText(/Plugin id:/), { + await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 20000, }); - await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { + await waitFor(() => findByText(`Plugin id: ${pluginId}`), { timeout: 20000, }); const plugins = await findAllByText(/Plugin id:/); diff --git a/test/proposal.spec.tsx b/test/proposal.spec.tsx index a0b480b..9ce1da5 100644 --- a/test/proposal.spec.tsx +++ b/test/proposal.spec.tsx @@ -65,10 +65,10 @@ describe("Proposal List", () => { const { findAllByText, queryAllByTestId, findByText } = render( ); - await waitFor(() => findByText(/Proposal id/), { + await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { timeout: 8000, }); - await waitForElementToBeRemoved(() => queryAllByTestId("default-loader"), { + await waitFor(() => findByText(`Proposal id: ${proposalId}`), { timeout: 8000, }); const proposals = await findAllByText(/Proposal id:/);