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

Indexeraddress #219

Merged
merged 70 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
102ebaf
feat: retrieve address from indexer
zzggo Sep 30, 2024
03b0af8
Merge branch 'han-dev' into indexeraddress
zzggo Nov 1, 2024
979939f
Merge branch 'han-dev' into indexeraddress
zzggo Nov 4, 2024
3b5cfb5
Merge branch 'han-dev' into indexeraddress
zzggo Nov 6, 2024
945b18e
Merge remote-tracking branch 'origin/master' into indexeraddress
zzggo Nov 7, 2024
f69e283
Merge remote-tracking branch 'origin/master' into indexeraddress
zzggo Nov 7, 2024
3e2aa93
fixed: address drawer balance update
zzggo Nov 7, 2024
ac164a8
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 8, 2024
a0aee34
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 11, 2024
c7baa44
fixed: indexaddresser emoji
zzggo Nov 11, 2024
526b4ff
feat: new ignore
zzggo Nov 12, 2024
7d8fb98
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 12, 2024
3f67ec2
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 12, 2024
531bc91
fixed: switching accounts
zzggo Nov 13, 2024
7657b9e
fixed: storage balance
zzggo Nov 14, 2024
91b54e7
Merge branch 'dev' into indexeraddress
zzggo Nov 18, 2024
36423fc
fixed: remove console
zzggo Nov 18, 2024
59c9f44
Merge branch 'dev' into indexeraddress
zzggo Nov 20, 2024
8e0daf5
Merge branch 'dev' into indexeraddress
zzggo Nov 21, 2024
4837dc0
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 21, 2024
0857dfb
Merge branch 'dev' into indexeraddress
zzggo Nov 22, 2024
76f9664
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 22, 2024
f6a3485
feat: indicator for parent address
zzggo Nov 22, 2024
0058719
Merge branch 'dev' into indexeraddress
zzggo Nov 26, 2024
09c7404
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 26, 2024
990e58e
Merge branch 'dev' into indexeraddress
zzggo Nov 26, 2024
3407018
Merge branch 'dev' into indexeraddress
zzggo Nov 28, 2024
64e520d
Merge branch 'dev' into indexeraddress
zzggo Nov 29, 2024
1f02352
fixed: parent directory merge and format update
zzggo Nov 29, 2024
aa06f59
fixed: merge utils
zzggo Nov 29, 2024
c05139e
fixed: update assets
zzggo Nov 29, 2024
dac2836
fixed: update page
zzggo Nov 29, 2024
3010b89
fixed: shared folder
zzggo Nov 29, 2024
28e32a5
fixed: content script page format
zzggo Nov 29, 2024
b7f9dbc
fixed: ui theme
zzggo Nov 29, 2024
4f9ea40
fixed: update icon
zzggo Nov 29, 2024
ef153c4
fixed: background utils
zzggo Nov 29, 2024
14a641d
fixed: service format
zzggo Nov 29, 2024
7d2a77f
fixed: update background
zzggo Nov 29, 2024
cfedf79
fixed: ui component
zzggo Nov 29, 2024
79c1e48
fixed: utils moduls
zzggo Nov 29, 2024
ca98635
fixed: utils
zzggo Nov 29, 2024
50ffe4e
fixed: ui views
zzggo Nov 30, 2024
484354f
fixed: format
zzggo Nov 30, 2024
e439b25
fixed: views format
zzggo Nov 30, 2024
909e5ec
fixed: ui
zzggo Nov 30, 2024
3fa89a4
fixed: ui views format
zzggo Nov 30, 2024
e9bfc9c
fixed: nft and move
zzggo Nov 30, 2024
7afe2a5
fixed: ui strucutre
zzggo Nov 30, 2024
1ac9249
fixed: pick username page function
zzggo Nov 30, 2024
9122919
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Nov 30, 2024
d81d987
fixed: commit error
zzggo Nov 30, 2024
a750d09
fixed: update message directory
zzggo Nov 30, 2024
340a685
fixed: remove unused ignore
zzggo Nov 30, 2024
514c44e
Merge branch 'dev' into indexeraddress
zzggo Dec 3, 2024
f3481f8
Merge remote-tracking branch 'origin/dev' into indexeraddress
zzggo Dec 3, 2024
183d0d1
feat: new dropdown menu for multiple account
zzggo Dec 3, 2024
508f1d4
fixed: register ui
zzggo Dec 4, 2024
84067da
fixed: register blackscreen
zzggo Dec 4, 2024
4f7830b
fixed: confirmation page popup
zzggo Dec 4, 2024
6dba80b
fixed: popup
zzggo Dec 4, 2024
8c7851c
fixed: confirmation spelling
zzggo Dec 4, 2024
9ca97d6
fixed: ui and sign dapp
zzggo Dec 5, 2024
a31de08
fixed: callback function emoji
zzggo Dec 5, 2024
02c5a99
fixed: hide arrow when only one address
zzggo Dec 5, 2024
d51b6bb
fixed: update bpicon and username
zzggo Dec 5, 2024
69229ca
fixed: remove console for fcl
zzggo Dec 6, 2024
3be4105
fixed: remove console
zzggo Dec 6, 2024
437a0cc
fixed: move child button
zzggo Dec 6, 2024
28e1487
fixed: move evm button
zzggo Dec 6, 2024
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
3 changes: 2 additions & 1 deletion src/background/controller/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cloneDeep from 'lodash/cloneDeep';

