Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): basic record to mark restore as complete #888

Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8a68d4
feat: basic record to mark restore as complete
Sotatek-TungNguyen2a Dec 13, 2024
7e210dc
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
Sotatek-TungNguyen2a Dec 13, 2024
b7d4337
feat: mark done when finished recovering in the DB
Sotatek-TungNguyen2a Dec 13, 2024
9bca87c
feat: update unittest
Sotatek-TungNguyen2a Dec 13, 2024
14fe07d
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
Sotatek-TungNguyen2a Dec 16, 2024
b88048a
update: resolve comment
Sotatek-TungNguyen2a Dec 16, 2024
d6262a9
update: update unit test
Sotatek-TungNguyen2a Dec 16, 2024
db6fb03
feat: resolve comment
Sotatek-TungNguyen2a Dec 18, 2024
8dccd3f
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
Sotatek-TungNguyen2a Dec 19, 2024
fd8b348
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
Sotatek-TungNguyen2a Dec 19, 2024
d382f5e
feat: resolve comment
Sotatek-TungNguyen2a Dec 19, 2024
17411f0
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
Sotatek-TungNguyen2a Dec 19, 2024
7575554
feat: resolve comment
Sotatek-TungNguyen2a Dec 19, 2024
200fe37
feat: call loadDatabase() after syncWithKeria and before startup app
Sotatek-TungNguyen2a Dec 19, 2024
e1f500a
feat: remove unused import
Sotatek-TungNguyen2a Dec 19, 2024
e65967f
Merge branch 'develop' into feat/DTIS-1540-basic-record-to-mark-resto…
Sotatek-TungNguyen2a Dec 30, 2024
0223f74
update: remove unnecessary event references and resolve comment
Sotatek-TungNguyen2a Dec 30, 2024
21250b5
update: separate to set agent to online in AppWrapper
Sotatek-TungNguyen2a Dec 31, 2024
3505610
update: remove decorator check online when syncing keria
Sotatek-TungNguyen2a Dec 31, 2024
f9314f8
update: add the pagination for sync methods
Sotatek-TungNguyen2a Dec 31, 2024
976c2f7
fix(core): fix connection handling and pagination while syncing ident…
iFergal Jan 2, 2025
684d6e5
Merge remote-tracking branch 'origin/develop' into feat/DTIS-1540-bas…
iFergal Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: resolve comment
  • Loading branch information
Sotatek-TungNguyen2a committed Dec 16, 2024
commit b88048a468542be74c6163922a95cf58a2c33738
2 changes: 1 addition & 1 deletion src/core/agent/agent.test.ts
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ describe("test cases of recoverKeriaAgent function", () => {
_tags: {},
content: { value: false },
createdAt: now,
id: MiscRecordId.PROCESS_RECOVERING,
id: MiscRecordId.CLOUD_RECOVERY_STATUS,
type: "BasicRecord",
updatedAt: undefined,
});
14 changes: 7 additions & 7 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
@@ -296,11 +296,6 @@ class Agent {
this.agentServicesProps.signifyClient = this.signifyClient;
await this.connectSignifyClient();

await this.basicStorage.save({
id: MiscRecordId.PROCESS_RECOVERING,
content: { value: true },
});

await SecureStorage.set(KeyStoreKeys.SIGNIFY_BRAN, bran);
await this.saveAgentUrls({
url: connectUrl,
@@ -312,14 +307,19 @@ class Agent {
}

async syncWithKeria() {
await this.basicStorage.save({
id: MiscRecordId.CLOUD_RECOVERY_STATUS,
content: { syncing: true },
});

await this.connections.syncKeriaContacts();
await this.identifiers.syncKeriaIdentifiers();
await this.credentials.syncACDCs();

await this.basicStorage.update(
new BasicRecord({
id: MiscRecordId.PROCESS_RECOVERING,
content: { value: false },
id: MiscRecordId.CLOUD_RECOVERY_STATUS,
content: { syncing: false },
})
);
}
2 changes: 1 addition & 1 deletion src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ enum MiscRecordId {
LOGIN_METADATA = "login-metadata",
CAMERA_DIRECTION = "camera-direction",
FAILED_NOTIFICATIONS = "failed-notifications",
PROCESS_RECOVERING = "process-recovering",
CLOUD_RECOVERY_STATUS = "cloud-recovery-status",
}

interface ConnectionShortDetails {
1 change: 0 additions & 1 deletion src/core/agent/services/connectionService.test.ts
Original file line number Diff line number Diff line change
@@ -544,7 +544,6 @@ describe("Connection service of agent", () => {
connectionStorage.getAll = jest.fn().mockReturnValue([]);
await connectionService.syncKeriaContacts();
expect(connectionStorage.save).toBeCalledTimes(2);
expect(eventEmitter.emit).toBeCalledTimes(2);
});

test("Can get multisig linked contacts", async () => {
21 changes: 0 additions & 21 deletions src/core/agent/services/connectionService.ts
Original file line number Diff line number Diff line change
@@ -168,17 +168,6 @@ class ConnectionService extends AgentService {
}
await this.createConnectionMetadata(connectionId, connectionMetadata);
} else {
this.props.eventEmitter.emit<ConnectionStateChangedEvent>({
type: EventTypes.ConnectionStateChanged,
payload: {
isMultiSigInvite: false,
connectionId,
status: ConnectionStatus.PENDING,
url,
label: alias,
},
});

await this.createConnectionMetadata(connectionId, connectionMetadata);
}
return { type: KeriConnectionType.NORMAL, connection };
@@ -444,16 +433,6 @@ class ConnectionService extends AgentService {
groupId: contact.groupCreationId,
createdAtUTC: contact.createdAt,
});

this.props.eventEmitter.emit<ConnectionStateChangedEvent>({
type: EventTypes.ConnectionStateChanged,
payload: {
connectionId: contact.id,
status: ConnectionStatus.CONFIRMED,
url: contact.oobi,
label: contact.alias,
},
});
}
}
}
8 changes: 0 additions & 8 deletions src/core/agent/services/credentialService.ts
Original file line number Diff line number Diff line change
@@ -196,14 +196,6 @@ class CredentialService extends AgentService {
};

await this.createMetadata(metadata);

this.props.eventEmitter.emit<AcdcStateChangedEvent>({
type: EventTypes.AcdcStateChanged,
payload: {
status: CredentialStatus.CONFIRMED,
credential: metadata,
},
});
} catch (error) {
/* eslint-disable no-console */
console.error(error);
49 changes: 0 additions & 49 deletions src/core/agent/services/identifierService.test.ts
Original file line number Diff line number Diff line change
@@ -708,24 +708,6 @@ describe("Single sig service of agent", () => {
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});

expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.IdentifierStateChanged,
payload: {
identifier: {
id: "EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
displayName: "1-group1",
groupMetadata: {
groupId: "1-group1",
groupCreated: false,
groupInitiator: true,
},
theme: 0,
isPending: false,
createdAtUTC: expect.any(String),
},
},
});

