Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Oct 21, 2021
1 parent 873e2b0 commit 1cb730d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 42 deletions.
29 changes: 17 additions & 12 deletions src/event-stream/event-stream.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
Event,
EventStream,
EventStreamReply,
EventStreamSubscription
EventStreamSubscription,
} from './event-stream.interfaces';

const RECONNECT_TIME = 5000;
Expand Down Expand Up @@ -144,17 +144,20 @@ export class EventStreamService {
inputs: true,
};

const existingStreamRes = await lastValueFrom(this.http
.get<EventStream[]>(`${baseUrl}/eventstreams`));
const existingStreamRes = await lastValueFrom(
this.http.get<EventStream[]>(`${baseUrl}/eventstreams`),
);
const stream = existingStreamRes.data.find(s => s.name === streamDetails.name);
if (stream) {
const patchedStreamRes = await lastValueFrom(this.http
.patch<EventStream>(`${baseUrl}/eventstreams/${stream.id}`, streamDetails));
const patchedStreamRes = await lastValueFrom(
this.http.patch<EventStream>(`${baseUrl}/eventstreams/${stream.id}`, streamDetails),
);
this.logger.log(`Event stream for ${topic}: ${stream.id}`);
return patchedStreamRes.data;
}
const newStreamRes = await lastValueFrom(this.http
.post<EventStream>(`${baseUrl}/eventstreams`, streamDetails));
const newStreamRes = await lastValueFrom(
this.http.post<EventStream>(`${baseUrl}/eventstreams`, streamDetails),
);
this.logger.log(`Event stream for ${topic}: ${newStreamRes.data.id}`);
return newStreamRes.data;
}
Expand All @@ -164,13 +167,14 @@ export class EventStreamService {
event: string,
streamId: string,
): Promise<EventStreamSubscription> {
const response = await lastValueFrom(this.http
.post<EventStreamSubscription>(`${instanceUrl}/${event}`, {
const response = await lastValueFrom(
this.http.post<EventStreamSubscription>(`${instanceUrl}/${event}`, {
name: event,
description: event,
stream: streamId,
fromBlock: '0', // subscribe from the start of the chain
}));
}),
);
this.logger.log(`Created subscription ${event}: ${response.data.id}`);
return response.data;
}
Expand All @@ -181,8 +185,9 @@ export class EventStreamService {
streamId: string,
subscriptions: string[],
): Promise<EventStreamSubscription[]> {
const existingRes = await lastValueFrom(this.http
.get<EventStreamSubscription[]>(`${baseUrl}/subscriptions`));
const existingRes = await lastValueFrom(
this.http.get<EventStreamSubscription[]>(`${baseUrl}/subscriptions`),
);
const results: EventStreamSubscription[] = [];
for (const eventName of subscriptions) {
const sub = existingRes.data.find(s => s.name === eventName && s.stream === streamId);
Expand Down
51 changes: 29 additions & 22 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
TokenTransfer,
TokenTransferEvent,
TokenType,
TransferSingleEvent
TransferSingleEvent,
} from './tokens.interfaces';
import { decodeHex, encodeHex, isFungible, packTokenId, unpackTokenId } from './tokens.util';

Expand Down Expand Up @@ -79,12 +79,13 @@ export class TokensService {
}

async getReceipt(id: string): Promise<EventStreamReply> {
const response = await lastValueFrom(this.http
.get<EventStreamReply>(`${this.baseUrl}/reply/${id}`, {
const response = await lastValueFrom(
this.http.get<EventStreamReply>(`${this.baseUrl}/reply/${id}`, {
validateStatus: status => {
return status < 300 || status === 404;
},
}));
}),
);
if (response.status === 404) {
throw new NotFoundException();
}
Expand All @@ -96,15 +97,16 @@ export class TokensService {
trackingId: dto.trackingId,
data: dto.data, // TODO: remove
};
const response = await lastValueFrom(this.http
.post<EthConnectAsyncResponse>(
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
`${this.instanceUrl}/create`,
{
is_fungible: dto.type === TokenType.FUNGIBLE,
data: encodeHex(JSON.stringify(dataToPack)),
},
this.postOptions(dto.requestId),
));
),
);
return { id: response.data.id };
}

