From 354af5864d293282071843b5ab7450dd382e7f91 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 29 Aug 2023 11:12:43 +0200 Subject: [PATCH 1/8] add working community switch to send coins --- .../src/graphql/arg/TransactionSendArgs.ts | 5 +- .../src/graphql/resolver/CommunityResolver.ts | 2 +- .../graphql/resolver/TransactionResolver.ts | 2 +- frontend/src/components/CommunitySwitch.vue | 58 +++++++++++++++++++ .../GddSend/TransactionConfirmationSend.vue | 4 +- .../components/GddSend/TransactionForm.vue | 16 ++++- frontend/src/graphql/mutations.js | 14 ++++- frontend/src/graphql/queries.js | 5 +- frontend/src/pages/Send.vue | 6 +- 9 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 frontend/src/components/CommunitySwitch.vue diff --git a/backend/src/graphql/arg/TransactionSendArgs.ts b/backend/src/graphql/arg/TransactionSendArgs.ts index ecda848d1..80f25b817 100644 --- a/backend/src/graphql/arg/TransactionSendArgs.ts +++ b/backend/src/graphql/arg/TransactionSendArgs.ts @@ -1,5 +1,5 @@ import { Decimal } from 'decimal.js-light' -import { ArgsType, Field } from 'type-graphql' +import { ArgsType, Field, Int } from 'type-graphql' @ArgsType() export class TransactionSendArgs { @@ -11,4 +11,7 @@ export class TransactionSendArgs { @Field(() => String) memo: string + + @Field(() => Int) + targetCommunity: number } diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 4c6c8e785..09553bf24 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -26,7 +26,7 @@ export class CommunityResolver { @Authorized([RIGHTS.COMMUNITIES]) @Query(() => [Community]) - async getCommunitySelections(): Promise { + async communities(): Promise { const dbCommunities: DbCommunity[] = await DbCommunity.find({ order: { name: 'ASC', diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index ba5d6e155..52a240c28 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -317,7 +317,7 @@ export class TransactionResolver { @Authorized([RIGHTS.SEND_COINS]) @Mutation(() => Boolean) async sendCoins( - @Args() { identifier, amount, memo }: TransactionSendArgs, + @Args() { identifier, amount, memo, targetCommunity }: TransactionSendArgs, @Ctx() context: Context, ): Promise { logger.info(`sendCoins(identifier=${identifier}, amount=${amount}, memo=${memo})`) diff --git a/frontend/src/components/CommunitySwitch.vue b/frontend/src/components/CommunitySwitch.vue new file mode 100644 index 000000000..10decbcdf --- /dev/null +++ b/frontend/src/components/CommunitySwitch.vue @@ -0,0 +1,58 @@ + + diff --git a/frontend/src/components/GddSend/TransactionConfirmationSend.vue b/frontend/src/components/GddSend/TransactionConfirmationSend.vue index 95a06ea3c..4a29d00d3 100644 --- a/frontend/src/components/GddSend/TransactionConfirmationSend.vue +++ b/frontend/src/components/GddSend/TransactionConfirmationSend.vue @@ -6,7 +6,7 @@ {{ $t('form.recipientCommunity') }} - {{ communityName }} + {{ targetCommunity.name }} {{ $t('form.recipient') }} @@ -76,11 +76,11 @@ 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 }}, }, data() { return { disabled: false, - communityName: COMMUNITY_NAME, } }, } diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index d5b67d547..1a4873b15 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -54,7 +54,12 @@ {{ $t('form.recipientCommunity') }} - {{ communityName }} + + + @@ -137,6 +142,7 @@ import { SEND_TYPES } from '@/pages/Send' import InputIdentifier from '@/components/Inputs/InputIdentifier' import InputAmount from '@/components/Inputs/InputAmount' import InputTextarea from '@/components/Inputs/InputTextarea' +import CommunitySwitch from '@/components/CommunitySwitch.vue' import { user as userQuery } from '@/graphql/queries' import { isEmpty } from 'lodash' import { COMMUNITY_NAME } from '@/config' @@ -147,6 +153,7 @@ export default { InputIdentifier, InputAmount, InputTextarea, + CommunitySwitch, }, props: { balance: { type: Number, default: 0 }, @@ -154,6 +161,7 @@ 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 } }, }, data() { return { @@ -161,10 +169,10 @@ export default { identifier: this.identifier, amount: this.amount ? String(this.amount) : '', memo: this.memo, + targetCommunity: this.targetCommunity, }, radioSelected: this.selected, - userName: '', - communityName: COMMUNITY_NAME, + userName: '' } }, methods: { @@ -179,6 +187,7 @@ export default { amount: Number(this.form.amount.replace(',', '.')), memo: this.form.memo, userName: this.userName, + targetCommunity: this.form.targetCommunity, }) }, onReset(event) { @@ -186,6 +195,7 @@ export default { this.form.identifier = '' this.form.amount = '' this.form.memo = '' + this.form.targetCommunity = { id: 0, 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 2f6b53ac9..91873e627 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -71,8 +71,18 @@ export const createUser = gql` ` export const sendCoins = gql` - mutation($identifier: String!, $amount: Decimal!, $memo: String!) { - sendCoins(identifier: $identifier, amount: $amount, memo: $memo) + mutation( + $identifier: String! + $amount: Decimal! + $memo: String! + $targetCommunity: Int! + ) { + sendCoins( + identifier: $identifier, + amount: $amount, + memo: $memo, + targetCommunity: $targetCommunity + ) } ` diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index c7e1e9067..7e23f5f03 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -72,14 +72,13 @@ export const listGDTEntriesQuery = gql` } ` -export const communities = gql` +export const selectCommunities = gql` query { communities { id name - url description - registerUrl + foreign } } ` diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index 30ffc06ed..924eb7388 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -122,7 +122,11 @@ export default { this.$apollo .mutate({ mutation: sendCoins, - variables: this.transactionData, + variables: { + ...this.transactionData, + // from target community we need only the id + targetCommunity: this.transactionData.targetCommunity.id, + }, }) .then(() => { this.error = false From 67d48a2eec7880bea3074ed7257af5b7bc1e7d4f Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 29 Aug 2023 16:30:33 +0200 Subject: [PATCH 2/8] 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(() => { From fef424b93d4401272cb05c4fef9679b4a9287885 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 29 Aug 2023 16:54:09 +0200 Subject: [PATCH 3/8] remove not existing query, update existing along with resolver --- backend/src/seeds/graphql/queries.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 949ed86d7..1b5a84d45 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -118,17 +118,6 @@ export const listGDTEntriesQuery = gql` } ` -export const communityInfo = gql` - query { - getCommunityInfo { - name - description - registerUrl - url - } - } -` - export const communities = gql` query { communities { @@ -159,7 +148,7 @@ export const getCommunities = gql` export const getCommunitySelections = gql` query { - getCommunitySelections { + communities { id foreign name From 9a8fac54aec6138acc917453a402bb279b43453d Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Wed, 30 Aug 2023 18:00:26 +0200 Subject: [PATCH 4/8] fix frontend tests --- frontend/src/components/CommunitySwitch.vue | 4 --- .../GddSend/TransactionForm.spec.js | 31 ++++++++++++++++++- frontend/src/pages/Send.spec.js | 12 +++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/CommunitySwitch.vue b/frontend/src/components/CommunitySwitch.vue index 257d3ef83..dd4b159aa 100644 --- a/frontend/src/components/CommunitySwitch.vue +++ b/frontend/src/components/CommunitySwitch.vue @@ -15,16 +15,12 @@