Skip to content

Commit

Permalink
#135 Added User type
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jan 9, 2023
1 parent 456dab2 commit e7a2811
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 86 deletions.
24 changes: 12 additions & 12 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VUE_APP_API_COSMOS=https://cardchain.crowdcontrol.network/cosmos
VUE_APP_WS_TENDERMINT=wss://cardchain.crowdcontrol.network/tendermint/websocket
VUE_APP_API_TENDERMINT=https://cardchain.crowdcontrol.network/tendermint/
VUE_APP_FAUCET=https://cardchain.crowdcontrol.network/faucet/claimTokens
#VUE_APP_API_COSMOS=https://cardchain.crowdcontrol.network/cosmos
#VUE_APP_WS_TENDERMINT=wss://cardchain.crowdcontrol.network/tendermint/websocket
#VUE_APP_API_TENDERMINT=https://cardchain.crowdcontrol.network/tendermint/
#VUE_APP_FAUCET=https://cardchain.crowdcontrol.network/faucet/claimTokens

VUE_APP_FAUCET_SITEKEY="ea68532a-a9e6-4f99-9361-db90a3071b72"
VUE_APP_ADDRESS_PREFIX=cc
Expand All @@ -11,12 +11,12 @@ VUE_APP_CARDIMG_MAXKB=500
VUE_APP_UCREDITS_FACTOR=1000000
NODE_VERSION=v12.18.3

VUE_APP_API_COSMOS_FALLBACK=https://cardchain2.crowdcontrol.network/cosmos
VUE_APP_WS_TENDERMINT_FALLBACK=wss://cardchain2.crowdcontrol.network/tendermint/websocket
VUE_APP_API_TENDERMINT_FALLBACK=https://cardchain2.crowdcontrol.network/tendermint/
VUE_APP_FAUCET_FALLBACK=https://cardchain2.crowdcontrol.network/faucet/claimTokens
#VUE_APP_API_COSMOS_FALLBACK=https://cardchain2.crowdcontrol.network/cosmos
#VUE_APP_WS_TENDERMINT_FALLBACK=wss://cardchain2.crowdcontrol.network/tendermint/websocket
#VUE_APP_API_TENDERMINT_FALLBACK=https://cardchain2.crowdcontrol.network/tendermint/
#VUE_APP_FAUCET_FALLBACK=https://cardchain2.crowdcontrol.network/faucet/claimTokens

#VUE_APP_API_COSMOS=http://localhost:1317
#VUE_APP_WS_TENDERMINT=ws://localhost:26657/websocket
#VUE_APP_API_TENDERMINT=http://localhost:26657
#VUE_APP_FAUCET="http://localhost:4500/claimTokens"
VUE_APP_API_COSMOS=http://localhost:1317
VUE_APP_WS_TENDERMINT=ws://localhost:26657/websocket
VUE_APP_API_TENDERMINT=http://localhost:26657
VUE_APP_FAUCET="http://localhost:4500/claimTokens"
3 changes: 3 additions & 0 deletions src/model/Coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ class Coin {
pretty() {
return this.amount + this.denom;
}
static from(json) {
return Object.assign(new Coin(), json);
}
}
exports.Coin = Coin;
4 changes: 4 additions & 0 deletions src/model/Coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ export class Coin {
pretty() {
return this.amount + this.denom;
}

static from(json) {
return Object.assign(new Coin(), json);
}
}
47 changes: 47 additions & 0 deletions src/model/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.User = void 0;
class User {
constructor() {
this.ReportMatches = false;
this.airDrops = new AirDrops();
this.alias = "";
this.biography = "";
this.boosterPacks = [];
this.cards = [];
this.councilParticipation = new CouncilParticipation();
this.ownedCardSchemes = [];
this.ownedPrototypes = [];
this.profileCard = 0;
this.voteRights = [];
this.website = "";
}
static from(json) {
let user = Object.assign(new User(), json);
user.airDrops = AirDrops.from(json.airDrops);
user.councilParticipation = CouncilParticipation.from(json.councilParticipation);
return user;
}
}
exports.User = User;
class AirDrops {
constructor() {
this.vote = false;
this.create = false;
this.buy = false;
this.play = false;
this.user = false;
}
static from(json) {
return Object.assign(new AirDrops(), json);
}
}
class CouncilParticipation {
constructor() {
this.council = 0;
this.status = "";
}
static from(json) {
return Object.assign(new CouncilParticipation(), json);
}
}
42 changes: 42 additions & 0 deletions src/model/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export class User {
ReportMatches: boolean = false
airDrops: AirDrops = new AirDrops()
alias: string = ""
biography: string = ""
boosterPacks: Array<any> = []
cards: Array<number> = []
councilParticipation: CouncilParticipation = new CouncilParticipation()
ownedCardSchemes: Array<number> = []
ownedPrototypes: Array<number> = []
profileCard: number = 0
voteRights: Array<any> = []
website: string = ""

static from(json) {
let user: User = Object.assign(new User(), json);
user.airDrops = AirDrops.from(json.airDrops)
user.councilParticipation = CouncilParticipation.from(json.councilParticipation)
return user
}
}

