From 354af5864d293282071843b5ab7450dd382e7f91 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 29 Aug 2023 11:12:43 +0200 Subject: [PATCH] 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