expect(
identifierStorage.createIdentifierMetadataRecord
).toHaveBeenCalledWith({
@@ -736,19 +718,6 @@ describe("Single sig service of agent", () => {
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});

expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.IdentifierStateChanged,
payload: {
identifier: {
id: "EJ9oenRW3_SNc0JkETnOegspNGaDCypBfTU1kJiL2AMs",
displayName: "test2",
theme: 33,
isPending: false,
createdAtUTC: expect.any(String),
},
},
});

// sync data of group record
expect(identifierStorage.updateIdentifierMetadata).toHaveBeenCalledWith(
"EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
@@ -771,24 +740,6 @@ describe("Single sig service of agent", () => {
isPending: false,
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});

expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.IdentifierStateChanged,
payload: {
identifier: {
id: "EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
displayName: "1-group1",
theme: 0,
groupMetadata: {
groupId: "1-group1",
groupCreated: false,
groupInitiator: true,
},
isPending: false,
createdAtUTC: expect.any(String),
},
},
});
});

test("should call signify.rotateIdentifier with correct params", async () => {
63 changes: 20 additions & 43 deletions src/core/agent/services/identifierService.ts
Original file line number Diff line number Diff line change
@@ -193,7 +193,9 @@ class IdentifierService extends AgentService {
const identifier = operation.serder.ked.i;

// @TODO - foconnor: Need update HabState interface on signify.
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };
const identifierDetail = (await this.props.signifyClient
.identifiers()
.get(identifier)) as HabState & { icp_dt: string };

const addRoleOperation = await this.props.signifyClient
.identifiers()
@@ -222,9 +224,13 @@ class IdentifierService extends AgentService {
id: identifier,
...metadata,
isPending: !op.done,
createdAt: new Date(identifierDetail.icp_dt)
createdAt: new Date(identifierDetail.icp_dt),
});
return { identifier, isPending: !op.done, createdAt: identifierDetail.icp_dt };
return {
identifier,
isPending: !op.done,
createdAt: identifierDetail.icp_dt,
};
}

