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

Remove inbox stake swap #466

Merged
merged 9 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
264 changes: 0 additions & 264 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
googleDriveService,
passwordService,
flownsService,
stakingService,
proxyService,
newsService,
mixpanelTrack,
Expand Down Expand Up @@ -1049,12 +1048,6 @@ export class WalletController extends BaseController {

return wallet;
};
fetchFlownsInbox = async () => {
const info = await userInfoService.getUserInfo();
const res = await openapiService.getFlownsInbox(info.username);

return res;
};

setPopStat = async (stat: boolean) => {
const network = await this.getNetwork();
Expand Down Expand Up @@ -1272,25 +1265,6 @@ export class WalletController extends BaseController {
}
};

fetchTokenList = async (_expiry = 5000) => {
const network = await this.getNetwork();
try {
const now = new Date();
const exp = _expiry + now.getTime();
coinListService.setExpiry(exp);

const tokenList = await openapiService.getEnabledTokenList(network);
return tokenList;
} catch (err) {
if (err.message === 'Operation aborted') {
console.log('fetchTokenList operation aborted.');
} else {
console.error('fetchTokenList encountered an error:', err);
}
throw err;
}
};

fetchBalance = async ({ signal } = { signal: new AbortController().signal }) => {
const network = await this.getNetwork();
const tokenList = await openapiService.getEnabledTokenList(network);
Expand Down Expand Up @@ -1368,7 +1342,6 @@ export class WalletController extends BaseController {
fetchCoinList = async (_expiry = 5000, { signal } = { signal: new AbortController().signal }) => {
const network = await this.getNetwork();
try {
await this.fetchTokenList(_expiry);
await this.fetchBalance({ signal });

// const allTokens = await openapiService.getAllTokenInfo();
Expand Down Expand Up @@ -2520,37 +2493,6 @@ export class WalletController extends BaseController {
);
};

claimNFTFromInbox = async (
domain: string,
itemId: string,
symbol: string,
root = 'meow'
): Promise<string> => {
const domainName = domain.split('.')[0];
const token = await openapiService.getNFTCollectionInfo(symbol);
if (!token) {
throw new Error(`Invaild token name - ${symbol}`);
}
const address = fcl.sansPrefix(token.address);
const key = `A.${address}.${symbol}.Collection`;
const script = await getScripts('domain', 'claimNFTFromInbox');

return await userWalletService.sendTransaction(
script
.replaceAll('<NFT>', token.contract_name)
.replaceAll('<NFTAddress>', token.address)
.replaceAll('<CollectionStoragePath>', token.path.storage_path)
.replaceAll('<CollectionPublicType>', token.path.public_type)
.replaceAll('<CollectionPublicPath>', token.path.public_path),
[
fcl.arg(domainName, t.String),
fcl.arg(root, t.String),
fcl.arg(key, t.String),
fcl.arg(itemId, t.UInt64),
]
);
};

enableTokenStorage = async (symbol: string) => {
const token = await openapiService.getTokenInfo(symbol);
if (!token) {
Expand Down Expand Up @@ -3161,113 +3103,6 @@ export class WalletController extends BaseController {
return txID;
};

sendInboxNFT = async (recipient: string, id: any, token: any): Promise<string> => {
const script = await getScripts('domain', 'sendInboxNFT');

const txID = await userWalletService.sendTransaction(
script
.replaceAll('<NFT>', token.contract_name)
.replaceAll('<NFTAddress>', token.address)
.replaceAll('<CollectionStoragePath>', token.path.storage_path)
.replaceAll('<CollectionPublicPath>', token.path.public_path),
[fcl.arg(recipient, t.Address), fcl.arg(parseInt(id), t.UInt64)]
);
mixpanelTrack.track('nft_transfer', {
tx_id: txID,
from_address: (await this.getCurrentAddress()) || '',
to_address: recipient,
nft_identifier: token.contract_name,
from_type: 'flow',
to_type: 'flow',
isMove: false,
});
return txID;
};

// SwapTokensForExactTokens
swapSend = async (
swapPaths,
tokenInMax,
tokenInVaultPath,
tokenOutSplit,
tokenOutVaultPath,
tokenOutReceiverPath,
tokenOutBalancePath,
deadline
): Promise<string> => {
await this.getNetwork();
// let SwapConfig = testnetCodes;

// if (network == 'mainnet') {
// SwapConfig = mainnetCodes;
// }

// const CODE = SwapConfig.Codes.Transactions.SwapTokensForExactTokens;
const CODE = await getScripts('swap', 'SwapTokensForExactTokens');

const tokenOutKey = swapPaths[swapPaths.length - 1];
const arr = tokenOutKey.split('.');
if (arr.length !== 3) {
throw Error(`Invalid TokenKey String, expect [A.address.name] got ${tokenOutKey}`);
}
const tokenName = arr[2];
const tokenAddress = `0x${arr[1]}`;
return await userWalletService.sendTransaction(
CODE.replaceAll('Token1Name', tokenName).replaceAll('Token1Addr', tokenAddress),
[
fcl.arg(swapPaths, t.Array(t.String)),
fcl.arg(tokenOutSplit, t.Array(t.UFix64)),
fcl.arg(tokenInMax.toFixed(8), t.UFix64),
fcl.arg(deadline.toFixed(8), t.UFix64),
fcl.arg({ domain: 'storage', identifier: tokenInVaultPath }, t.Path),
fcl.arg({ domain: 'storage', identifier: tokenOutVaultPath }, t.Path),
fcl.arg({ domain: 'public', identifier: tokenOutReceiverPath }, t.Path),
fcl.arg({ domain: 'public', identifier: tokenOutBalancePath }, t.Path),
]
);
};

// SwapExactTokensForTokens
sendSwap = async (
swapPaths,
tokenInSplit,
tokenInVaultPath,
tokenOutMin,
tokenOutVaultPath,
tokenOutReceiverPath,
tokenOutBalancePath,
deadline
): Promise<string> => {
await this.getNetwork();
// let SwapConfig = testnetCodes;
// if (network == 'mainnet') {
// SwapConfig = mainnetCodes;
// }
// const CODE = SwapConfig.Codes.Transactions.SwapExactTokensForTokens;
const CODE = await getScripts('swap', 'SwapExactTokensForTokens');

const tokenOutKey = swapPaths[swapPaths.length - 1];
const arr = tokenOutKey.split('.');
if (arr.length !== 3) {
throw Error(`Invalid TokenKey String, expect [A.adress.name] got ${tokenOutKey}`);
}
const tokenName = arr[2];
const tokenAddress = `0x${arr[1]}`;
return await userWalletService.sendTransaction(
CODE.replaceAll('Token1Name', tokenName).replaceAll('Token1Addr', tokenAddress),
[
fcl.arg(swapPaths, t.Array(t.String)),
fcl.arg(tokenInSplit, t.Array(t.UFix64)),
fcl.arg(tokenOutMin.toFixed(8), t.UFix64),
fcl.arg(deadline.toFixed(8), t.UFix64),
fcl.arg({ domain: 'storage', identifier: tokenInVaultPath }, t.Path),
fcl.arg({ domain: 'storage', identifier: tokenOutVaultPath }, t.Path),
fcl.arg({ domain: 'public', identifier: tokenOutReceiverPath }, t.Path),
fcl.arg({ domain: 'public', identifier: tokenOutBalancePath }, t.Path),
]
);
};

//transaction

getTransactions = async (
Expand Down Expand Up @@ -3874,25 +3709,6 @@ export class WalletController extends BaseController {
}
};

getSwapConfig = async () => {
const swapStorage = await storage.get('swapConfig');

const now = new Date();
const exp = 1000 * 60 * 60 * 1 + now.getTime();
if (swapStorage && swapStorage['expiry'] && now.getTime() <= swapStorage['expiry']) {
return swapStorage['data'];
}

const data = (await openapiService.getSwapInfo()) ?? false;
console.log('data expired ');
const swapConfig = {
data: data,
expiry: exp,
};
storage.set('swapConfig', swapConfig);
return data;
};

reset = async () => {
await keyringService.loadStore(undefined);
keyringService.store.subscribe((value) => storage.set('keyringState', value));
Expand Down Expand Up @@ -4038,86 +3854,6 @@ export class WalletController extends BaseController {
return resp;
};

nodeInfo = async (address) => {
const result = await stakingService.nodeInfo(address);
return result;
};

stakeInfo = async (address) => {
const result = await stakingService.stakeInfo(address);
return result;
};

delegateInfo = async (address) => {
const result = await stakingService.delegateInfo(address);
return result;
};

delegateStore = async () => {
const result = await stakingService.delegateStore();
return result;
};

createDelegator = async (amount, node) => {
const result = await stakingService.createDelegator(amount, node);
// Track delegation creation
mixpanelTrack.track('delegation_created', {
address: (await this.getCurrentAddress()) || '',
node_id: node,
amount: amount,
});
return result;
};

createStake = async (amount, node, delegate) => {
const result = await stakingService.createStake(amount, node, delegate);
return result;
};

withdrawReward = async (amount, node, delegate) => {
const result = await stakingService.withdrawReward(amount, node, delegate);
return result;
};

restakeReward = async (amount, node, delegate) => {
const result = await stakingService.restakeReward(amount, node, delegate);
return result;
};

restakeUnstaked = async (amount, node, delegate) => {
const result = await stakingService.restakeUnstaked(amount, node, delegate);
return result;
};

withdrawUnstaked = async (amount, node, delegate) => {
const result = await stakingService.withdrawUnstaked(amount, node, delegate);
return result;
};

unstake = async (amount, node, delegate) => {
const result = await stakingService.unstake(amount, node, delegate);
return result;
};

getApr = async () => {
const result = await stakingService.getApr();
return result;
};

checkStakingSetup = async (address) => {
return await stakingService.checkSetup(address);
};

setupDelegator = async (address) => {
const result = await stakingService.setup(address);
return result;
};

checkCrescendo = async () => {
const result = await userWalletService.checkCrescendo();
return result;
};

getAccount = async (): Promise<FclAccount> => {
const address = await this.getCurrentAddress();
const account = await fcl.account(address!);
Expand Down
2 changes: 0 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
googleSafeHostService,
passwordService,
flownsService,
stakingService,
mixpanelTrack,
} from './service';
import { getFirbaseConfig } from './utils/firebaseConfig';
Expand Down Expand Up @@ -126,7 +125,6 @@ async function restoreAppState() {
await googleSafeHostService.init();
await passwordService.init();
await flownsService.init();
await stakingService.init();
await mixpanelTrack.init();
// rpcCache.start();

Expand Down
1 change: 0 additions & 1 deletion src/background/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export { default as nftService } from './nft';
export { default as googleDriveService } from './googleDrive';
export { default as googleSafeHostService } from './googleSafeHost';
export { default as flownsService } from './flowns';
export { default as stakingService } from './staking';
export { default as signTextHistoryService } from './signTextHistory';
export { default as i18n } from './i18n';
export { default as newsService } from './news';
Expand Down
Loading