import { preferenceService, keyringService } from 'background/service';
import { Account } from 'background/service/preference';
import { type Account } from 'background/service/preference';

class BaseController {
getCurrentAccount = async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { TypedDataUtils, SignTypedDataVersion, normalize } from '@metamask/eth-s
import * as fcl from '@onflow/fcl';
import BigNumber from 'bignumber.js';
import { ethErrors } from 'eth-rpc-errors';
import { intToHex } from 'ethereumjs-util';
import { isHexString, intToHex } from 'ethereumjs-util';
import { ethers } from 'ethers';
import RLP from 'rlp';
import Web3 from 'web3';
import { stringToHex } from 'web3-utils';

import { ensureEvmAddressPrefix, isValidEthereumAddress } from '@/shared/utils/address';
import {
Expand Down Expand Up @@ -95,7 +96,6 @@ async function signMessage(msgParams, opts = {}) {
const hashAlgo = await storage.get('hashAlgo');
const signAlgo = await storage.get('signAlgo');
const keyindex = await storage.get('keyIndex');
console.log('keyindex ', [BigInt(keyindex)], account);
// const wallet = new ethers.Wallet(privateKey);
const signature = await signWithKey(signableData, signAlgo, hashAlgo, privateKey);

Expand Down Expand Up @@ -388,7 +388,7 @@ class ProviderController extends BaseController {
});
}
};
/*

// Should not be in controller
personalSign = async ({ data, approvalRes, session }) => {
if (!data.params) return;
Expand All @@ -403,7 +403,7 @@ class ProviderController extends BaseController {
});
return result;
};
*/

private _checkAddress = async (address) => {
return normalize(address).toLowerCase();
};
Expand Down
5 changes: 3 additions & 2 deletions src/background/controller/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ethErrors } from 'eth-rpc-errors';
import { tab } from 'background/webapi';

import { sessionService, keyringService, userWalletService } from 'background/service';
import { tab } from 'background/webapi';

import rpcFlow from './rpcFlow';
import internalMethod from './internalMethod';
import rpcFlow from './rpcFlow';

