From 67d48a2eec7880bea3074ed7257af5b7bc1e7d4f Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 29 Aug 2023 16:30:33 +0200 Subject: [PATCH] linting, add claus peters suggestions --- backend/src/graphql/arg/TransactionSendArgs.ts | 11 ++++++----- .../src/graphql/resolver/TransactionResolver.ts | 9 ++++++--- frontend/src/components/CommunitySwitch.vue | 14 +++++++++----- .../GddSend/TransactionConfirmationSend.vue | 7 ++++++- .../src/components/GddSend/TransactionForm.vue | 15 ++++++++++----- frontend/src/graphql/mutations.js | 12 ++++++------ frontend/src/graphql/queries.js | 2 +- frontend/src/pages/Send.vue | 8 +++++--- 8 files changed, 49 insertions(+), 29 deletions(-) diff --git a/backend/src/graphql/arg/TransactionSendArgs.ts b/backend/src/graphql/arg/TransactionSendArgs.ts index 7691d7b80..5bd8b89f7 100644 --- a/backend/src/graphql/arg/TransactionSendArgs.ts +++ b/backend/src/graphql/arg/TransactionSendArgs.ts @@ -1,6 +1,6 @@ import { MaxLength, MinLength, IsString } from 'class-validator' import { Decimal } from 'decimal.js-light' -import { ArgsType, Field, Int } from 'type-graphql' +import { ArgsType, Field } from 'type-graphql' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from '@/graphql/resolver/const/const' import { IsPositiveDecimal } from '@/graphql/validator/Decimal' @@ -9,7 +9,11 @@ import { IsPositiveDecimal } from '@/graphql/validator/Decimal' export class TransactionSendArgs { @Field(() => String) @IsString() - identifier: string + recipientCommunityIdentifier: string + + @Field(() => String) + @IsString() + recipientIdentifier: string @Field(() => Decimal) @IsPositiveDecimal() @@ -19,7 +23,4 @@ export class TransactionSendArgs { @MaxLength(MEMO_MAX_CHARS) @MinLength(MEMO_MIN_CHARS) memo: string - - @Field(() => Int) - targetCommunity: number } diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 264a8e219..32b453ae1 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -308,15 +308,18 @@ export class TransactionResolver { @Authorized([RIGHTS.SEND_COINS]) @Mutation(() => Boolean) async sendCoins( - @Args() { identifier, amount, memo, targetCommunity }: TransactionSendArgs, + @Args() + { /* recipientCommunityIdentifier, */ recipientIdentifier, amount, memo }: TransactionSendArgs, @Ctx() context: Context, ): Promise { - logger.info(`sendCoins(identifier=${identifier}, amount=${amount}, memo=${memo})`) + logger.info( + `sendCoins(recipientIdentifier=${recipientIdentifier}, amount=${amount}, memo=${memo})`, + ) const senderUser = getUser(context) // validate recipient user - const recipientUser = await findUserByIdentifier(identifier) + const recipientUser = await findUserByIdentifier(recipientIdentifier) if (!recipientUser) { throw new LogError('The recipient user was not found', recipientUser) } diff --git a/frontend/src/components/CommunitySwitch.vue b/frontend/src/components/CommunitySwitch.vue index 10decbcdf..257d3ef83 100644 --- a/frontend/src/components/CommunitySwitch.vue +++ b/frontend/src/components/CommunitySwitch.vue @@ -6,7 +6,7 @@ @click.prevent="updateCommunity(community)" :key="community.id" :title="community.description" - :active="value.id === community.id" + :active="value.uuid === community.uuid" > {{ community.name }} @@ -20,7 +20,12 @@ import { COMMUNITY_NAME } from '@/config' export default { name: 'CommunitySwitch', props: { - value: { type: Object, default: { id: 0, name: COMMUNITY_NAME } }, + value: { + type: Object, + default: function () { + return { uuid: '', name: COMMUNITY_NAME } + }, + }, }, data() { return { @@ -29,13 +34,12 @@ export default { }, methods: { updateCommunity(community) { - this.value = community - this.$emit('input', this.value) + this.$emit('input', community) }, setDefaultCommunity() { // set default community, the only one which isn't foreign // we assume it is only one entry with foreign = false - if (!this.value.id && this.communities.length) { + if (this.value.uuid === '' && this.communities.length) { const foundCommunity = this.communities.find((community) => !community.foreign) if (foundCommunity) { this.updateCommunity(foundCommunity) diff --git a/frontend/src/components/GddSend/TransactionConfirmationSend.vue b/frontend/src/components/GddSend/TransactionConfirmationSend.vue index 4a29d00d3..caa40d128 100644 --- a/frontend/src/components/GddSend/TransactionConfirmationSend.vue +++ b/frontend/src/components/GddSend/TransactionConfirmationSend.vue @@ -76,7 +76,12 @@ export default { amount: { type: Number, required: true }, memo: { type: String, required: true }, userName: { type: String, default: '' }, - targetCommunity: { type: Object, default: { id: 0, name: COMMUNITY_NAME }}, + targetCommunity: { + type: Object, + default: function () { + return { uuid: '', name: COMMUNITY_NAME } + }, + }, }, data() { return { diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index 1a4873b15..7304137ee 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -55,8 +55,8 @@ - @@ -161,7 +161,12 @@ export default { amount: { type: Number, default: 0 }, memo: { type: String, default: '' }, selected: { type: String, default: 'send' }, - targetCommunity: { type: Object, default: { id: 0, name: COMMUNITY_NAME } }, + targetCommunity: { + type: Object, + default: function () { + return { uuid: '', name: COMMUNITY_NAME } + }, + }, }, data() { return { @@ -172,7 +177,7 @@ export default { targetCommunity: this.targetCommunity, }, radioSelected: this.selected, - userName: '' + userName: '', } }, methods: { @@ -195,7 +200,7 @@ export default { this.form.identifier = '' this.form.amount = '' this.form.memo = '' - this.form.targetCommunity = { id: 0, name: COMMUNITY_NAME } + this.form.targetCommunity = { uuid: '', name: COMMUNITY_NAME } this.$refs.formValidator.validate() if (this.$route.query && !isEmpty(this.$route.query)) this.$router.replace({ query: undefined }) diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index 91873e627..b4f96179f 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -72,16 +72,16 @@ export const createUser = gql` export const sendCoins = gql` mutation( - $identifier: String! + $recipientCommunityIdentifier: String! + $recipientIdentifier: String! $amount: Decimal! $memo: String! - $targetCommunity: Int! ) { sendCoins( - identifier: $identifier, - amount: $amount, - memo: $memo, - targetCommunity: $targetCommunity + recipientCommunityIdentifier: $recipientCommunityIdentifier + recipientIdentifier: $recipientIdentifier + amount: $amount + memo: $memo ) } ` diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 7e23f5f03..6ef5d56d6 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -75,7 +75,7 @@ export const listGDTEntriesQuery = gql` export const selectCommunities = gql` query { communities { - id + uuid name description foreign diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index 924eb7388..607c7e36c 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -123,9 +123,11 @@ export default { .mutate({ mutation: sendCoins, variables: { - ...this.transactionData, - // from target community we need only the id - targetCommunity: this.transactionData.targetCommunity.id, + // from target community we need only the uuid + recipientCommunityIdentifier: this.transactionData.targetCommunity.uuid, + recipientIdentifier: this.transactionData.identifier, + amount: this.transactionData.amount, + memo: this.transactionData.memo, }, }) .then(() => {