Skip to content

Commit

Permalink
Release Adena version '1.7.4' (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss authored Jul 19, 2023
1 parent 872d459 commit 5104ccb
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adena-wallet",
"version": "1.7.3",
"version": "1.7.4",
"description": "Adena Wallet",
"license": "Adena License",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/adena-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adena-extension",
"version": "1.7.3",
"version": "1.7.4",
"private": true,
"description": "Adena is a friendly browser extension wallet for the Gnoland blockchain.",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/adena-extension/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Adena",
"description": "Adena Wallet",
"manifest_version": 3,
"version": "1.7.3",
"version": "1.7.4",
"action": {
"default_popup": "popup.html"
},
Expand All @@ -27,6 +27,6 @@
}
],
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; default-src 'self'; img-src 'self' https: data:; font-src https://fonts.gstatic.com; style-src 'self' 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net; connect-src 'self' data: https://* http://localhost:* http://127.0.0.1:*; prefetch-src https://*.openlogin.com; frame-src https://*;"
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; default-src 'self'; img-src 'self' https: data:; font-src https://fonts.gstatic.com; style-src 'self' 'unsafe-inline'; style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net; connect-src 'self' data: *; prefetch-src https://*.openlogin.com; frame-src *;"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export class GnoProvider extends GnoJSONRPCProvider {
} catch (e) {
console.error(e);
}
return defaultAccount;
return {
...defaultAccount,
address,
};
}

public getValueByEvaluteExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,13 @@ export const WalletProvider: React.FC<React.PropsWithChildren<unknown>> = ({ chi
async function changeNetwork(networkMetainfo: NetworkMetainfo) {
const rpcUrl = networkMetainfo.rpcUrl;
const gnoProvider = new GnoProvider(rpcUrl, networkMetainfo.networkId);
const currentNetwork = await gnoProvider.getStatus().then(status => ({
...networkMetainfo,
networkId: status.node_info.network
})).catch(() => networkMetainfo);
setCurrentNetwrok(currentNetwork);
setCurrentNetwrok(networkMetainfo);
setGnoProvider(gnoProvider);

accountService.setGnoProvider(gnoProvider);
balanceService.setGnoProvider(gnoProvider);
transactionService.setGnoProvider(gnoProvider);
return currentNetwork;
return networkMetainfo;
}

return (
Expand Down
12 changes: 12 additions & 0 deletions packages/adena-extension/src/common/utils/client-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import theme from '@styles/theme';
import axios from 'axios';
import BigNumber from 'bignumber.js';
import dayjs from 'dayjs';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';

export function formatAddress(v: string, num?: number): string {
const length = num ?? 4;
Expand Down Expand Up @@ -392,3 +393,14 @@ export const getDateTimeText = (date: string) => {
const formatDate = `${result.month} ${result.day}, ${result.year} ${result.time}`;
return formatDate;
};

export async function fetchHealth(url: string) {
const healthy = await axios
.get(url + '/health', { adapter: fetchAdapter, timeout: 5000 })
.then((response) => response.status === 200)
.catch(() => false);
return {
url,
healthy,
};
}
21 changes: 9 additions & 12 deletions packages/adena-extension/src/components/background/background.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useEffect } from "react";
import { useLocation } from "react-router-dom";
import { useRecoilState } from "recoil";
import axios from "axios";
import fetchAdapter from "@vespaiach/axios-fetch-adapter";
import { useCurrentAccount } from "@hooks/use-current-account";
import { useNetwork } from "@hooks/use-network";
import { useTokenMetainfo } from "@hooks/use-token-metainfo";
Expand All @@ -12,6 +10,7 @@ import { useAccountName } from "@hooks/use-account-name";
import { CommonState } from "@states/index";
import useScrollHistory from "@hooks/use-scroll-history";
import { NetworkMetainfo } from "@states/network";
import { fetchHealth } from "@common/utils/client-utils";

type BackgroundProps = React.PropsWithChildren<unknown>;

Expand Down Expand Up @@ -58,20 +57,18 @@ export const Background: React.FC<BackgroundProps> = ({ children }) => {
if (['NONE', 'CREATE', 'LOGIN'].includes(walletStatus)) {
return;
}
fetchHealth(currentNetwork);
}

async function fetchHealth(currentNetwork: NetworkMetainfo) {
const healthy = await axios.get(currentNetwork.rpcUrl + '/health', { adapter: fetchAdapter })
.then(response => response.status === 200)
.catch(() => false);
updateFailedNetwork(currentNetwork.id, !healthy);
fetchHealth(currentNetwork.rpcUrl).then(({ url, healthy }) => {
updateFailedNetwork(url, healthy);
});
}

function updateFailedNetwork(networkId: string, failed: boolean) {
function updateFailedNetwork(url: string, healthy: boolean) {
if (currentNetwork.rpcUrl !== url) {
return;
}
setFailedNetwork({
...failedNetwork,
[networkId]: failed
[currentNetwork.id]: !healthy
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DefaultFavicon from '@assets/favicon-default.svg';
import {
createFaviconByHostname,
decodeParameter,
fetchHealth,
getSiteName,
parseParmeters,
} from '@common/utils/client-utils';
Expand All @@ -13,6 +14,7 @@ import { useAdenaContext } from '@hooks/use-context';
import { useCurrentAccount } from '@hooks/use-current-account';
import { useNetwork } from '@hooks/use-network';
import { RoutePath } from '@router/path';
import axios from 'axios';

const ApproveEstablishContainer: React.FC = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -86,6 +88,12 @@ const ApproveEstablishContainer: React.FC = () => {
};

const establish = async () => {
const { url, healthy } = await checkHealth(currentNetwork.rpcUrl);
if (!healthy || url !== currentNetwork.rpcUrl) {
chrome.runtime.sendMessage(InjectionMessageInstance.failure('NETWORK_TIMEOUT', {}, key));
return;
}

const siteName = getSiteName(protocol, hostname);
const accountId = currentAccount?.id ?? '';
const networkId = currentNetwork.id ?? '';
Expand All @@ -101,6 +109,11 @@ const ApproveEstablishContainer: React.FC = () => {
chrome.runtime.sendMessage(InjectionMessageInstance.success('CONNECTION_SUCCESS', {}, key));
}

const checkHealth = async (rpcUrl: string) => {
const healthy = await fetchHealth(rpcUrl);
return healthy;
};

const onClickCancle = () => {
window.close();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import ApproveTransaction from '@components/approve/approve-transaction/approve-
import { useLocation, useNavigate } from 'react-router-dom';
import { useCurrentAccount } from '@hooks/use-current-account';
import { InjectionMessage, InjectionMessageInstance } from '@inject/message';
import { createFaviconByHostname, decodeParameter, parseParmeters } from '@common/utils/client-utils';
import { createFaviconByHostname, decodeParameter, fetchHealth, parseParmeters } from '@common/utils/client-utils';
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
import { StdSignDoc, Account, isLedgerAccount } from 'adena-module';
import { RoutePath } from '@router/path';
import { validateInjectionData } from '@inject/message/methods';
import BigNumber from 'bignumber.js';
import { useNetwork } from '@hooks/use-network';
import axios from 'axios';

function mappedTransactionData(document: StdSignDoc) {
return {
Expand All @@ -29,9 +28,7 @@ function mappedTransactionData(document: StdSignDoc) {
}

const checkHealth = (rpcUrl: string, requestKey?: string) => setTimeout(async () => {
const healthy = await axios.get(rpcUrl + '/health')
.then(response => response.status === 200)
.catch(() => false)
const { healthy } = await fetchHealth(rpcUrl);
if (healthy === false) {
chrome.runtime.sendMessage(
InjectionMessageInstance.failure('NETWORK_TIMEOUT', {}, requestKey),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WalletAccountService {
public getAccountInfoByProvider = async (address: string, gnoProvider: GnoProvider) => {
try {
const account = await gnoProvider.getAccount(address);
if (!account) {
if (account) {
return account;
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/adena-module/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adena-module",
"private": true,
"version": "1.7.3",
"version": "1.7.4",
"description": "Adena's Wallet",
"main": "./dist/index.umd.js",
"module": "./dist/index.esm.js",
Expand Down
12 changes: 11 additions & 1 deletion packages/adena-module/src/amino/signdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ function sortedObject(obj: any): any {
/** Returns a JSON string with objects sorted by key */
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function sortedJsonStringify(obj: any): string {
return JSON.stringify(sortedObject(obj));
const sortedJson = JSON.stringify(sortedObject(obj));
return encodeCharacterSet(sortedJson);
}

/**
* Escapes <,>,& in string.
* Golang's json marshaller escapes <,>,& by default.
* https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53
*/
function encodeCharacterSet(data: string) {
return data.replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/&/g, '\\u0026');
}

export function makeSignDoc(
Expand Down
87 changes: 87 additions & 0 deletions packages/adena-module/src/wallet/wallet-sign.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { AdenaWallet } from '.';

const mnemonic =
'source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast';

function makeDocument(body: string) {
return {
msgs: [
{
type: '/vm.m_addpkg',
value: {
creator: 'g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5',
deposit: '1ugnot',
package: {
Name: 'hello',
Path: 'gno.land/r/demo/hello',
Files: [
{
Name: 'hello.gno',
Body: body,
},
],
},
},
},
],
fee: {
amount: [
{
amount: '1',
denom: 'ugnot',
},
],
gas: '5000000',
},
chain_id: 'dev',
memo: '',
account_number: '0',
sequence: '1',
};
}

describe('Transaction Sign', () => {
it('default success', async () => {
const wallet = await AdenaWallet.createByMnemonic(mnemonic);
const body = 'package hello\n// test\n';
const documnet = makeDocument(body);
const signature = await wallet.sign(documnet);

expect(signature.signature.signature).toBe(
'NN3EWlM/M4bnkQlJtBTp6lDqcY3UsWlDuDdl3NKFtDRztl/hVyyg4sjaBZiYZoq6kjCAeLj5j5aqyETGr5PhiA==',
);
});

it('"&" includes success', async () => {
const wallet = await AdenaWallet.createByMnemonic(mnemonic);
const body = 'package hello\n\nfunc main() {\n // &\n}\n';
const documnet = makeDocument(body);
const signature = await wallet.sign(documnet);

expect(signature.signature.signature).toBe(
'fwoe2djDbqcNl0Nw0tPSIUJbij/+rzflTW50lbvWXOgog9hDr+LCZgnJroAyo/QcDo8O1t/l5PhCcxZldPLJow==',
);
});

it('">" includes success', async () => {
const wallet = await AdenaWallet.createByMnemonic(mnemonic);
const body = 'package hello\n\nfunc main() {\n // >\n}\n';
const documnet = makeDocument(body);
const signature = await wallet.sign(documnet);

expect(signature.signature.signature).toBe(
'5H5Dx+7g+m92T6+eSO+DTBYVWr7Wq/ok0mrgPuvuwxUKikBLkAQrS4aGx79sxv8lpxAfFCIFdZYk/pW7+vpB1Q==',
);
});

it('"<" includes success', async () => {
const wallet = await AdenaWallet.createByMnemonic(mnemonic);
const body = 'package hello\n\nfunc main() {\n // <\n}\n';
const documnet = makeDocument(body);
const signature = await wallet.sign(documnet);

expect(signature.signature.signature).toBe(
'RxjoXe8NwW+89vKNntbuEJ6ZvVBdytWCSbqfy7TtIztXpmcGDoPbWDIvOIZfZWKe2BJDG06MzvXd8Y8LvecKYg==',
);
});
});

0 comments on commit 5104ccb

Please sign in to comment.