class AirDrops {
vote: boolean = false
create: boolean = false
buy: boolean = false
play: boolean = false
user: boolean = false

static from(json) {
return Object.assign(new AirDrops(), json);
}
}

class CouncilParticipation {
council: number = 0
status: string = ""

static from(json) {
return Object.assign(new CouncilParticipation(), json);
}
}
57 changes: 8 additions & 49 deletions src/plugins/cardChain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { entropyToMnemonic } from 'bip39'
import { creditsFromCoins } from '@/components/utils/utils.js'
import { GenericAuthorization } from "../store/generated/cosmos/cosmos-sdk/cosmos.authz.v1beta1/module/types/cosmos/authz/v1beta1/authz.js"
import { Card, ChainCard } from "@/model/Card";
import { User } from "@/model/User";
import { Coin } from "@/model/Coin";
//import {Any} from "../store/generated/cosmos/cosmos-sdk/cosmos.authz.v1beta1/module/types/google/protobuf/any.js"

export default {
Expand Down Expand Up @@ -91,53 +93,6 @@ export default {
})
}
}
cardWebModelToCardobject (webModel, cardImageUrl) {
console.log('trying to parse ', webModel)
let cardContent = {
CardName: webModel.CardName,
Tags: R.reject(R.isNil, webModel.Tags),
FlavourText: webModel.FlavourText,
Class: {
Nature: webModel.Class.Nature == true,
Technology: webModel.Class.Technology == true,
Culture: webModel.Class.Culture == true,
Mysticism: webModel.Class.Mysticism == true,
},
Keywords: R.map(JSON.stringify, webModel.Keywords),
RulesTexts: webModel.RulesTexts
}
// in the following part we check things that are only required for specific card types
if (webModel.type !== "Headquarter") {
cardContent.CastingCost = webModel.CastingCost
console.log("additionalcost empty?", R.isEmpty(webModel.AdditionalCost))
if (!R.isEmpty(webModel.AdditionalCost)) {
cardContent.AdditionalCost = webModel.AdditionalCost
}
}
if (webModel.type !== "Action") {
cardContent.Health = webModel.Health
cardContent.Abilities = webModel.Abilities
}
if (webModel.type === "Entity") {
cardContent.Attack = webModel.Attack
}
else if (webModel.type === "Action") {
cardContent.Effects = webModel.Effects
}
else if (webModel.type === "Headquarter") {
cardContent.Delay = webModel.Delay
}
let cardobject = {
content: {
[webModel.type]: cardContent
},
image: cardImageUrl ? cardImageUrl : "if you read this, someone was able to upload a card without proper image...",
fullArt: webModel.fullArt,
notes: webModel.notes,
}
console.log('parsed into:', cardobject)
return cardobject
}
saveContentToUnusedCardSchemeTx (card) {
return this.getUserInfo(this.vue.$store.getters['common/wallet/address'])
.then(user => {
Expand Down Expand Up @@ -328,7 +283,7 @@ export default {
this.vue.notifyFail('YOU SHALL NOT PASS!', address + ' is not registered. Please click Join and register in the blockchain.')
throw new Error('account ' + address + ' is not registered')
} else {
return res.data
return User.from(res.data)
}
})
handleGetGrants = R.curry((res, address) => {
Expand All @@ -340,8 +295,12 @@ export default {
this.vue.notifyFail('Account not registered', address + ' is not registered on the blockchain.')
throw new Error(address + ' is not registered on the blockchain.')
} else {
let coins = []
res.data.balances.forEach(coin => {
coins.push(Coin.from(coin))
})
return {
coins: res.data.balances
coins: coins
}
}
})
Expand Down
42 changes: 17 additions & 25 deletions src/views/UserView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@
</router-link> <br>
Owned cards:
<router-link
:to="{ name: 'Gallery', query: { cardList: user.ownedCards }}"
:to="{ name: 'Gallery', query: { cardList: user.cards }}"
>
{{ user.cards.length }}
</router-link>
</div>
<br>

<div>
Council status: {{ user.CouncilStatus }} <br>
Council status: {{ user.councilParticipation.status }} <br>
<div
v-if="loggedinHere"
style="display: inline"
>
<button
v-if="user.CouncilStatus == 'unavailable'"
v-if="user.councilParticipation.status === 'unavailable'"
@click="register()"
>
Register for council
</button>
<button
v-if="user.CouncilStatus == 'available'"
v-if="user.councilParticipation.status === 'available'"
@click="deRegister()"
>
Deregister from council
Expand Down Expand Up @@ -144,7 +144,7 @@ import TransferModal from '../components/modals/TransferModal.vue';
import ChoosePBModal from '../components/modals/ChoosePBModal.vue';
import GrantModal from '../components/modals/GrantModal.vue';
import AirdropsModal from '../components/modals/AirdropsModal.vue';
import { Coin } from '@/model/Coin'
import { User } from "@/model/User";
export default {
name: 'UserView',
Expand All @@ -164,25 +164,18 @@ export default {
address: "",
coins: [],
img: "",
user: {
ownedCardSchemes: [],
ownedPrototypes: [],
cards: [],
voteRights: [],
profileCard: 0,
airdrops: {},
},
user: new User()
}
},
watch: {
"$route.params.id"(value) {
"$route.params.id"(_) {
console.log(this.$route)
if (this.$route.name == "UserView") {
if (this.$route.name === "UserView") {
this.init()
}
},
'$store.state.common.wallet.selectedAddress': function () {
this.loggedinHere = (this.address == this.$store.getters['common/wallet/address'])
this.loggedinHere = (this.address === this.$store.getters['common/wallet/address'])
}
},
mounted () {
Expand All @@ -202,7 +195,7 @@ export default {
this.address = id
}
this.loggedinHere = (this.address == this.$store.getters['common/wallet/address'])
this.loggedinHere = (this.address === this.$store.getters['common/wallet/address'])
if (! this.$cardChain.validAddress(this.address)) {
this.$router.push({name: "NotFound"})
Expand Down Expand Up @@ -231,9 +224,9 @@ export default {
},
normalizeCoins(coins) {
let newCoins = [];
for (let i = 0; i<coins.length; i++) {
newCoins.push(new Coin(coins[i]).nornalize())
}
coins.forEach(coin => {
newCoins.push(coin.normalize())
})
return newCoins
},
showModal() {
Expand Down Expand Up @@ -263,14 +256,13 @@ export default {
this.isAirdropsModalVisible = false;
},
getDefaultImg() {
var myRandom = this.address.charCodeAt(this.address.length-1) % 4
console.log("random", myRandom)
let myRandom = this.address.charCodeAt(this.address.length-1) % 4
return "Avatar"+myRandom+".png"
},
async getImg() {
console.log(this.user.profileCard)
if (this.user.profileCard != 0) {
var a = await this.getCard(this.user.profileCard)
if (this.user.profileCard !== 0) {
let a = await this.getCard(this.user.profileCard)
if (a === null) {
this.img = this.getDefaultImg()
} else {
Expand All @@ -284,7 +276,7 @@ export default {
return this.$cardChain.getCard(id).then(res => {
return res
})
.catch(err => {
.catch(_ => {
return null
})
}
Expand Down

0 comments on commit e7a2811

Please sign in to comment.