Skip to content

Commit

Permalink
Removed direct background service imports
Browse files Browse the repository at this point in the history
Closes #298
  • Loading branch information
tombeckenham committed Dec 18, 2024
1 parent d895b0e commit 9b3d7f5
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RLP from 'rlp';
import Web3 from 'web3';
import { stringToHex } from 'web3-utils';

import { signWithKey } from '@/background/utils/modules/publicPrivateKey';
import { ensureEvmAddressPrefix, isValidEthereumAddress } from '@/shared/utils/address';
import {
permissionService,
Expand All @@ -22,9 +23,6 @@ import { storage } from '../../webapi';
import BaseController from '../base';
import Wallet from '../wallet';

// eslint-disable-next-line import/order
import { signWithKey } from '@/background/utils/modules/publicPrivateKey';

interface Web3WalletPermission {
// The name of the method corresponding to the permission
parentCapability: string;
Expand Down
10 changes: 10 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ export class WalletController extends BaseController {
const { origin } = sessionService.getSession(tabId) || {};
return permissionService.getWithoutUpdate(origin);
};
addConnectedSite = (
origin: string,
name: string,
icon: string,
defaultChain = 747,
isSigned = false
) => {
permissionService.addConnectedSite(origin, name, icon, defaultChain, isSigned);
};

updateConnectSite = (origin: string, data: ConnectedSite) => {
permissionService.updateConnectSite(origin, data);
// sessionService.broadcastEvent(
Expand Down
2 changes: 1 addition & 1 deletion src/background/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import packageJson from '@/../package.json';
import { storage } from '@/background/webapi';

const { version } = packageJson;
import { mixpanelTrack } from '../service';
import { mixpanelTrack } from '../service/mixpanel';
import pageStateCache from '../service/pageStateCache';

export { default as createPersistStore } from './persisitStore';
Expand Down
3 changes: 1 addition & 2 deletions src/ui/views/Approval/components/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useCallback, useEffect, useState } from 'react';

import { storage } from '@/background/webapi';
import { authnServiceDefinition, serviceDefinition } from 'background/controller/serviceDefinition';
import { permissionService } from 'background/service';
import flowgrey from 'ui/FRWAssets/svg/flow-grey.svg';
import Link from 'ui/FRWAssets/svg/link.svg';
import linkGlobe from 'ui/FRWAssets/svg/linkGlobe.svg';
Expand Down Expand Up @@ -97,7 +96,7 @@ const Connect = ({ params: { /*icon, origin,*/ tabId } }: ConnectProps) => {
chainId = 747;
}
console.log('permission add ', host, title, logo, chainId);
permissionService.addConnectedSite(host, title, logo, chainId);
wallet.addConnectedSite(host, title, logo, chainId);

if (appIdentifier && nonce) {
const message = WalletUtils.encodeAccountProof({
Expand Down
3 changes: 1 addition & 2 deletions src/ui/views/EvmMove/MoveFromChild/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Box, Button, Typography, Drawer, IconButton, Grid } from '@mui/material
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

import wallet from '@/background/controller/wallet';
import { isValidEthereumAddress, withPrefix } from '@/shared/utils/address';
import { WarningStorageLowSnackbar } from '@/ui/FRWComponent/WarningStorageLowSnackbar';
import { useStorageCheck } from '@/ui/utils/useStorageCheck';
Expand Down Expand Up @@ -159,7 +158,7 @@ const MoveFromChild = (props: TransferConfirmationProps) => {

const moveToken = useCallback(async () => {
setLoading(true);
const tokenResult = await wallet.openapi.getTokenInfo(currentCoin, network);
const tokenResult = await usewallet.openapi.getTokenInfo(currentCoin, network);
usewallet
.moveFTfromChild(childUserInfo!.address, 'flowTokenProvider', amount!, tokenResult!.name)
.then(async (createRes) => {
Expand Down
3 changes: 1 addition & 2 deletions src/ui/views/EvmMove/MoveFromEvm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Box, Button, Typography, Drawer, IconButton, Grid } from '@mui/material
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

import wallet from '@/background/controller/wallet';
import { isValidEthereumAddress, withPrefix } from '@/shared/utils/address';
import { WarningStorageLowSnackbar } from '@/ui/FRWComponent/WarningStorageLowSnackbar';
import { useStorageCheck } from '@/ui/utils/useStorageCheck';
Expand Down Expand Up @@ -164,7 +163,7 @@ const MoveFromEvm = (props: TransferConfirmationProps) => {

const bridgeToken = async () => {
setLoading(true);
const tokenResult = await wallet.openapi.getEvmTokenInfo(currentCoin, network);
const tokenResult = await usewallet.openapi.getEvmTokenInfo(currentCoin, network);

let flowId = tokenResult!['flowIdentifier'];

Expand Down
3 changes: 1 addition & 2 deletions src/ui/views/EvmMove/MoveFromFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Box, Button, Typography, Drawer, IconButton, Grid } from '@mui/material
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

import wallet from '@/background/controller/wallet';
import { withPrefix, isValidEthereumAddress } from '@/shared/utils/address';
import { WarningStorageLowSnackbar } from '@/ui/FRWComponent/WarningStorageLowSnackbar';
import { useStorageCheck } from '@/ui/utils/useStorageCheck';
Expand Down Expand Up @@ -177,7 +176,7 @@ const MoveFromFlow = (props: TransferConfirmationProps) => {

const bridgeToken = async () => {
setLoading(true);
const tokenResult = await wallet.openapi.getTokenInfo(currentCoin, network);
const tokenResult = await usewallet.openapi.getTokenInfo(currentCoin, network);
console.log('tokenResult ', tokenResult);
const address = tokenResult!.address.startsWith('0x')
? tokenResult!.address.slice(2)
Expand Down
3 changes: 1 addition & 2 deletions src/ui/views/EvmMove/MoveFromParent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ThemeProvider } from '@mui/material/styles';
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

import wallet from '@/background/controller/wallet';
import { isValidEthereumAddress, withPrefix } from '@/shared/utils/address';
import { WarningStorageLowSnackbar } from '@/ui/FRWComponent/WarningStorageLowSnackbar';
import { useStorageCheck } from '@/ui/utils/useStorageCheck';
Expand Down Expand Up @@ -160,7 +159,7 @@ const MoveFromParent = (props: TransferConfirmationProps) => {

const moveToken = async () => {
setLoading(true);
const tokenResult = await wallet.openapi.getTokenInfo(currentCoin, network);
const tokenResult = await usewallet.openapi.getTokenInfo(currentCoin, network);
console.log('tokenResult ', tokenResult);
usewallet
.moveFTfromChild(childUserInfo!.address, 'flowTokenProvider', amount!, tokenResult!.name)
Expand Down

0 comments on commit 9b3d7f5

Please sign in to comment.