tab.on('tabRemove', (id) => {
sessionService.deleteSession(id);
Expand Down
1 change: 0 additions & 1 deletion src/background/controller/serviceDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// import { walletController } from './index';

Expand Down
167 changes: 112 additions & 55 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import web3, { TransactionError } from 'web3';
import eventBus from '@/eventBus';
import { isValidEthereumAddress, withPrefix } from '@/shared/utils/address';
import { getHashAlgo, getSignAlgo } from '@/shared/utils/algo';
// eslint-disable-next-line import/order,no-restricted-imports
import { findAddressWithNetwork } from '@/ui/utils/modules/findAddressWithPK';
import {
keyringService,
preferenceService,
Expand Down Expand Up @@ -280,7 +282,7 @@ export class WalletController extends BaseController {

// lockadd here
lockAdd = async () => {
const switchingTo = process.env.NODE_ENV === 'production' ? 'mainnet' : 'testnet';
const switchingTo = 'mainnet';

const password = keyringService.getPassword();
await storage.set('tempPassword', password);
Expand All @@ -294,7 +296,7 @@ export class WalletController extends BaseController {

// lockadd here
resetPwd = async () => {
const switchingTo = process.env.NODE_ENV === 'production' ? 'mainnet' : 'testnet';
const switchingTo = 'mainnet';
await storage.clear();

await keyringService.resetKeyRing();
Expand All @@ -308,7 +310,7 @@ export class WalletController extends BaseController {

// lockadd here
restoreWallet = async () => {
const switchingTo = process.env.NODE_ENV === 'production' ? 'mainnet' : 'testnet';
const switchingTo = 'mainnet';

const password = keyringService.getPassword();
await storage.set('tempPassword', password);
Expand Down Expand Up @@ -898,16 +900,16 @@ export class WalletController extends BaseController {
};

checkUserChildAccount = async () => {
const cacheKey = 'checkUserChildAccount';
const network = await this.getNetwork();
const address = await userWalletService.getMainWallet(network);
const cacheKey = `checkUserChildAccount${address}`;
const ttl = 5 * 60 * 1000; // 5 minutes in milliseconds

// Try to get the cached result
let meta = await storage.getExpiry(cacheKey);
if (!meta) {
try {
const network = await this.getNetwork();
let result = {};
const address = await userWalletService.getMainWallet(network);
result = await openapiService.checkChildAccountMeta(address);

if (result) {
Expand Down Expand Up @@ -1578,21 +1580,75 @@ export class WalletController extends BaseController {
//user wallets
refreshUserWallets = async () => {
const network = await this.getNetwork();
const active = await userWalletService.getActiveWallet();
const v2data = await openapiService.userWalletV2();
const filteredData = v2data.data.wallets.filter((item) => item.blockchain !== null);

const pubKey = await this.getPubKey();
const address = await findAddressWithNetwork(pubKey, network);
const emoji = await this.getEmoji();
if (!address) {
throw new Error("Can't find address in chain");
}
let transformedArray: any[];

// Check if the addresses array is empty
if (address.length === 0) {
// Add a placeholder blockchain item
transformedArray = [
{
id: 0,
name: 'flow',
chain_id: network,
icon: 'placeholder',
color: 'placeholder',
blockchain: [
{
id: 0,
name: 'Flow',
chain_id: network,
address: '0x00000000',
coins: ['flow'],
icon: '',
},
],
},
];
} else {
// Transform the address array into blockchain objects
transformedArray = address.map((item, index) => {
return {
id: 0,
name: emoji[index].name,
chain_id: network,
icon: emoji[index].emoji,
color: emoji[index].bgcolor,
blockchain: [
{
id: index,
name: emoji[index].name,
chain_id: network,
address: item.address,
coins: ['flow'],
icon: emoji[index].emoji,
color: emoji[index].bgcolor,
},
],
};
});
}

console.log('v2data ', transformedArray, address);
const active = await userWalletService.getActiveWallet();
if (!active) {
userInfoService.addUserId(v2data.data.id);
userWalletService.setUserWallets(filteredData, network);
// userInfoService.addUserId(v2data.data.id);
userWalletService.setUserWallets(transformedArray, network);
}

return filteredData;
return transformedArray;
};

getUserWallets = async (): Promise<WalletResponse[]> => {
const network = await this.getNetwork();
const wallets = await userWalletService.getUserWallets(network);
console.log('getUserWallets ', wallets);
if (!wallets[0]) {
await this.refreshUserWallets();
const data = await userWalletService.getUserWallets(network);
Expand All @@ -1619,11 +1675,11 @@ export class WalletController extends BaseController {
return activeWallet;
};

setActiveWallet = async (wallet: any, key: any) => {
setActiveWallet = async (wallet: any, key: any, index = null) => {
await userWalletService.setActiveWallet(key);

const network = await this.getNetwork();
await userWalletService.setCurrentWallet(wallet, key, network);
await userWalletService.setCurrentWallet(wallet, key, network, index);
};

hasCurrentWallet = async () => {
Expand All @@ -1633,6 +1689,7 @@ export class WalletController extends BaseController {

getCurrentWallet = async () => {
const wallet = await userWalletService.getCurrentWallet();
console.log('getCurrentWallet ', wallet);
if (!wallet.address) {
const network = await this.getNetwork();
await this.refreshUserWallets();
Expand All @@ -1648,7 +1705,8 @@ export class WalletController extends BaseController {
};

setEvmAddress = async (address) => {
await userWalletService.setEvmAddress(address);
const emoji = await this.getEmoji();
await userWalletService.setEvmAddress(address, emoji);
};

getEvmAddress = async () => {
Expand All @@ -1660,10 +1718,10 @@ export class WalletController extends BaseController {
getCurrentAddress = async () => {
const address = await userWalletService.getCurrentAddress();
if (!address) {
const data = this.refreshUserWallets();
const data = await this.refreshUserWallets();
return withPrefix(data[0].blockchain[0].address);
} else if (address.length < 3) {
const data = this.refreshUserWallets();
const data = await this.refreshUserWallets();
return withPrefix(data[0].blockchain[0].address);
}
return withPrefix(address);
Expand All @@ -1673,10 +1731,10 @@ export class WalletController extends BaseController {
const network = await this.getNetwork();
const address = await userWalletService.getMainWallet(network);
if (!address) {
const data = this.refreshUserWallets();
const data = await this.refreshUserWallets();
return withPrefix(data[0].blockchain[0].address);
} else if (address.length < 3) {
const data = this.refreshUserWallets();
const data = await this.refreshUserWallets();
return withPrefix(data[0].blockchain[0].address);
}
return withPrefix(address);
Expand Down Expand Up @@ -2192,8 +2250,24 @@ export class WalletController extends BaseController {
};

getFlowBalance = async (address) => {
const account = await fcl.send([fcl.getAccount(address!)]).then(fcl.decode);
return account.balance;
const cacheKey = `checkFlowBalance${address}`;
let balance = await storage.getExpiry(cacheKey);
const ttl = 1 * 60 * 1000;
if (!balance) {
try {
const account = await fcl.send([fcl.getAccount(address!)]).then(fcl.decode);
balance = account.balance;
if (balance) {
// Store the result in the cache with an expiry
await storage.setExpiry(cacheKey, balance, ttl);
}
} catch (error) {
console.error('Error occurred:', error);
return {}; // Return an empty object in case of an error
}
}

return balance;
};

getNonce = async (hexEncodedAddress: string): Promise<string> => {
Expand Down Expand Up @@ -3257,7 +3331,6 @@ export class WalletController extends BaseController {
refreshAll = async () => {
await this.refreshUserWallets();
this.clearNFT();
this.clearChildAccount();
this.refreshAddressBook();
this.refreshEvmWallets();
await this.getCadenceScripts();
Expand All @@ -3280,11 +3353,7 @@ export class WalletController extends BaseController {

getEvmEnabled = async (): Promise<boolean> => {
const address = await this.getEvmAddress();
if (isValidEthereumAddress(address)) {
return true;
} else {
return false;
}
return !!address && isValidEthereumAddress(address);
};

refreshEvmWallets = () => {
Expand Down Expand Up @@ -3946,44 +4015,32 @@ export class WalletController extends BaseController {

getEmoji = async () => {
const currentId = await storage.get('currentId');
let emojires = await storage.get(`${currentId}emoji`);
if (!emojires) {
const index1 = Math.floor(Math.random() * emoji.emojis.length);
let index2;
// let emojires = await storage.get(`${currentId}emoji`)
// if (!emojires) {
// const index1 = Math.floor(Math.random() * emoji.emojis.length);
// let index2;

do {
index2 = Math.floor(Math.random() * emoji.emojis.length);
} while (index1 === index2);
// do {
// index2 = Math.floor(Math.random() * emoji.emojis.length);
// } while (index1 === index2);

emojires = [emoji.emojis[index1], emoji.emojis[index2]];
storage.set(`${currentId}emoji`, emojires);
}
// emojires = [emoji.emojis[index1], emoji.emojis[index2]];
// storage.set(`${currentId}emoji`, emojires)
// }

return emojires;
return emoji.emojis;
};

setEmoji = async (emoji, type) => {
const currentId = await storage.get('currentId');
let emojires = await storage.get(`${currentId}emoji`);
if (!emojires) {
const index1 = Math.floor(Math.random() * emoji.emojis.length);
let index2;

do {
index2 = Math.floor(Math.random() * emoji.emojis.length);
} while (index1 === index2);
setEmoji = async (emoji, type, index) => {
const network = await this.getNetwork();

emojires = [emoji.emojis[index1], emoji.emojis[index2]];
}
if (type === 'evm') {
emojires[1] = emoji;
await userWalletService.setEvmEmoji(emoji);
} else {
emojires[0] = emoji;
await userWalletService.setWalletEmoji(emoji, network, index);
}

await storage.set(`${currentId}emoji`, emojires);

return emojires;
return emoji;
};

// Get the news from the server
Expand Down
2 changes: 1 addition & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const findPath = (service) => {
case 'authn':
return 'Connect';
case 'authz':
return 'Confimation';
return 'Confirmation';
case 'user-signature':
return 'SignMessage';
default:
Expand Down
3 changes: 2 additions & 1 deletion src/background/service/addressBook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createPersistStore } from 'background/utils';
import { Contact } from './networkModel';

import { type Contact } from './networkModel';

interface AddressBookStore {
addressBook: Record<string, Contact[]>;
Expand Down
1 change: 1 addition & 0 deletions src/background/service/googleSafeHost.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';

import { createPersistStore } from 'background/utils';

interface GoogleHostModel {
Expand Down
1 change: 1 addition & 0 deletions src/background/service/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18n from 'i18next';

import messages from '../../messages.json';

export const fetchLocale = async (locale) => {
Expand Down
Loading
Loading