Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: metamask support #194

Merged
merged 23 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4bafd61
chore: install web3 and metamask related npm packages and resolve bui…
YasunoriMATSUOKA May 27, 2022
d865086
feat: wip connect to metmask and sign with metamask
YasunoriMATSUOKA May 27, 2022
7d56c56
feat: connect metamask and get public key and address and sign with m…
YasunoriMATSUOKA May 30, 2022
017bb48
feat: connecting to metamask dialog
YasunoriMATSUOKA May 30, 2022
6792325
chore: remove unnecessary code and fix validation
YasunoriMATSUOKA May 30, 2022
dc4379a
feat: wip sign to cosmos sdk tx data with metamask and broadcast
YasunoriMATSUOKA May 31, 2022
ef2049c
chore: hardcode expected public key for debugging
YasunoriMATSUOKA Jun 1, 2022
d807abc
feat: fix to sign tx with personal sign
YasunoriMATSUOKA Jun 2, 2022
286f7db
fix: sign mode sign direct
YasunoriMATSUOKA Jun 3, 2022
7772466
fix: typo of sign mode
YasunoriMATSUOKA Jun 6, 2022
1e24c4a
fix: mistake on rebase
YasunoriMATSUOKA Jun 7, 2022
aeebd55
feat: sign and verify with ethers
YasunoriMATSUOKA Jun 7, 2022
3b5f959
fix: compile error
YasunoriMATSUOKA Jun 7, 2022
0d63c04
chore: bumps cosmos client to 0.45.4
YasunoriMATSUOKA Jun 7, 2022
dc19bcc
fix: use canonicalize json and convert tx json args from number to st…
YasunoriMATSUOKA Jun 7, 2022
4d356f4
feat: latest-cosmos-client-for-metamask
kimurayu45z Jun 9, 2022
6b6efe3
fix: tiny refactor
kimurayu45z Jun 9, 2022
62441ff
fix: explorer build
kimurayu45z Jun 9, 2022
960fb0c
fix: protoJSON null problem
kimurayu45z Jun 9, 2022
dfd8c75
feat: fix long problem
kimurayu45z Jun 10, 2022
60b63b0
feat: metamask successfully sent
kimurayu45z Jun 10, 2022
169de99
feat: refactor bank service
kimurayu45z Jun 11, 2022
e676d39
fix: config js
YasunoriMATSUOKA Jun 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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