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

Track colony versions in the database #163

Merged
merged 12 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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: 4 additions & 2 deletions amplify/backend/api/colonycdapp/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ input CreateUniqueColonyInput {
type: ColonyType
status: ColonyStatusInput
meta: MetadataInput
version: Int!
}

input ProfileInput {
Expand Down Expand Up @@ -82,7 +83,7 @@ input UpdateExtensionByColonyAndHashInput {
}

input SetCurrentVersionInput {
item: String!
key: String!
version: Int!
}

Expand Down Expand Up @@ -224,6 +225,7 @@ type Colony @model {
balances: ColonyBalances @function(name: "fetchColonyBalances")
meta: Metadata
extensions: [ColonyExtension!] @hasMany(indexName: "byColony", fields: ["id"])
version: Int!
}

type User @model {
Expand Down Expand Up @@ -331,6 +333,6 @@ type ColonyExtension @model {

type CurrentVersion @model {
id: ID!
item: String! @index(name: "byItem", queryField: "getCurrentVersionByItem")
key: String! @index(name: "byKey", queryField: "getCurrentVersionByKey")
version: Int!
}
2 changes: 2 additions & 0 deletions amplify/backend/function/createUniqueColony/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.handler = async (event) => {
profile,
colonyNativeTokenId,
type = 'COLONY',
version,
} = event.arguments?.input || {};

/*
Expand Down Expand Up @@ -140,6 +141,7 @@ exports.handler = async (event) => {
chainId: 2656691,
network: 'GANACHE',
},
version,
},
},
GRAPHQL_URI,
Expand Down
4 changes: 2 additions & 2 deletions amplify/backend/function/setCurrentVersion/src/graphql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
getCurrentVersion: /* GraphQL */ `
query GetCurrentVersion($item: CurrentVersionItem!) {
getCurrentVersionByItem(item: $item) {
query GetCurrentVersion($key: String!) {
getCurrentVersionByKey(key: $key) {
items {
id
}
Expand Down
8 changes: 4 additions & 4 deletions amplify/backend/function/setCurrentVersion/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const GRAPHQL_URI = 'http://localhost:20002/graphql';
* @type {import('@types/aws-lambda').APIGatewayProxyHandler}
*/
exports.handler = async (event) => {
const { item, version } = event.arguments?.input || {};
const { key, version } = event.arguments?.input || {};

const getCurrentVersionData = await graphqlRequest(
getCurrentVersion,
{
item,
key,
},
GRAPHQL_URI,
API_KEY,
);

const existingEntryId =
getCurrentVersionData?.data?.getCurrentVersionByItem?.items?.[0]?.id;
getCurrentVersionData?.data?.getCurrentVersionByKey?.items?.[0]?.id;

if (existingEntryId) {
const updateCurrentVersionData = await graphqlRequest(
Expand All @@ -51,7 +51,7 @@ exports.handler = async (event) => {
createCurrentVersion,
{
input: {
item,
key,
version,
},
},
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"homepage": "https://colony.io",
"devDependencies": {
"@aws-amplify/cli": "^10.2.1",
"@aws-amplify/cli": "^10.6.1",
"@babel/core": "^7.13.10",
"@babel/node": "^7.13.10",
"@babel/preset-env": "^7.13.10",
Expand Down
8 changes: 5 additions & 3 deletions scripts/temp-create-data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { utils, Wallet, Contract, ContractFactory, providers } = require('ethers');
const { utils, Wallet, Contract, ContractFactory, providers, BigNumber } = require('ethers');

const colonyJSExtras = require('@colony/colony-js/extras')
const colonyJSIColony = require('../node_modules/@colony/colony-js/dist/cjs/contracts/IColony/9/factories/IColony__factory.js')
const { addAugmentsB } = require('../node_modules/@colony/colony-js/dist/cjs/clients/Core/augments/AddDomain.js');
const { getExtensionHash } =require('@colony/colony-js');
const { getExtensionHash } = require('@colony/colony-js');

/*
* @NOTE To preserve time, I just re-used a script I wrote for one of the lambda functions
Expand Down Expand Up @@ -57,7 +57,7 @@ const createUniqueDomain = /* GraphQL */ `
const setCurrentVersion = /* GraphQL */`
mutation SetCurrentVersion($extensionHash: String!, $version: Int!) {
setCurrentVersion(input: {
item: $extensionHash,
key: $extensionHash,
version: $version
})
}
Expand Down Expand Up @@ -230,6 +230,7 @@ const createMetacolony = async (singerOrWallet) => {
name: 'meta',
profile: { displayName: 'Metacolony' },
type: 'METACOLONY',
version: BigNumber.from(metacolonyVersion).toNumber()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BigNumber.from...toNumber() could live as a little utility e.g.

numbers.ts

const toNumber = (bigNumber) => BigNumber.from(bigNumber).toNumber()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

}
},
GRAPHQL_URI,
Expand Down Expand Up @@ -300,6 +301,7 @@ const createColony = async (colonyName, tokenAddress, singerOrWallet) => {
colonyNativeTokenId: tokenAddress,
name: colonyName,
profile: { displayName: `Colony ${colonyName.toUpperCase()}` },
version: BigNumber.from(currentNetworkVersion).toNumber()
}
},
GRAPHQL_URI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const ExtensionActionButton = ({ extensionData }: Props) => {
);
};

const isSupportedColonyVersion = colony.version >= 5;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There used to be a ColonyVersion enum exported from colony-js but it's not there anymore. Open to suggestions on replacing the hardcoded value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say have a constant

const MIN_SUPPORTED_COLONY_VERSION = 5
const isSupportedColonyVersion = colony.version >= MIN_SUPPORTED_COLONY_VERSION;

or similar


if (!isInstalledExtensionData(extensionData)) {
return (
<ActionButton
Expand All @@ -51,6 +53,7 @@ const ExtensionActionButton = ({ extensionData }: Props) => {
extensionData,
}}
text={MSG.install}
disabled={!isSupportedColonyVersion}
/>
);
}
Expand All @@ -65,7 +68,7 @@ const ExtensionActionButton = ({ extensionData }: Props) => {
appearance={{ theme: 'primary', size: 'medium' }}
onClick={handleEnableButtonClick}
text={MSG.enable}
// disabled={!isSupportedColonyVersion}
disabled={!isSupportedColonyVersion}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const ExtensionUpgradeButton = ({ extensionData }: Props) => {
[],
);

// const isSupportedColonyVersion =
// parseInt(colonyVersion || '1', 10) >= ColonyVersion.LightweightSpaceship;
const isSupportedColonyVersion = true;
const isSupportedColonyVersion = (colony?.version || 1) >= 5;

const extensionCompatible = isExtensionCompatible(
Extension[extensionData.extensionId],
Expand Down
1 change: 1 addition & 0 deletions src/graphql/fragments/colony.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fragment Colony on Colony {
...Watcher
}
}
version
}

fragment Watcher on WatchedColonies {
Expand Down
Loading