Skip to content

Commit

Permalink
feat: encrypted telegram handle on-chain (#90)
Browse files Browse the repository at this point in the history
* chore: set client as ChainClient.dev

* chore: update models front

* chore: update profile data models and create ProfileModel to handle storage

* wip: crete offer and open trade with telegram handle

* chore: create cryptography helper

* chore: save secrets in local storage by wallet

* chore: fix contracts and tests

* fix: contract contact information

* change: use profile and secrets to encrypt and decrypt telegram handle

* fetch profile when create a offer and when open a trade

* update: test fixtures

* update tests

* fix: open trade

* fix: layout expandedOffer with telegram handle (#91)

chore: changed layout of expandedOffer with the new Telegram input

Co-authored-by: gabs <[email protected]>

* change: select arbitrator when the trade is created

* open dispute with buyer and seller contacts

* wip: arbitrator chat view

* fix: layout telegram handle part 2 (#92)

* chore: added tooltip
* chore: grid adjustments
* chore: created IconTooltip component
* chore: added tooltip to create offer and now passing content as props
* chore: passed content to create offer tooltip
* fix: adjust tooltip position
* chore: reorganized chatbox card messages and added telegram button
* fix: use flex instead of fixed width for layout proportions
* chore: adjusted button size

Co-authored-by: gabs <[email protected]>
Co-authored-by: davirds <[email protected]>

* fix: telegram arbitrator view (#93)

* chore: styled telegram buttons for buyer and seller
* chore: change maker and taker label on telegram btn

Co-authored-by: gabs <[email protected]>

* wip: clean

* renaming variables

* remove unused create profile action

* set multiple ownsership to the update_profile action

* use profile to save and read encrypt_key

* update models

* update tests

* delete MockChain

* clear code

* delete unused component chatbox

* rename variables

* fix: varibles names

Co-authored-by: gabs <[email protected]>
Co-authored-by: gabs <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2022
1 parent 5b32df4 commit cd473b3
Show file tree
Hide file tree
Showing 37 changed files with 1,349 additions and 753 deletions.
1 change: 1 addition & 0 deletions app/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module '@vue/runtime-core' {
Home: typeof import('./ui/pages/Home.vue')['default']
HomeHero: typeof import('./ui/components/HomeHero.vue')['default']
IconDone: typeof import('./ui/components/commons/IconDone.vue')['default']
IconTooltip: typeof import('./ui/components/commons/IconTooltip.vue')['default']
ListContentResult: typeof import('./ui/components/commons/ListContentResult.vue')['default']
ListDisputes: typeof import('./ui/components/arbitration/ListDisputes.vue')['default']
ListMyOffers: typeof import('./ui/components/myOffers/ListMyOffers.vue')['default']
Expand Down
9 changes: 4 additions & 5 deletions app/src/network/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type {
NewTrade,
PatchOffer,
PostOffer,
Profile,
Trade,
TradeInfo,
} from '~/types/components.interface'
import { MockChain } from '~/network/mock/MockChain'
import { CosmosChain } from '~/network/cosmos/CosmosChain'

export interface Chain {
Expand All @@ -22,6 +22,8 @@ export interface Chain {

getWalletAddress(): string

fetchProfile(): Promise<Profile>

fetchOffer(offerId: string): Promise<GetOffer>

fetchOffers(args: FetchOffersArgs): Promise<GetOffer[]>
Expand Down Expand Up @@ -54,15 +56,14 @@ export interface Chain {

refundEscrow(tradeId: string): Promise<void>

openDispute(tradeId: string): Promise<void>
openDispute(tradeId: string, buyerContact: string, sellerContact: string): Promise<void>

settleDispute(tradeId: string, winner: string): Promise<void>

newArbitrator(arbitrator: Arbitrator): Promise<void>
}

export enum ChainClient {
mock = 'MOCK',
kujira = 'KUJIRA',
juno = 'JUNO',
dev = 'DEV',
Expand All @@ -71,8 +72,6 @@ export enum ChainClient {
// Centralized place to instantiate chain client and inject dependencies if needed
export function chainFactory(client: ChainClient): Chain {
switch (client) {
case ChainClient.mock:
return new MockChain()
case ChainClient.kujira:
return new CosmosChain(KUJIRA_TESTNET_CONFIG, KUJIRA_TESTNET_HUB_INFO)
case ChainClient.juno:
Expand Down
25 changes: 23 additions & 2 deletions app/src/network/cosmos/CosmosChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
NewTrade,
PatchOffer,
PostOffer,
Profile,
Trade,
TradeInfo,
} from '~/types/components.interface'
Expand Down Expand Up @@ -63,6 +64,22 @@ export class CosmosChain implements Chain {
return this.account ? this.account.address : 'undefined'
}

async fetchProfile() {
if (this.cwClient instanceof SigningCosmWasmClient && this.signer) {
try {
const result = (await this.cwClient.queryContractSmart(this.hubInfo.hubConfig.profile_addr, {
profile: { addr: this.getWalletAddress() },
})) as Profile
console.log('Profile result >> ', result)
return result
} catch (e) {
throw new DefaultError()
}
} else {
throw new WalletNotConnected()
}
}

// TODO encrypt the postOffer.owner_contact field
async createOffer(postOffer: PostOffer) {
const msg = { create: { offer: postOffer } }
Expand Down Expand Up @@ -368,9 +385,13 @@ export class CosmosChain implements Chain {
})
}

async openDispute(tradeId: string) {
async openDispute(tradeId: string, buyerContact: string, sellerContact: string) {
await this.changeTradeState(this.hubInfo.hubConfig.trade_addr, {
dispute_escrow: { trade_id: tradeId },
dispute_escrow: {
trade_id: tradeId,
buyer_contact: buyerContact,
seller_contact: sellerContact,
},
})
}

Expand Down
1 change: 1 addition & 0 deletions app/src/network/cosmos/config/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const DEV_HUB_INFO: HubInfo = {
offer_addr: process.env.OFFER ?? '',
trade_addr: process.env.TRADE ?? '',
trading_incentives_addr: '',
profile_addr: '',
local_market_addr: process.env.LOCAL_MARKET ?? '',
local_denom: {
native: process.env.LOCAL_DENOM ?? '',
Expand Down
1 change: 1 addition & 0 deletions app/src/network/cosmos/config/juno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const JUNO_TESTNET_HUB_INFO: HubInfo = {
hubConfig: {
offer_addr: 'juno1qzjsgnpwtlz265t2cxheftf5mlgs7lqjacvz3lkp5vr4ga3rgassgvsegx',
trade_addr: 'juno1htpc5ek2p80agv2x7tjgx6l03p52l930dd4dyk3qk9raanzyrngq4zx8da',
profile_addr: '',
trading_incentives_addr: 'juno1a6qzj0ep50jjn97ufmsjlwdhnqmny2phhcug3e6404tkngfd906syquknw',
local_market_addr: 'juno1gqhxtrsve4f2pcp65fr8l5t86pu7v0cxqvqgj6',
local_denom: { native: 'ujunox' },
Expand Down
1 change: 1 addition & 0 deletions app/src/network/cosmos/config/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const KUJIRA_TESTNET_HUB_INFO: HubInfo = {
hubConfig: {
offer_addr: 'kujira17yfjhj4adsqlsm452a4hawp6lgtzd2lyrqnmfe057vd5pcpd8rwsykv8na',
trade_addr: 'kujira1kd0uf7za28hslrlz4ag82kyyaucmd8mzukut44p8nlnrkj4mps0sgxzuck',
profile_addr: '',
trading_incentives_addr: 'kujira1lzsuzy7485zzyze0tla55vn4ddwxa2flwhws9mrwfxftmhzmnwuslxv6z2',
local_market_addr: 'kujira1chejx4qqtvwxy6684yrsmf6pylancxqhk3vsmtleg5ta3zrffljq4xf685',
local_denom: {
Expand Down
150 changes: 0 additions & 150 deletions app/src/network/mock/MockChain.ts

This file was deleted.

50 changes: 0 additions & 50 deletions app/src/network/mock/fixtures/home/offers.json

This file was deleted.

50 changes: 0 additions & 50 deletions app/src/network/mock/fixtures/offers/my-offers.json

This file was deleted.

15 changes: 0 additions & 15 deletions app/src/network/mock/fixtures/trade/open-trade-info.json

This file was deleted.

Loading

0 comments on commit cd473b3

Please sign in to comment.