Skip to content

Commit

Permalink
Merge pull request #194 from UnUniFi/feature/metamask-support
Browse files Browse the repository at this point in the history
feat: metamask support
  • Loading branch information
YasunoriMATSUOKA authored Jun 13, 2022
2 parents 3b9f040 + e676d39 commit 568081e
Show file tree
Hide file tree
Showing 41 changed files with 6,051 additions and 4,302 deletions.
9,539 changes: 5,403 additions & 4,136 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,32 @@
"@angular/platform-browser-dynamic": "~12.2.0",
"@angular/router": "~12.2.0",
"@apollo/client": "^3.0.0",
"@cosmos-client/core": "^0.45.1",
"@cosmos-client/core": "^0.45.9",
"@metamask/detect-provider": "^1.2.0",
"@ngneat/tailwind": "^7.0.3",
"@ngrx/effects": "^12.4.0",
"@ngrx/store": "^12.4.0",
"@ngrx/store-devtools": "^12.4.0",
"apollo-angular": "^3.0.1",
"assert": "^2.0.0",
"bignumber.js": "^9.0.2",
"bip39": "^3.0.4",
"crypto-browserify": "^3.12.0",
"dexie": "^3.0.3",
"ethers": "^5.6.8",
"firebase": "^9.6.10",
"graphql": "^16",
"https-browserify": "^1.0.0",
"ng-loading-dialog": "^12.0.6",
"ng-min-max": "^12.0.5",
"ngx-dropzone": "^3.1.0",
"ngx-skeleton-loader": "^5.0.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"querystring": "^0.2.1",
"rxjs": "~6.6.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tslib": "^2.3.0",
"ununifi-client": "^0.45.1",
"zone.js": "~0.11.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export class AccountComponent implements OnInit {
}
return rest.auth
.account(sdk.rest, address)
.then((res) => res.data && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((error) => {
console.error(error);
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class AccountComponent implements OnInit, OnChanges {
if (this.account instanceof proto.cosmos.auth.v1beta1.BaseAccount) {
this.baseAccount = this.account;
// Todo: fix pub_key zero issue and convert bech32 format
const publicKey = cosmosclient.codec.unpackAny(this.baseAccount.pub_key);
const publicKey = cosmosclient.codec.protoAnyToInstance(this.baseAccount.pub_key);
if (!(publicKey instanceof proto.cosmos.crypto.secp256k1.PubKey)) {
throw Error('Invalid public key!');
}
Expand All @@ -47,7 +47,7 @@ export class AccountComponent implements OnInit, OnChanges {
this.vestingAccount.base_vesting_account?.base_account,
);
// Todo: fix pub_key zero issue and convert bech32 format
const publicKey = cosmosclient.codec.unpackAny(this.baseAccount.pub_key);
const publicKey = cosmosclient.codec.protoAnyToInstance(this.baseAccount.pub_key);
if (!(publicKey instanceof proto.cosmos.crypto.secp256k1.PubKey)) {
throw Error('Invalid public key!');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ProposalComponent implements OnInit {

unpackContent(value: any) {
try {
return cosmosclient.codec.unpackCosmosAny(value) as ProposalContent;
return cosmosclient.codec.protoJSONToInstance(value) as ProposalContent;
} catch {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ProposalsComponent implements OnInit {

unpackContent(value: any) {
try {
return cosmosclient.codec.unpackCosmosAny(value) as ProposalContent;
return cosmosclient.codec.protoJSONToInstance(value) as ProposalContent;
} catch {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions projects/explorer/src/app/views/txs/tx/tx.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export class TxComponent implements OnInit {

unpackMsg(value: any) {
try {
return cosmosclient.codec.unpackCosmosAny(value);
return cosmosclient.codec.protoJSONToInstance(value);
} catch {
return null;
}
}

unpackKey(value: any) {
try {
return cosmosclient.codec.unpackCosmosAny(value) as cosmosclient.PubKey;
return cosmosclient.codec.protoJSONToInstance(value) as cosmosclient.PubKey;
} catch {
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions projects/explorer/src/assets/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const domainCauchyEC = 'c.private-test.ununifi.cauchye.net';
const domainCauchyED = 'd.private-test.ununifi.cauchye.net';

const chainID = 'ununifi-8-private-test'
const chainName = 'UnUnuFi (Private)';

const chainName = 'UnUniFi (alpha-test)';

const bech32Prefix = {
accAddr: 'ununifi',
Expand Down Expand Up @@ -170,7 +169,7 @@ const configs = [
'http',
'ws',
)}//${domainCauchyEC}:${websocketPort}`,
chainID: 'ununifi-8-private-test',
chainID,
bech32Prefix,
minimumGasPrices: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IAuctionInfrastructure } from './auction.service';
import { Injectable } from '@angular/core';
import { cosmosclient, proto } from '@cosmos-client/core';
import { InlineResponse20075 } from '@cosmos-client/core/esm/openapi';
import Long from 'long';
import { ununifi } from 'ununifi-client';

@Injectable({
Expand Down Expand Up @@ -101,7 +102,7 @@ export class AuctionInfrastructureService implements IAuctionInfrastructure {
amount: proto.cosmos.base.v1beta1.ICoin,
): ununifi.auction.MsgPlaceBid {
const msgPlaceBid = new ununifi.auction.MsgPlaceBid({
auction_id: cosmosclient.Long.fromNumber(auctionID),
auction_id: Long.fromNumber(auctionID),
bidder: bidder,
amount: amount,
});
Expand Down
61 changes: 41 additions & 20 deletions projects/portal/src/app/models/cdps/cdp.infrastructure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ICdpInfrastructure } from './cdp.service';
import { Injectable } from '@angular/core';
import { cosmosclient, proto, rest } from '@cosmos-client/core';
import { InlineResponse20075 } from '@cosmos-client/core/esm/openapi';
import Long from 'long';
import { CosmosSDKService } from 'projects/portal/src/app/models/cosmos-sdk.service';
import { ununifi } from 'ununifi-client';

Expand Down Expand Up @@ -87,7 +88,11 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
// get account info
const account = await rest.auth
.account(sdk.rest, sender)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((_) => undefined);

const baseAccount = convertUnknownAccountToBaseAccount(account);
Expand All @@ -105,12 +110,12 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
});

const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgCreateCdp)],
messages: [cosmosclient.codec.instanceToProtoAny(msgCreateCdp)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
Expand All @@ -121,7 +126,7 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
],
fee: {
amount: [fee],
gas_limit: cosmosclient.Long.fromString(gas.amount ? gas.amount : '300000'),
gas_limit: Long.fromString(gas.amount ? gas.amount : '300000'),
},
});

Expand Down Expand Up @@ -195,7 +200,11 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
// get account info
const account = await rest.auth
.account(sdk.rest, sender)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((_) => undefined);

const baseAccount = convertUnknownAccountToBaseAccount(account);
Expand All @@ -211,12 +220,12 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
});

const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgDrawDebt)],
messages: [cosmosclient.codec.instanceToProtoAny(msgDrawDebt)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
Expand All @@ -227,7 +236,7 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
],
fee: {
amount: [fee],
gas_limit: cosmosclient.Long.fromString(gas.amount ? gas.amount : '300000'),
gas_limit: Long.fromString(gas.amount ? gas.amount : '300000'),
},
});

Expand Down Expand Up @@ -301,7 +310,11 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
// get account info
const account = await rest.auth
.account(sdk.rest, sender)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((_) => undefined);

const baseAccount = convertUnknownAccountToBaseAccount(account);
Expand All @@ -317,12 +330,12 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
});

const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgRepayDebt)],
messages: [cosmosclient.codec.instanceToProtoAny(msgRepayDebt)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
Expand All @@ -333,7 +346,7 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
],
fee: {
amount: [fee],
gas_limit: cosmosclient.Long.fromString(gas.amount ? gas.amount : '300000'),
gas_limit: Long.fromString(gas.amount ? gas.amount : '300000'),
},
});

