From 059e43fb9b7126785b42d4676aa0f405ab90b4b4 Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Thu, 24 Aug 2023 10:56:28 +1000 Subject: [PATCH 1/6] Fix previously active but removed policies being shown as active --- api/dbschema/policy.esdl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/dbschema/policy.esdl b/api/dbschema/policy.esdl index 5d9f9fdb9..7ffa89a2a 100644 --- a/api/dbschema/policy.esdl +++ b/api/dbschema/policy.esdl @@ -23,7 +23,7 @@ module default { limit 1 ) filter not exists .activationBlock ); - property isActive := (exists .state); + required property isActive := (.state.isRemoved ?= false); constraint exclusive on ((.account, .key)); constraint exclusive on ((.account, .name)); From ce73659d1c3a177835a8a9a264ef97c6757f938e Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Thu, 24 Aug 2023 10:56:48 +1000 Subject: [PATCH 2/6] Include draft policies in account policies --- api/dbschema/default.esdl | 2 +- api/dbschema/edgeql-js/__spec__.ts | 4 ++-- api/dbschema/edgeql-js/modules/default.ts | 4 ++-- api/dbschema/migrations/00027.edgeql | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 api/dbschema/migrations/00027.edgeql diff --git a/api/dbschema/default.esdl b/api/dbschema/default.esdl index 3badc206c..23628cbf7 100644 --- a/api/dbschema/default.esdl +++ b/api/dbschema/default.esdl @@ -17,7 +17,7 @@ module default { required isActive: bool; required implementation: Address; required salt: Bytes32; - multi link policies := (select .; "; "; + "; "; "; "; - "; "; "; }>; @@ -141,8 +141,8 @@ export type $ApproverλShape = $.typeutil.flatten<_std.$Object_169a5ce7108a11eeb "; "; "; - "; "; + "; "; "; "; diff --git a/api/dbschema/migrations/00027.edgeql b/api/dbschema/migrations/00027.edgeql new file mode 100644 index 000000000..b02ed11b1 --- /dev/null +++ b/api/dbschema/migrations/00027.edgeql @@ -0,0 +1,19 @@ +CREATE MIGRATION m1ltit76m3dki4tixcyjxlzlcil27yag5depkcrr6sarp2hf3c7f6a + ONTO m1gi4tvmgtsvjgnymrdmw5ebzvq5i6llq7raoa754vlopfvqlhslsa +{ + ALTER TYPE default::Policy { + ALTER PROPERTY isActive { + USING ((.state.isRemoved ?= false)); + SET REQUIRED; + }; + }; + ALTER TYPE default::Account { + ALTER LINK policies { + USING (SELECT + . Date: Thu, 24 Aug 2023 13:10:37 +1000 Subject: [PATCH 3/6] Navigate to proposal when removing if a proposal is required --- app/src/screens/policy/PolicyAppbar.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/screens/policy/PolicyAppbar.tsx b/app/src/screens/policy/PolicyAppbar.tsx index 973762779..7333eebd7 100644 --- a/app/src/screens/policy/PolicyAppbar.tsx +++ b/app/src/screens/policy/PolicyAppbar.tsx @@ -48,6 +48,13 @@ const Remove = gql(/* GraphQL */ ` mutation PolicyAppbar_Remove($account: Address!, $key: PolicyKey!) { removePolicy(input: { account: $account, key: $key }) { id + draft { + id + proposal { + id + hash + } + } } } `); @@ -123,8 +130,11 @@ export const PolicyAppbar = ({ view, reset, setParams, ...props }: PolicyAppbarP onPress={async () => { close(); if (await confirmRemove()) { - await remove({ account: policy.account.address, key: policy.key }); - goBack(); + const proposal = ( + await remove({ account: policy.account.address, key: policy.key }) + ).data?.removePolicy.draft?.proposal?.hash; + + proposal ? navigate('Proposal', { proposal }) : goBack(); } }} /> From 03b39fc7465a0a6e021b97a0040ef08e2f4f2143 Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Thu, 24 Aug 2023 13:11:18 +1000 Subject: [PATCH 4/6] Fix activity tab crashing when a proposal subscription is received in some cases --- app/src/screens/home/Tabs/ActivityTab.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/screens/home/Tabs/ActivityTab.tsx b/app/src/screens/home/Tabs/ActivityTab.tsx index 90b23be90..a7b55f7a4 100644 --- a/app/src/screens/home/Tabs/ActivityTab.tsx +++ b/app/src/screens/home/Tabs/ActivityTab.tsx @@ -68,17 +68,22 @@ export type ActivityTabProps = TabNavigatorScreenProp<'Activity'> & { account: A export const ActivityTab = withSuspense( ({ account }: ActivityTabProps) => { - const { proposals, transfers, user } = useQuery(Query, { accounts: [account] }).data ?? {}; + // When proposals are invalidated (on proposal sub) and the user is on a different screen this screen remains mounted but suspense doesn't occur + const { + proposals = [], + transfers = [], + user, + } = useQuery(Query, { accounts: [account] }).data ?? {}; useSubscription({ query: ProposalSubscription, variables: { accounts: [account] } }); useSubscription({ query: TransferSubscription, variables: { accounts: [account] } }); - const data = [...proposals, ...transfers].sort( + const items = [...proposals, ...transfers].sort( (a, b) => asDateTime(b.timestamp).toMillis() - asDateTime(a.timestamp).toMillis(), ); return ( match(item) .with({ __typename: 'TransactionProposal' }, (p) => ( @@ -97,6 +102,7 @@ export const ActivityTab = withSuspense( There is no activity to show } + extraData={[user]} contentContainerStyle={styles.contentContainer} estimatedItemSize={ListItemHeight.DOUBLE_LINE} showsVerticalScrollIndicator={false} From 44d9138e50c3ffffee90d01a679fc5b50832c5b2 Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Thu, 24 Aug 2023 13:36:34 +1000 Subject: [PATCH 5/6] Remove unnecessary warnings --- app/src/components/InputsView.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/components/InputsView.tsx b/app/src/components/InputsView.tsx index c186e4cf0..b20583302 100644 --- a/app/src/components/InputsView.tsx +++ b/app/src/components/InputsView.tsx @@ -8,7 +8,6 @@ import { View } from 'react-native'; import { Button, IconButton, Text } from 'react-native-paper'; import { FiatValue } from '~/components/fiat/FiatValue'; import { TokenAmount } from '~/components/token/TokenAmount'; -import { logWarning } from '~/util/analytics'; const FragmentDoc = gql(/* GraphQL */ ` fragment InputsView_token on Token @argumentDefinitions(account: { type: "Address!" }) { @@ -65,10 +64,6 @@ export const InputsView = ({ input, setInput, type, setType, ...props }: InputsV setType(InputType.Token); setInput(formatUnits(token.balance, token.decimals)); }} - onLayout={(e) => { - if (e.nativeEvent.layout.width !== BUTTON_WIDTH) - logWarning(`BUTTON_WIDTH mismatch`, { width: e.nativeEvent.layout.width }); - }} > Max @@ -87,10 +82,6 @@ export const InputsView = ({ input, setInput, type, setType, ...props }: InputsV iconColor={styles.button.color} style={styles.iconButton} onPress={() => setType((type) => Number(!type))} - onLayout={(e) => { - if (e.nativeEvent.layout.width !== ICON_BUTTON_WIDTH) - logWarning('ICON_BUTTON_WIDTH mismatch', { width: e.nativeEvent.layout.width }); - }} /> From d5ba3aed389166d338ab2b63c86cab172e3a3251 Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Thu, 24 Aug 2023 14:03:23 +1000 Subject: [PATCH 6/6] Set executing policy in the same query as inserting transaction --- .../transactions/transactions.service.ts | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/api/src/features/transactions/transactions.service.ts b/api/src/features/transactions/transactions.service.ts index 0cd518825..12c2779c4 100644 --- a/api/src/features/transactions/transactions.service.ts +++ b/api/src/features/transactions/transactions.service.ts @@ -151,26 +151,24 @@ export class TransactionsService { }, ); - const transactionHash = asHex(transaction.hash); - await e - .insert(e.Transaction, { - hash: transactionHash, - proposal: selectTransactionProposal(proposal.id), - gasPrice, - }) - .run(this.db.client); - - // Set executing policy if none was set - if (!proposal.policy?.state) { - await e - .update(e.TransactionProposal, () => ({ + // Set executing policy if not already set + const selectedProposal = proposal.policy?.state + ? selectTransactionProposal(proposal.id) + : e.update(e.TransactionProposal, () => ({ filter_single: { id: proposal.id }, set: { policy: selectPolicy({ account: proposal.account.address as Address, key: policy.key }), }, - })) - .run(this.db.client); - } + })); + + const transactionHash = asHex(transaction.hash); + await this.db.query( + e.insert(e.Transaction, { + hash: transactionHash, + proposal: selectedProposal, + gasPrice, + }), + ); await this.proposals.publishProposal( { hash: proposal.hash as Hex, account: proposal.account.address as Address },