Skip to content

Commit

Permalink
Merge pull request #37 from infinitybase/FEAT/transaction-split
Browse files Browse the repository at this point in the history
Feat/transaction split
  • Loading branch information
guimroque authored Nov 20, 2023
2 parents d126ae5 + 43085b7 commit cffab91
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/modules/dApps/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export class DappController {
}
}

async current({ params }: IDappRequest) {
try {
const currentVaultId = await this._dappService.findCurrent(params.sessionId);
return successful(currentVaultId, Responses.Ok);
} catch (e) {
return error(e.error, e.statusCode);
}
}

async accounts({ params, headers }: IDappRequest) {
try {
return successful(
Expand Down
5 changes: 4 additions & 1 deletion src/modules/dApps/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { DAppsService } from './service';

const router = Router();
const dAppService = new DAppsService();
const { currentAccount, accounts, state } = new DappController(dAppService);
const { currentAccount, current, accounts, state } = new DappController(
dAppService,
);

router.get('/:sessionId/state', handleResponse(state));
router.get('/:sessionId/accounts', handleResponse(accounts));
router.get('/:sessionId/currentAccount', handleResponse(currentAccount));
router.get('/:sessionId', handleResponse(current));

export default router;
17 changes: 17 additions & 0 deletions src/modules/dApps/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ export class DAppsService implements IDAppsService {
});
}

async findCurrent(sessionID: string) {
return await DApp.createQueryBuilder('d')
.select()
.innerJoin('d.currentVault', 'currentVault')
.addSelect(['currentVault.predicateAddress', 'currentVault.id'])
.where('d.session_id = :sessionID', { sessionID })
.getOne()
.then(data => data?.currentVault.id ?? undefined)
.catch(e => {
throw new Internal({
type: ErrorTypes.Internal,
title: 'Error on find current to dapp',
detail: e,
});
});
}

// async checkExist(address: string, sessionId, url: string) {
// return await DApp.createQueryBuilder('d')
// .innerJoin('d.users', 'users')
Expand Down
1 change: 1 addition & 0 deletions src/modules/dApps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IDappFilterParams {
export interface IDAppsService {
create: (payload: IDAPPCreatePayload) => Promise<DApp>;
findBySessionID: (sessionID: string, origin: string) => Promise<DApp>;
findCurrent: (sessionID: string) => Promise<string>;
}

interface IDappRequestSchema extends ValidatedRequestSchema {
Expand Down
6 changes: 3 additions & 3 deletions src/socket/calbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const popAuth: IEventsExecute = {
const isIncludedVault = dapp.vaults.find(v => v.id === vaultId);
if (!isIncludedVault) {
dapp.vaults = [...dapp.vaults, predicate];
dapp.currentVault = predicate;

await dapp.save();
}

dapp.currentVault = predicate;
await dapp.save();

socket.to(room).emit(SocketEvents.DEFAULT, {
type: SocketEvents.CONNECTION,
data: [true],
Expand Down

0 comments on commit cffab91

Please sign in to comment.