Expand Down Expand Up @@ -412,7 +425,11 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
// get account info
const account = await rest.auth
.account(sdk.rest, sender)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((_) => undefined);

const baseAccount = convertUnknownAccountToBaseAccount(account);
Expand All @@ -430,12 +447,12 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
});

const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgDepositCDP)],
messages: [cosmosclient.codec.instanceToProtoAny(msgDepositCDP)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
Expand All @@ -446,7 +463,7 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
],
fee: {
amount: [fee],
gas_limit: cosmosclient.Long.fromString(gas.amount ? gas.amount : '300000'),
gas_limit: Long.fromString(gas.amount ? gas.amount : '300000'),
},
});

Expand Down Expand Up @@ -525,7 +542,11 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
// get account info
const account = await rest.auth
.account(sdk.rest, sender)
.then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account))
.then((res) =>
cosmosclient.codec.protoJSONToInstance(
cosmosclient.codec.castProtoJSONOfProtoAny(res.data?.account),
),
)
.catch((_) => undefined);

const baseAccount = convertUnknownAccountToBaseAccount(account);
Expand All @@ -543,12 +564,12 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
});

const txBody = new proto.cosmos.tx.v1beta1.TxBody({
messages: [cosmosclient.codec.packAny(msgWithdraw)],
messages: [cosmosclient.codec.instanceToProtoAny(msgWithdraw)],
});
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
signer_infos: [
{
public_key: cosmosclient.codec.packAny(pubKey),
public_key: cosmosclient.codec.instanceToProtoAny(pubKey),
mode_info: {
single: {
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
Expand All @@ -559,7 +580,7 @@ export class CdpInfrastructureService implements ICdpInfrastructure {
],
fee: {
amount: [fee],
gas_limit: cosmosclient.Long.fromString(gas.amount ? gas.amount : '300000'),
gas_limit: Long.fromString(gas.amount ? gas.amount : '300000'),
},
});

Expand Down
Loading

0 comments on commit 568081e

Please sign in to comment.