From 8ed8719a51d285d7a78ef28c9a91fef93ac97a7d Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Mon, 2 Aug 2021 13:59:32 +0300 Subject: [PATCH] Add stream endpoint. Add filters. --- backend/moonstream/api.py | 4 +- backend/moonstream/data.py | 19 ++++- frontend/src/components/EntriesNavigation.js | 82 +++++++++++++++---- frontend/src/components/StreamEntry.js | 14 +--- .../core/services/subscriptions.service.js | 2 +- 5 files changed, 89 insertions(+), 32 deletions(-) diff --git a/backend/moonstream/api.py b/backend/moonstream/api.py index 412e3834..60429dec 100644 --- a/backend/moonstream/api.py +++ b/backend/moonstream/api.py @@ -10,6 +10,8 @@ from . import data from .routes.subscriptions import app as subscriptions_api from .routes.users import app as users_api from .routes.txinfo import app as txinfo_api +from .routes.streams import app as streams_api + from .settings import ORIGINS from .version import MOONSTREAM_VERSION @@ -39,4 +41,4 @@ async def version_handler() -> data.VersionResponse: app.mount("/subscriptions", subscriptions_api) app.mount("/users", users_api) -app.mount("/txinfo", txinfo_api) +app.mount("/streams", streams_api) diff --git a/backend/moonstream/data.py b/backend/moonstream/data.py index f11f338c..3e00db3c 100644 --- a/backend/moonstream/data.py +++ b/backend/moonstream/data.py @@ -70,7 +70,7 @@ class SubscriptionResponse(BaseModel): class SubscriptionsListResponse(BaseModel): - subscriptions: List[SubscriptionResponse] = Field(default_factory=list) + subscriptions: List[SubscriptionResourceData] = Field(default_factory=list) class EVMFunctionSignature(BaseModel): @@ -100,6 +100,22 @@ class EthereumTransaction(BaseModel): input: Optional[str] = None +class EthereumTransactionItem(BaseModel): + from_label: Optional[str] = "from_label" + to_label: Optional[str] = "to_label" + gas: int + gasPrice: int + value: int + from_address: Optional[str] # = Field(alias="from") + to_address: Optional[str] # = Field(default=None, alias="to") + hash: Optional[str] = None + input: Optional[str] = None + + +class EthereumTransactionResponse(BaseModel): + stream: List[EthereumTransactionItem] + + class TxinfoEthereumBlockchainRequest(BaseModel): tx: EthereumTransaction @@ -108,4 +124,3 @@ class TxinfoEthereumBlockchainResponse(BaseModel): tx: EthereumTransaction abi: Optional[ContractABI] = None errors: List[str] = Field(default_factory=list) - diff --git a/frontend/src/components/EntriesNavigation.js b/frontend/src/components/EntriesNavigation.js index c3f627e9..bbb3a73a 100644 --- a/frontend/src/components/EntriesNavigation.js +++ b/frontend/src/components/EntriesNavigation.js @@ -42,7 +42,7 @@ const FILTER_TYPES = { HASH: 4, DISABLED: 99, }; -const DIRECTIONS = { SOURCE: 0, DESTINATION: 1 }; +const DIRECTIONS = { SOURCE: "from", DESTINATION: "to" }; const CONDITION = { EQUAL: 0, CONTAINS: 1, @@ -68,10 +68,11 @@ const EntriesNavigation = () => { const [filterState, setFilterState] = useState([]); const setNewFilterState = (props) => { + console.log(subscriptionsCache.data.subscriptions); console.log( "setNewFilterState", props, - subscriptionsCache.data.subscriptions[0].id + subscriptionsCache.data.subscriptions[0].address ); _setNewFilterState(props); }; @@ -126,20 +127,44 @@ const EntriesNavigation = () => { const canDelete = false; const dropNewFilterArrayItem = (idx) => { - const newArray = [...newFilterState]; - delete newArray[idx]; + const oldArray = [...newFilterState]; + + const newArray = oldArray.filter(function (ele) { + return ele != oldArray[idx]; + }); + console.log(newFilterState); + console.log(newArray); setNewFilterState(newArray); }; const dropFilterArrayItem = (idx) => { console.log("dropFilterArrayItem", idx, filterState); - const newArray = [...filterState]; - newArray[idx].type = FILTER_TYPES.DISABLED; + const oldArray = [...filterState]; + //newArray[idx].type = FILTER_TYPES.DISABLED; + const newArray = oldArray.filter(function (ele) { + return ele != oldArray[idx]; + }); + setFilterState(newArray); + setNewFilterState(newArray); + ui.setSearchTerm( + newArray + .map((filter) => { + return filter.direction + ":" + filter.value; + }) + .join("+") + ); }; const handleFilterSubmit = () => { setFilterState(newFilterState); + ui.setSearchTerm( + newFilterState + .map((filter) => { + return filter.direction + ":" + filter.value; + }) + .join("+") + ); onClose(); }; @@ -159,7 +184,7 @@ const EntriesNavigation = () => { setFilterState(newFilterState); }; if (subscriptionsCache.isLoading) return ""; - console.log("filterstate test", filterState); + return ( { Source: {newFilterState.map((filter, idx) => { + console.log("197", newFilterState); if (filter.type === FILTER_TYPES.DISABLED) return ""; return ( { )} {filter.direction === DIRECTIONS.DESTINATION && ( - - setFilterProps(idx, { - value: e.target.value, - }) - } - placeholder="Type in address" - /> + )} )} @@ -284,7 +328,8 @@ const EntriesNavigation = () => { type: FILTER_TYPES.ADDRESS, direction: DIRECTIONS.SOURCE, condition: CONDITION.EQUAL, - value: subscriptionsCache.data.subscriptions[0].id, + value: + subscriptionsCache.data.subscriptions[0].address, }, ]) } @@ -299,7 +344,8 @@ const EntriesNavigation = () => { type: FILTER_TYPES.ADDRESS, direction: DIRECTIONS.DESTINATION, condition: CONDITION.EQUAL, - value: null, + value: + subscriptionsCache.data.subscriptions[0].address, }, ]) } diff --git a/frontend/src/components/StreamEntry.js b/frontend/src/components/StreamEntry.js index cf3f7886..f1c9fe0c 100644 --- a/frontend/src/components/StreamEntry.js +++ b/frontend/src/components/StreamEntry.js @@ -48,16 +48,13 @@ const StreamEntry = ({ entry, filterCallback, filterConstants }) => { filterCallback({ direction: filterConstants.DIRECTIONS.SOURCE, type: filterConstants.FILTER_TYPES.ADDRESS, - value: entry.from, + value: entry.from_address, conditon: filterConstants.CONDITION.EQUAL, }) } > {"From:"} - {`${entry.from_label} - ${entry.from.slice( - 0, - 5 - )}...${entry.from.slice(-3, -1)}`} + {`${entry.from_label} - ${entry.from_address}`} {" "} { filterCallback({ direction: filterConstants.DIRECTIONS.DESTINATION, type: filterConstants.FILTER_TYPES.ADDRESS, - value: entry.to, + value: entry.to_address, conditon: filterConstants.CONDITION.EQUAL, }) } > {"To:"} - {`${entry.to_label} - ${entry.to.slice(0, 5)}...${entry.to.slice( - -3, - -1 - )}`} + {`${entry.to_label} - ${entry.to_address}`} {" "} Gas Price: {entry.gasPrice} diff --git a/frontend/src/core/services/subscriptions.service.js b/frontend/src/core/services/subscriptions.service.js index 62950c63..118b0956 100644 --- a/frontend/src/core/services/subscriptions.service.js +++ b/frontend/src/core/services/subscriptions.service.js @@ -6,7 +6,7 @@ const API = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL; export const getStream = ({ searchTerm, limit, offset, isContent }) => http({ method: "GET", - url: `${API}/stream`, + url: `${API}/streams/`, params: { q: searchTerm, limit: encodeURIComponent(limit),