-
Notifications
You must be signed in to change notification settings - Fork 1
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
Wire Manage Tokens / Edit Colony motion #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TransactionDescription } from 'ethers/lib/utils'; | ||
import { ContractEvent, motionNameMapping } from '~types'; | ||
import { getPendingMetadataDatabaseId } from '~utils'; | ||
import { createMotionInDB } from '../helpers'; | ||
|
||
export const handleEditColonyMotion = async ( | ||
event: ContractEvent, | ||
{ name }: TransactionDescription, | ||
): Promise<void> => { | ||
const { transactionHash, contractAddress: colonyAddress } = event; | ||
const pendingColonyMetadataId = getPendingMetadataDatabaseId( | ||
colonyAddress, | ||
transactionHash, | ||
); | ||
await createMotionInDB(event, { | ||
type: motionNameMapping[name], | ||
pendingColonyMetadataId, | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { BigNumber } from 'ethers'; | ||
import { TransactionDescription } from 'ethers/lib/utils'; | ||
|
||
import { ColonyOperations, MotionQuery, MotionVote, StakerReward } from '~types'; | ||
import { getDomainDatabaseId, getVotingClient, verbose } from '~utils'; | ||
import { | ||
ColonyMetadata, | ||
ColonyOperations, | ||
MotionQuery, | ||
MotionVote, | ||
StakerReward, | ||
} from '~types'; | ||
import { | ||
getColonyFromDB, | ||
getDomainDatabaseId, | ||
getExistingTokenAddresses, | ||
getVotingClient, | ||
updateColonyTokens, | ||
verbose, | ||
} from '~utils'; | ||
import networkClient from '~networkClient'; | ||
import { mutate } from '~amplifyClient'; | ||
import { query, mutate } from '~amplifyClient'; | ||
|
||
export const getStakerReward = async ( | ||
motionId: string, | ||
|
@@ -70,8 +83,15 @@ const getParsedActionFromDomainMotion = async ( | |
} | ||
}; | ||
|
||
export const linkPendingDomainMetadataWithDomain = async (action: string, colonyAddress: string, finalizedMotion: MotionQuery): Promise<void> => { | ||
const parsedDomainAction = await getParsedActionFromDomainMotion(action, colonyAddress); | ||
export const linkPendingDomainMetadataWithDomain = async ( | ||
action: string, | ||
colonyAddress: string, | ||
finalizedMotion: MotionQuery, | ||
): Promise<void> => { | ||
const parsedDomainAction = await getParsedActionFromDomainMotion( | ||
action, | ||
colonyAddress, | ||
); | ||
if (parsedDomainAction?.name === ColonyOperations.AddDomain) { | ||
const colonyClient = await networkClient.getColonyClient(colonyAddress); | ||
const domainCount = await colonyClient.getDomainCount(); | ||
|
@@ -96,3 +116,84 @@ export const linkPendingDomainMetadataWithDomain = async (action: string, colony | |
}); | ||
} | ||
}; | ||
|
||
export const linkPendingColonyMetadataWithColony = async ( | ||
pendingColonyMetadata: ColonyMetadata, | ||
colonyAddress: string, | ||
): Promise<void> => { | ||
const currentColonyMetadata = await query<ColonyMetadata>( | ||
'getColonyMetadata', | ||
{ | ||
id: colonyAddress, | ||
}, | ||
); | ||
|
||
if (!currentColonyMetadata) { | ||
console.error( | ||
`Could not find the current metadata for the colony: ${colonyAddress}. This is a bug and should be investigated.`, | ||
); | ||
return; | ||
} | ||
|
||
const { | ||
haveTokensChanged, | ||
hasAvatarChanged, | ||
hasWhitelistChanged, | ||
newDisplayName, | ||
oldDisplayName, | ||
} = pendingColonyMetadata.changelog?.[0] ?? {}; | ||
|
||
const updatedMetadata = { | ||
...currentColonyMetadata, | ||
}; | ||
|
||
/* | ||
* Here, we update metadata as granularly as possible so that we don't overwrite state changes that occured | ||
* after this motion was created. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the comment suggests, this should fix the problem of one motion overwriting the state changes of another motion that was created after it, but finalized before it is finalized. To be tested in JoinColony/colonyCDapp#433 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this works as I imagine, we can refactor how we store Domain metadata to follow the same pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if (hasAvatarChanged) { | ||
// If avatar has changed, update avatar and thumbnail | ||
updatedMetadata.avatar = pendingColonyMetadata.avatar; | ||
updatedMetadata.thumbnail = pendingColonyMetadata.thumbnail; | ||
} | ||
|
||
if (hasWhitelistChanged) { | ||
// If whitelist has changed, update whitelistedAddresses and isWhitelistActivated | ||
updatedMetadata.isWhitelistActivated = | ||
pendingColonyMetadata.isWhitelistActivated; | ||
|
||
updatedMetadata.whitelistedAddresses = | ||
pendingColonyMetadata.whitelistedAddresses; | ||
} | ||
|
||
if (newDisplayName !== oldDisplayName) { | ||
// If displayName has changed, update displayName | ||
updatedMetadata.displayName = pendingColonyMetadata.displayName; | ||
} | ||
|
||
if (haveTokensChanged && pendingColonyMetadata.modifiedTokenAddresses) { | ||
// If tokens have changed, update colony tokens | ||
const colony = await getColonyFromDB(colonyAddress); | ||
|
||
if (colony) { | ||
const existingTokenAddresses = getExistingTokenAddresses(colony); | ||
|
||
await updateColonyTokens( | ||
colony, | ||
existingTokenAddresses, | ||
pendingColonyMetadata.modifiedTokenAddresses, | ||
); | ||
} | ||
} | ||
|
||
await mutate('updateColonyMetadata', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally, we update the metadata changelog with the changes the motion introduced. |
||
input: { | ||
...updatedMetadata, | ||
changelog: [ | ||
...(currentColonyMetadata.changelog ?? []), | ||
pendingColonyMetadata.changelog?.[0], | ||
], | ||
}, | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're following the same pattern as with Domains. We attach the "pending" metadata to the action, so it can be retreived when the motion is finalized.