async deleteIdentifier(identifier: string): Promise<void> {
@@ -405,41 +411,24 @@ class IdentifierService extends AgentService {
const name = identifier.name.split(":");
const theme = parseInt(name[0], 10);
const isMultiSig = name.length === 3;
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };

const identifierDetail = (await this.props.signifyClient
.identifiers()
.get(identifier.prefix)) as HabState & { icp_dt: string };
if (isMultiSig) {
const groupId = identifier.name.split(":")[1];
const groupInitiator = groupId.split("-")[0] === "1";

await this.identifierStorage.createIdentifierMetadataRecord({
id: identifier.prefix,
displayName: groupId,
displayName: identifier.name.split(":")[1],
theme,
groupMetadata: {
groupId,
groupCreated: false,
groupInitiator,
},
isPending,
createdAt: new Date(identifierDetail.icp_dt)
});

this.props.eventEmitter.emit<IdentifierStateChangedEvent>({
type: EventTypes.IdentifierStateChanged,
payload: {
identifier: {
id: identifier.prefix,
displayName: groupId,
theme,
groupMetadata: {
groupId,
groupCreated: false,
groupInitiator,
},
isPending,
createdAtUTC: new Date().toISOString(),
},
},
createdAt: new Date(identifierDetail.icp_dt),
});
continue;
}
@@ -449,20 +438,7 @@ class IdentifierService extends AgentService {
displayName: identifier.name.split(":")[1],
theme,
isPending,
createdAt: new Date(identifierDetail.icp_dt)
});

this.props.eventEmitter.emit<IdentifierStateChangedEvent>({
type: EventTypes.IdentifierStateChanged,
payload: {
identifier: {
id: identifier.prefix,
displayName: identifier.name.split(":")[1],
theme,
isPending,
createdAtUTC: new Date().toISOString(),
},
},
createdAt: new Date(identifierDetail.icp_dt),
});
}

@@ -479,7 +455,9 @@ class IdentifierService extends AgentService {
.operations()
.get(`group.${identifier.prefix}`);
const isPending = !op.done;
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };
const identifierDetail = (await this.props.signifyClient
.identifiers()
.get(identifier)) as HabState & { icp_dt: string };

if (isPending) {
const pendingOperation = await this.operationPendingStorage.save({
@@ -506,9 +484,8 @@ class IdentifierService extends AgentService {
theme,
multisigManageAid,
isPending,
createdAt: new Date(identifierDetail.icp_dt
)
})
createdAt: new Date(identifierDetail.icp_dt),
});
}
}

3 changes: 1 addition & 2 deletions src/ui/App.test.tsx
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ jest.mock("../core/agent/agent", () => ({
identifiers: {
getIdentifiers: jest.fn().mockResolvedValue([]),
syncKeriaIdentifiers: jest.fn(),
onIdentifierStateChanged: jest.fn(),
},
connections: {
getConnections: jest.fn().mockResolvedValue([]),
@@ -134,7 +133,7 @@ const addKeyboardEventMock = jest.fn();
jest.mock("@capacitor/keyboard", () => ({
Keyboard: {
addListener: (...params: any[]) => addKeyboardEventMock(...params),
hide: jest.fn()
hide: jest.fn(),
},
}));

1 change: 0 additions & 1 deletion src/ui/components/AppWrapper/AppWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -64,7 +64,6 @@ jest.mock("../../../core/agent/agent", () => ({
identifiers: {
getIdentifiers: jest.fn().mockResolvedValue([]),
syncKeriaIdentifiers: jest.fn(),
onIdentifierStateChanged: jest.fn(),
},
multiSigs: {
getMultisigIcpDetails: jest.fn().mockResolvedValue({}),
22 changes: 9 additions & 13 deletions src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
@@ -123,15 +123,6 @@ const acdcChangeHandler = async (
}
};

const identifierChangeHandler = async (
event: IdentifierStateChangedEvent,
dispatch: ReturnType<typeof useAppDispatch>
) => {
const identifierRecord = event.payload.identifier;

dispatch(updateOrAddIdentifiersCache(identifierRecord));
};

const peerConnectRequestSignChangeHandler = async (
event: PeerConnectSigningEvent,
dispatch: ReturnType<typeof useAppDispatch>
@@ -500,10 +491,6 @@ const AppWrapper = (props: { children: ReactNode }) => {
Agent.agent.keriaNotifications.onRemoveNotification((event) => {
notificatiStateChanged(event, dispatch);
});

Agent.agent.identifiers.onIdentifierStateChanged((event) => {
identifierChangeHandler(event, dispatch);
});
};

const initApp = async () => {
@@ -534,6 +521,15 @@ const AppWrapper = (props: { children: ReactNode }) => {

if (keriaConnectUrlRecord) {
try {
if (keriaConnectUrlRecord?.content?.url) {
const recoveryStatus = await Agent.agent.basicStorage.findById(
MiscRecordId.CLOUD_RECOVERY_STATUS
);
if (recoveryStatus?.content?.syncing) {
Agent.agent.syncWithKeria();
}
}

await Agent.agent.start(keriaConnectUrlRecord.content.url as string);
} catch (e) {
const errorMessage = (e as Error).message;
Loading