Skip to content

Commit

Permalink
fix: ui issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Mar 10, 2023
1 parent 551a29a commit 15e2466
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 34 deletions.
11 changes: 8 additions & 3 deletions packages/adena-extension/src/common/utils/client-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,16 @@ const fetchFavicon = async (hostname: string) => {
let response = null;

response = await fetchArrayData(`https://${hostname}/apple-touch-icon.png`);
console.log("apple");
if (response?.data) {
return response.data;
}

response = await fetchArrayData(`https://${hostname}/favicon.ico`);
console.log("favicon");
if (response?.data) {
return response.data;
}

response = await fetchArrayData(`https://www.google.com/s2/favicons?domain=${hostname}&sz=256`);
console.log("Google API");
if (response?.data) {
return response.data;
}
Expand Down Expand Up @@ -314,6 +311,14 @@ const isFailedReceive = (cur: any) => {
return cur.func === 'Received' && cur.result.status === 'Failed';
};

// TODO: CHECK SSL
export const getSiteName = (hostname: string | undefined) => {
if (!hostname) {
return "-";
}
return hostname.replace("www.", "");
};

export const optimizeNumber = (value: BigNumber, multiply: BigNumber) => {
const decimalPosition = multiply.toString().indexOf('.');
const decimalLength = decimalPosition > -1 ? `${multiply}`.substring(decimalPosition).length : 0;
Expand Down
7 changes: 4 additions & 3 deletions packages/adena-extension/src/inject/message/methods/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encodeParameter } from '@common/utils/client-utils';
import { encodeParameter, getSiteName } from '@common/utils/client-utils';
import { InjectionMessage, InjectionMessageInstance } from '../message';
import { InjectCore } from './core';

Expand All @@ -10,7 +10,7 @@ export const createPopup = async (
) => {
const popupOption: chrome.windows.CreateData = {
url: chrome.runtime.getURL(
`popup.html#${popupPath}?key=${message.key}&hostname=${message.hostname}&data=${encodeParameter(message)}`,
`popup.html#${popupPath}?key=${message.key}&url=${message.url}&hostname=${message.hostname}&data=${encodeParameter(message)}`,
),
type: 'popup',
height: 590,
Expand Down Expand Up @@ -63,7 +63,8 @@ export const checkEstablished = async (
const core = new InjectCore();

const address = await core.accountService.getCurrentAccountAddress();
const isEstablished = await core.establishService.isEstablished(requestData.hostname ?? '', address);
const siteName = getSiteName(requestData.hostname);
const isEstablished = await core.establishService.isEstablished(siteName, address);
if (!isEstablished) {
sendResponse(InjectionMessageInstance.failure('NOT_CONNECTED', requestData, requestData.key));
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSiteName } from '@common/utils/client-utils';
import { RoutePath } from '@router/path';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';
import { GnoClient } from 'gno-client';
Expand Down Expand Up @@ -47,7 +48,8 @@ export const addEstablish = async (

const isLocked = await core.walletService.isLocked();
const address = await core.accountService.getCurrentAccountAddress();
const isEstablised = await core.establishService.isEstablished(message.hostname ?? '', address);
const siteName = getSiteName(message.hostname);
const isEstablised = await core.establishService.isEstablished(siteName, address);

if (isLocked) {
HandlerMethod.createPopup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Text from '@components/text';
import styled from 'styled-components';
import { CopyTooltip } from '@components/tooltips';
import { StatusDot } from '@components/status-dot';
import { formatAddress, formatNickname, parseParmeters } from '@common/utils/client-utils';
import { formatAddress, formatNickname, getSiteName, parseParmeters } from '@common/utils/client-utils';
import { useCurrentAccount } from '@hooks/use-current-account';
import { useLocation } from 'react-router-dom';
import { useAdenaContext } from '@hooks/use-context';
Expand Down Expand Up @@ -65,7 +65,8 @@ const ApproveMenu = () => {
const updateEstablishState = async () => {
if (requestData?.hostname) {
const address = currentAccount?.getAddress() ?? "";
const currentIsEstablished = await establishService.isEstablished(requestData?.hostname, address);
const siteName = getSiteName(requestData.hostname);
const currentIsEstablished = await establishService.isEstablished(siteName, address);
setIsEstablished(currentIsEstablished);
}
};
Expand Down
24 changes: 14 additions & 10 deletions packages/adena-extension/src/layouts/header/top-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StatusDot } from '@components/status-dot';
import { HamburgerMenuBtn } from '@components/buttons/hamburger-menu-button';
import SubMenu from '@layouts/sub-menu';
import { useCurrentAccount } from '@hooks/use-current-account';
import { formatAddress, formatNickname } from '@common/utils/client-utils';
import { formatAddress, formatNickname, getSiteName } from '@common/utils/client-utils';
import { useLocation } from 'react-router-dom';
import { useAdenaContext } from '@hooks/use-context';

Expand All @@ -28,18 +28,11 @@ const Header = styled.div`
}
`;

const tooltipTextMaker = (hostname: string, isEstablish: boolean): string => {
let currentHostname = hostname;
if (!hostname.includes('.')) {
currentHostname = 'chrome-extension';
}
return isEstablish ? `You are connected to ${currentHostname}` : `You are not connected to ${currentHostname}`;
}

export const TopMenu = ({ disabled }: { disabled?: boolean }) => {
const { establishService } = useAdenaContext();
const [open, setOpen] = useState(false);
const [hostname, setHostname] = useState('');
const [url, setUrl] = useState('');
const [currentAccount] = useCurrentAccount();
const toggleMenuHandler = () => setOpen(!open);
const [isEstablish, setIsEstablish] = useState(false);
Expand All @@ -54,8 +47,10 @@ export const TopMenu = ({ disabled }: { disabled?: boolean }) => {
useEffect(() => {
getCurrentUrl().then(async (currentUrl) => {
const hostname = new URL(currentUrl as string).hostname;
const href = new URL(currentUrl as string).href;
if (hostname !== "") {
setHostname(hostname);
setUrl(href);
}
});
}, [location]);
Expand All @@ -68,10 +63,19 @@ export const TopMenu = ({ disabled }: { disabled?: boolean }) => {
setCurrentAccountAddress(address ?? "");
setCurrentAccountName(name ?? '');

const isEstablished = await establishService.isEstablished(hostname, address);
const siteName = getSiteName(hostname);
const isEstablished = await establishService.isEstablished(siteName, address);
setIsEstablish(isEstablished);
};

const tooltipTextMaker = (hostname: string, isEstablish: boolean): string => {
let currentHostname = hostname;
if (!hostname.includes('.')) {
currentHostname = 'chrome-extension';
}
return isEstablish ? `You are connected to ${currentHostname}` : `You are not connected to ${currentHostname}`;
}

const getCurrentUrl = () => {
return new Promise((resolver) => {
const queryOptions = { active: true, lastFocusedWindow: true };
Expand Down
3 changes: 2 additions & 1 deletion packages/adena-extension/src/pages/certify/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const Login = () => {
}
await walletService.updatePassowrd(password);
await loadAccounts();
navigate(RoutePath.Home);
navigate(RoutePath.Wallet);
return;
}
} catch (e) {
setValidateState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const useLogin = () => {

const tryLogin = async (password: string) => {
const equalPassword = await walletService.equalsPassowrd(password);
console.log("equalPassword", equalPassword)
if (equalPassword) {
await walletService.updatePassowrd(password);
setState("LOADING");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import theme from '@styles/theme';
import {
createFaviconByHostname,
decodeParameter,
getSiteName,
parseParmeters,
} from '@common/utils/client-utils';
import { InjectionMessageInstance } from '@inject/message';
Expand All @@ -21,6 +22,7 @@ export const ApproveEstablish = () => {
const [key, setKey] = useState<string>('');
const [appName, setAppName] = useState<string>('');
const [hostname, setHostname] = useState<string>('');
const [url, setUrl] = useState<string>('');
const [favicon, setFavicon] = useState<string | null>(null);
const location = useLocation();

Expand All @@ -37,8 +39,10 @@ export const ApproveEstablish = () => {
const initRequestSite = async () => {
try {
const data = parseParmeters(location.search);
console.log(data)
setKey(data['key']);
setHostname(data['hostname']);
setUrl(data['url']);
updateFavicon(data['hostname']);
if (data?.data) {
const message = decodeParameter(data.data);
Expand All @@ -50,8 +54,9 @@ export const ApproveEstablish = () => {
};

const checkEstablised = async () => {
const siteName = getSiteName(hostname);
const address = currentAccount?.getAddress() ?? '';
const isEstablised = await establishService.isEstablished(hostname ?? '', address);
const isEstablised = await establishService.isEstablished(siteName, address);
if (isEstablised) {
chrome.runtime.sendMessage(InjectionMessageInstance.failure('ALREADY_CONNECTED', {}, key));
return;
Expand All @@ -68,8 +73,9 @@ export const ApproveEstablish = () => {
};

const onClickConfirmButton = async () => {
const siteName = getSiteName(hostname);
const address = currentAccount?.getAddress() ?? '';
await establishService.establish(hostname, address, appName, favicon);
await establishService.establish(siteName, address, appName, favicon);
chrome.runtime.sendMessage(InjectionMessageInstance.success('CONNECTION_SUCCESS', {}, key));
};

Expand All @@ -80,7 +86,7 @@ export const ApproveEstablish = () => {
</Text>
<img className='logo' src={favicon !== null ? favicon : DefaultFavicon} alt='gnoland-logo' />
<UrlBox>
<Text type='body2Reg'>{hostname}</Text>
<Text type='body2Reg'>{getSiteName(hostname)}</Text>
</UrlBox>
<AllowSiteWrap>
<Text className='allow-title' type='body2Bold' color={theme.color.neutral[9]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const WalletCreate = () => {
loadAccounts();
break;
case 'FINISH':
navigate(RoutePath.Wallet);
window.location.replace("popup.html#" + RoutePath.Wallet);
break;
case 'LOGIN':
navigate(RoutePath.Login);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useLayoutEffect } from 'react';
import styled from 'styled-components';
import Text from '@components/text';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const WalletMain = () => {
updateAccountBalances();
}, []);

useEffect(() => {
useLayoutEffect(() => {
if (currentAccount && gnoClient) {
updateLastHistory();
updateBalances();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class TransactionService {
await this.createTransactionAccount(account);
const chainId = this.gnoClient.chainId;
const gasAmount = await this.getGasAmount(gasFee);
console.log("currentAccount", currentAccount);
const document = Transaction.generateDocument(
currentAccount,
chainId,
Expand All @@ -87,7 +86,6 @@ export class TransactionService {
.signatures([transactionSignature])
.memo('')
.build();
console.log(document)
const transactionValue = uint8ArrayToArray(transaction.encodedValue);
return transactionValue;
};
Expand Down Expand Up @@ -267,7 +265,6 @@ export class TransactionService {
gasAmount,
memo
);
console.log("????")
const signAminoResponse = currentAccount.getSigner()?.signAmino(accountAddress, signedDocumnet);
return signAminoResponse;
};
Expand Down
12 changes: 8 additions & 4 deletions packages/adena-extension/src/services/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ export class WalletService {
const encryptedPassword = encryptSha256Password(password);
return storedPassword === encryptedPassword;
}

// For migration
const wallet = await this.deserializeWallet(password);
if (wallet) {
await this.updatePassowrd(password);
return true;
const isWallet = await this.existsWallet();
if (isWallet) {
const wallet = await this.deserializeWallet(password);
if (wallet) {
await this.updatePassowrd(password);
return true;
}
}
} catch (e) {
return false;
Expand Down

0 comments on commit 15e2466

Please sign in to comment.