Skip to content

Commit

Permalink
feat(network): expose relay ping method, feat(std-client): add tx has…
Browse files Browse the repository at this point in the history
…h to action component (#209)

* feat(network): expose relay ping method

* feat: add block explorer url to config

* feat(std-client): add tx hash to action component
  • Loading branch information
alvrs authored Oct 18, 2022
1 parent 93b9603 commit 3e0b4a7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/network/src/createRelayStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ export async function createRelayStream(signer: Signer, url: string, id: string)
push$.next({ label, message });
}

return { event$, dispose, subscribe, unsubscribe, push, countConnected };
// Expose method for consumers to ping the stream to keep receiving messages without pushing
function ping() {
return httpClient.ping(signature);
}

return { event$, dispose, subscribe, unsubscribe, push, countConnected, ping };
}
1 change: 1 addition & 0 deletions packages/network/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface NetworkConfig {
snapshotServiceUrl?: string;
streamServiceUrl?: string;
initialBlockNumber?: number;
blockExplorer?: string;
}

export interface ClockConfig {
Expand Down
8 changes: 7 additions & 1 deletion packages/std-client/src/components/ActionComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { defineComponent, World, Type, Component, Metadata, SchemaOf } from "@la
export function defineActionComponent<T = undefined>(world: World) {
const Action = defineComponent(
world,
{ state: Type.Number, on: Type.OptionalEntity, metadata: Type.OptionalT, overrides: Type.OptionalStringArray },
{
state: Type.Number,
on: Type.OptionalEntity,
metadata: Type.OptionalT,
overrides: Type.OptionalStringArray,
txHash: Type.OptionalString,
},
{ id: "Action" }
);
return Action as Component<SchemaOf<typeof Action>, Metadata, T>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function createActionSystem<M = undefined>(world: World, txReduced$: Obse
on: actionRequest.on ? world.entities[actionRequest.on] : undefined,
metadata: actionRequest.metadata,
overrides: undefined,
txHash: undefined,
});

// Add components that are not tracked yet to internal overridable component map.
Expand Down Expand Up @@ -160,7 +161,7 @@ export function createActionSystem<M = undefined>(world: World, txReduced$: Obse
// If the result includes a hash key (single tx) or hashes (multiple tx) key, wait for the transactions to complete before removing the pending actions
if (tx) {
// Wait for all tx events to be reduced
updateComponent(Action, action.entityIndex, { state: ActionState.WaitingForTxEvents });
updateComponent(Action, action.entityIndex, { state: ActionState.WaitingForTxEvents, txHash: tx.hash });
const txConfirmed = tx.wait().catch(() => handleError(action)); // Also catch the error if not awaiting
await awaitStreamValue(txReduced$, (v) => v === tx.hash);
updateComponent(Action, action.entityIndex, { state: ActionState.TxReduced });
Expand Down

0 comments on commit 3e0b4a7

Please sign in to comment.