Expand All @@ -115,8 +117,8 @@ export class TokensService {
data: dto.data,
};
if (isFungible(dto.poolId)) {
const response = await lastValueFrom(this.http
.post<EthConnectAsyncResponse>(
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
`${this.instanceUrl}/mintFungible`,
{
type_id: typeId,
Expand All @@ -125,7 +127,8 @@ export class TokensService {
data: encodeHex(JSON.stringify(dataToPack)),
},
this.postOptions(dto.requestId),
));
),
);
return { id: response.data.id };
} else {
// In the case of a non-fungible token:
Expand All @@ -137,16 +140,17 @@ export class TokensService {
to.push(dto.to);
}

const response = await lastValueFrom(this.http
.post<EthConnectAsyncResponse>(
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
`${this.instanceUrl}/mintNonFungible`,
{
type_id: typeId,
to,
data: encodeHex(JSON.stringify(dataToPack)),
},
this.postOptions(dto.requestId),
));
),
);
return { id: response.data.id };
}
}
Expand All @@ -156,8 +160,8 @@ export class TokensService {
trackingId: dto.trackingId,
data: dto.data,
};
const response = await lastValueFrom(this.http
.post<EthConnectAsyncResponse>(
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
`${this.instanceUrl}/safeTransferFrom`,
{
from: dto.from,
Expand All @@ -167,7 +171,8 @@ export class TokensService {
data: encodeHex(JSON.stringify(dataToPack)),
},
this.postOptions(dto.requestId),
));
),
);
return { id: response.data.id };
}

Expand All @@ -176,8 +181,8 @@ export class TokensService {
trackingId: dto.trackingId,
data: dto.data,
};
const response = await lastValueFrom(this.http
.post<EthConnectAsyncResponse>(
const response = await lastValueFrom(
this.http.post<EthConnectAsyncResponse>(
`${this.instanceUrl}/burn`,
{
from: dto.from,
Expand All @@ -186,18 +191,20 @@ export class TokensService {
data: encodeHex(JSON.stringify(dataToPack)),
},
this.postOptions(dto.requestId),
));
),
);
return { id: response.data.id };
}

async balance(dto: TokenBalanceQuery): Promise<TokenBalance> {
const response = await lastValueFrom(this.http
.get<EthConnectReturn>(`${this.instanceUrl}/balanceOf`, {
const response = await lastValueFrom(
this.http.get<EthConnectReturn>(`${this.instanceUrl}/balanceOf`, {
params: {
account: dto.account,
id: packTokenId(dto.poolId, dto.tokenIndex),
},
}));
}),
);
return { balance: response.data.output };
}
}
Expand Down
17 changes: 9 additions & 8 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
TokenTransfer,
TokenTransferEvent,
TokenType,
TransferSingleEvent
TransferSingleEvent,
} from '../src/tokens/tokens.interfaces';
import { TokensService } from '../src/tokens/tokens.service';
import { WebSocketMessage } from '../src/websocket-events/websocket-events.base';
Expand All @@ -66,13 +66,14 @@ class FakeObservable<T> {
constructor(public data: T) {}

subscribe(observer?: Partial<Observer<AxiosResponse<T>>>) {
observer?.next && observer?.next({
status: 200,
statusText: 'OK',
headers: {},
config: {},
data: this.data,
});
observer?.next &&
observer?.next({
status: 200,
statusText: 'OK',
headers: {},
config: {},
data: this.data,
});
observer?.complete && observer?.complete();
}
}
Expand Down

0 comments on commit 1cb730d

Please sign in to comment.