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

Zal 162 #146

Merged
merged 6 commits into from
Aug 24, 2023
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
2 changes: 1 addition & 1 deletion api/dbschema/default.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module default {
required isActive: bool;
required implementation: Address;
required salt: Bytes32;
multi link policies := (select .<account[is Policy] filter .state.isRemoved ?= false);
multi link policies := (select .<account[is Policy] filter (.isActive or exists .draft));
multi link proposals := .<account[is Proposal];
multi link transactionProposals := .<account[is TransactionProposal];
multi link transfers := .<account[is Transfer];
Expand Down
4 changes: 2 additions & 2 deletions api/dbschema/edgeql-js/__spec__.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/dbschema/edgeql-js/modules/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export type $AccountλShape = $.typeutil.flatten<_std.$Object_169a5ce7108a11eeb5
"<account[is Transfer]": $.LinkDesc<$Transfer, $.Cardinality.Many, {}, false, false, false, false>;
"<account[is Policy]": $.LinkDesc<$Policy, $.Cardinality.Many, {}, false, false, false, false>;
"<accounts[is Approver]": $.LinkDesc<$Approver, $.Cardinality.Many, {}, false, false, false, false>;
"<account[is MessageProposal]": $.LinkDesc<$MessageProposal, $.Cardinality.Many, {}, false, false, false, false>;
"<accounts[is current_approver]": $.LinkDesc<$current_approver, $.Cardinality.Many, {}, false, false, false, false>;
"<accounts[is User]": $.LinkDesc<$User, $.Cardinality.Many, {}, false, false, false, false>;
"<accounts[is current_user]": $.LinkDesc<$current_user, $.Cardinality.Many, {}, false, false, false, false>;
"<account[is MessageProposal]": $.LinkDesc<$MessageProposal, $.Cardinality.Many, {}, false, false, false, false>;
"<account": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
"<accounts": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
}>;
Expand Down Expand Up @@ -141,8 +141,8 @@ export type $ApproverλShape = $.typeutil.flatten<_std.$Object_169a5ce7108a11eeb
"<proposedBy[is Proposal]": $.LinkDesc<$Proposal, $.Cardinality.Many, {}, false, false, false, false>;
"<proposedBy[is TransactionProposal]": $.LinkDesc<$TransactionProposal, $.Cardinality.Many, {}, false, false, false, false>;
"<approvers[is PolicyState]": $.LinkDesc<$PolicyState, $.Cardinality.Many, {}, false, false, false, false>;
"<approvers[is Account]": $.LinkDesc<$Account, $.Cardinality.Many, {}, false, false, false, false>;
"<proposedBy[is MessageProposal]": $.LinkDesc<$MessageProposal, $.Cardinality.Many, {}, false, false, false, false>;
"<approvers[is Account]": $.LinkDesc<$Account, $.Cardinality.Many, {}, false, false, false, false>;
"<approver": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
"<approvers": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
"<proposedBy": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
Expand Down
19 changes: 19 additions & 0 deletions api/dbschema/migrations/00027.edgeql
Original file line number Diff line number Diff line change
@@ -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
.<account[IS default::Policy]
FILTER
(.isActive OR EXISTS (.draft))
);
};
};
};
2 changes: 1 addition & 1 deletion api/dbschema/policy.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
30 changes: 14 additions & 16 deletions api/src/features/transactions/transactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
9 changes: 0 additions & 9 deletions app/src/components/InputsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!" }) {
Expand Down Expand Up @@ -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
</Button>
Expand All @@ -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 });
}}
/>
</View>

Expand Down
12 changes: 9 additions & 3 deletions app/src/screens/home/Tabs/ActivityTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<FlashList
data={data}
data={items}
renderItem={({ item }) =>
match(item)
.with({ __typename: 'TransactionProposal' }, (p) => (
Expand All @@ -97,6 +102,7 @@ export const ActivityTab = withSuspense(
There is no activity to show
</Text>
}
extraData={[user]}
contentContainerStyle={styles.contentContainer}
estimatedItemSize={ListItemHeight.DOUBLE_LINE}
showsVerticalScrollIndicator={false}
Expand Down
14 changes: 12 additions & 2 deletions app/src/screens/policy/PolicyAppbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
`);
Expand Down Expand Up @@ -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();
}
}}
/>
Expand Down
Loading