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

feat: Add name to main identity #972

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion src/mappings/identity/calls/setSubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ export async function setSubs(

const subIdentities = await ctx.store.find(Identity, {
where: { super: { id: signer.id } },
relations: {
info: true,
},
})

await Promise.all(
subIdentities.map(async (sub) => {
if (sub.isSub) return ctx.store.remove(sub)
sub.super = null
sub.name = sub.info.display || sub.info.legal
return ctx.store.save(sub)
})
)
Expand All @@ -57,7 +61,7 @@ export async function setSubs(

if (existing) {
existing.super = new Identity({ id: signer.id })

existing.name = sub[1].__kind !== 'None' ? u8aToString(sub[1].value) : null
return existing
}

Expand Down
8 changes: 7 additions & 1 deletion src/mappings/identity/events/identityKilled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export async function identityKilled(
const eventData = getEventData(ctx, item.event)

const identity = await ctx.store.findOneOrFail(Identity, {
relations: { super: { info: true }, sub: true },
relations: {
super: { info: true },
sub: {
info: true,
},
},
where: { id: u8aToHex(eventData.who) },
})
await ctx.store.delete(Registration, { id: u8aToHex(eventData.who) })
Expand All @@ -34,6 +39,7 @@ export async function identityKilled(
identity.sub.map(async (sub) => {
if (sub.isSub) return ctx.store.remove(sub)
sub.super = null
sub.name = sub.info.display || sub.info.legal
return ctx.store.save(sub)
})
)
Expand Down
1 change: 1 addition & 0 deletions src/mappings/identity/events/identitySet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export async function identitySet(
id: account.id,
account,
isSub: false,
name: dataToValue(callData.info.display) || dataToValue(callData.info.legal),
info: registeration,
createdAt: new Date(block.timestamp),
})
Expand Down
8 changes: 7 additions & 1 deletion src/mappings/identity/events/subIdentityRemoved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ export async function subIdentityRemoved(
const eventData = getEventData(ctx, item.event)

const account = await getOrCreateAccount(ctx, eventData.sub)
const identity = await ctx.store.findOneByOrFail(Identity, { id: account.id })
const identity = await ctx.store.findOneOrFail(Identity, {
where: { id: account.id },
relations: {
info: true,
},
})

if (!identity.isSub) {
identity.super = null
identity.name = identity.info.display || identity.info.legal
await ctx.store.save(identity)
} else {
await ctx.store.remove(identity)
Expand Down
8 changes: 7 additions & 1 deletion src/mappings/identity/events/subIdentityRevoked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ export async function subIdentityRevoked(
const eventData = getEventData(ctx, item.event)

const account = await getOrCreateAccount(ctx, eventData.sub)
const identity = await ctx.store.findOneByOrFail(Identity, { id: account.id })
const identity = await ctx.store.findOneOrFail(Identity, {
where: { id: account.id },
relations: {
info: true,
},
})

if (!identity.isSub) {
identity.super = null
identity.name = identity.info.display || identity.info.legal
await ctx.store.save(identity)
} else {
await ctx.store.remove(identity)
Expand Down