From dcc90b9391ddac6b9e6578ac5a972c6864d36e5d Mon Sep 17 00:00:00 2001 From: karczuRF Date: Fri, 15 Nov 2024 18:12:16 +0100 Subject: [PATCH] celanup --- src-tauri/src/commands.rs | 5 +- src-tauri/src/lib.rs | 2 - src-tauri/src/rpc.rs | 11 +---- src/components/SelectAccount.tsx | 3 -- src/components/Tapplet.tsx | 1 - src/components/Wallet.tsx | 54 ++++----------------- src/helpers/address.ts | 4 +- src/provider/TariUniverseProvider.ts | 29 ++--------- src/provider/ipc_transport.ts | 1 - src/store/account/account.action.ts | 10 ++-- src/store/devTapplets/devTapplets.action.ts | 1 - src/store/provider/provider.action.ts | 9 +--- src/store/simulation/simulation.action.ts | 2 +- 13 files changed, 25 insertions(+), 107 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 430c564..f8ffa5a 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -59,9 +59,8 @@ pub async fn create_account(tokens: State<'_, Tokens>) -> Result<(), Error> { #[tauri::command] pub async fn get_free_coins(tokens: State<'_, Tokens>) -> Result<(), Error> { - println!("=============> get free coins"); // Use default account - let account_name = "tester".to_string(); + let account_name = "default".to_string(); let permission_token = tokens.permission .lock() .map_err(|_| FailedToObtainPermissionTokenLock)? @@ -92,7 +91,6 @@ pub async fn call_wallet( params: String, tokens: State<'_, Tokens> ) -> Result { - println!("======== HELLO THERE CALL WALLET {:?}", method); let permission_token = tokens.permission .lock() .map_err(|_| FailedToObtainPermissionTokenLock)? @@ -103,7 +101,6 @@ pub async fn call_wallet( make_request(Some(permission_token), method, req_params).await }); let response = handle.await?.map_err(|_| Error::ProviderError { method: method_clone, params })?; - println!("======== HELLO THERE CALL WALLET RESPOSNE {:?}", response); Ok(response) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 73d0519..0c49e1a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -69,12 +69,10 @@ async fn try_get_tokens() -> (String, String) { loop { match permission_token().await { Ok(tokens) => { - println!("permission token ok {:?}", tokens); info!(target: LOG_TARGET, "permission token ok {:?}", tokens); return tokens; } Err(e) => { - println!("permission token ERR {:?}", e); warn!(target: LOG_TARGET, "permission token ERR {:?}", e); sleep(Duration::from_millis(500)); continue; diff --git a/src-tauri/src/rpc.rs b/src-tauri/src/rpc.rs index 8a67cee..a86d4bd 100644 --- a/src-tauri/src/rpc.rs +++ b/src-tauri/src/rpc.rs @@ -42,15 +42,13 @@ pub async fn permission_token() -> Result<(String, String), anyhow::Error> { pub async fn account_create(account_name: Option, permissions_token: String) -> Result<(), anyhow::Error> { let create_acc_params = AccountsCreateRequest { - account_name: Some("User".to_string()), + account_name, custom_access_rules: None, is_default: false, key_id: None, max_fee: None, }; - println!("----------- REQEST {:?}", create_acc_params); let resp = make_request(Some(permissions_token), "accounts.create".to_string(), create_acc_params).await?; - println!("----------- REQEST resp {:?}", resp); Ok(()) } @@ -62,13 +60,11 @@ pub async fn free_coins(account_name: Option, permissions_token: String) max_fee: None, key_id: None, }; - println!("----------- REQEST free test coins {:?}", free_coins_params); - let resp = make_request( + let _resp = make_request( Some(permissions_token), "accounts.create_free_test_coins".to_string(), free_coins_params ).await?; - println!("----------- REQEST resp {:?}", resp); Ok(()) } @@ -111,10 +107,7 @@ pub async fn make_request( if let Some(token) = token { builder = builder.header(AUTHORIZATION, format!("Bearer {token}")); } - println!("------- JSON REQ BODY "); - println!("{:?}", &body); let resp = builder.json(&body).send().await?.json::().await?; - println!("------- JSON RESPONSE {:?} ", resp.result); match resp.result { JsonRpcAnswer::Result(result) => Ok(result), JsonRpcAnswer::Error(error) => Err(anyhow::Error::msg(error.to_string())), diff --git a/src/components/SelectAccount.tsx b/src/components/SelectAccount.tsx index 2c9b5b0..5bb7d16 100644 --- a/src/components/SelectAccount.tsx +++ b/src/components/SelectAccount.tsx @@ -22,7 +22,6 @@ function SelectAccount({ onSubmit, accountsList }: SelectAccountProps) { const [newAccountName, setNewAccountName] = useState("") const handleChange = (event: SelectChangeEvent) => { - console.log("TODO: set active account from the list") dispatch( accountActions.setAccountRequest({ accountName: event.target.value, @@ -31,12 +30,10 @@ function SelectAccount({ onSubmit, accountsList }: SelectAccountProps) { } const handleSubmit = useCallback(async () => { - console.log("submit handle new account", newAccountName) return onSubmit(newAccountName) }, [newAccountName, onSubmit]) const onAddAccountChange = (e: React.ChangeEvent) => { - console.log(accountsList) setNewAccountName(e.target.value) } diff --git a/src/components/Tapplet.tsx b/src/components/Tapplet.tsx index dadc74a..3b9c731 100644 --- a/src/components/Tapplet.tsx +++ b/src/components/Tapplet.tsx @@ -9,7 +9,6 @@ type TappletProps = { export const Tapplet: React.FC = ({ source }) => { const tappletRef = useRef(null) const provider = useSelector(providerSelector.selectProvider) - console.log(">>>>>>>>>>> PROVIDER", provider) function sendWindowSize() { if (tappletRef.current) { diff --git a/src/components/Wallet.tsx b/src/components/Wallet.tsx index b17ae5a..4403634 100644 --- a/src/components/Wallet.tsx +++ b/src/components/Wallet.tsx @@ -17,7 +17,6 @@ export const Wallet: React.FC = () => { const dispatch = useDispatch() const provider = useSelector(providerSelector.selectProvider) const currentAccount = useSelector(accountSelector.selectAccount) - // const [accountAddress, setAccountAddress] = useState("") const [accountsList, setAccountsList] = useState([]) useEffect(() => { @@ -25,11 +24,9 @@ export const Wallet: React.FC = () => { }, [provider]) const refreshAccount = useCallback(async () => { - console.log("fetch") try { - const { accounts, total } = await provider.getAccountsList() //TODO fix to get value not empty array + const { accounts } = await provider.getAccountsList() //TODO fix to get value not empty array - https://github.com/tari-project/tari-universe/issues/141 setAccountsList(accounts) - console.log(accountsList) } catch (error) { console.error(error) if (typeof error === "string") { @@ -40,20 +37,14 @@ export const Wallet: React.FC = () => { async function handleCreateAccount(accountName: string) { try { - const account = await provider.createFreeTestCoins(accountName) - console.log("HANDLE CREATE ACCOUNT", account) - const tst = await provider.client.accountsSetDefault({ - account: { - ComponentAddress: account.address, - }, - }) - console.log("HANDLE SET DEFAULT ACCOUNT", tst) + await provider.createFreeTestCoins(accountName) dispatch( accountActions.setAccountRequest({ accountName, }) ) } catch (error) { + console.error(error) if (typeof error === "string") { dispatch(errorActions.showError({ message: error, errorSource: ErrorSource.BACKEND })) } @@ -62,31 +53,11 @@ export const Wallet: React.FC = () => { async function get_free_coins() { try { - console.log("==================================================") - // needs to have account name - otherwise it throws error - if (!currentAccount) return const currentAccountName = currentAccount?.account.name ?? undefined - console.log(currentAccountName) - const account = await provider.createFreeTestCoins(currentAccountName) - // setAccountAddress(acc.address) - // dispatch( - // accountActions.setAccount({ - // account: { - // account: { - // name: account.address, - // address: account.address as any, - // key_index: account.account_id, - // is_default: true, - // }, - // public_key: account.public_key, - // }, - // }) - // ) - // console.log("GET ACCOUNT", acc) + await provider.createFreeTestCoins(currentAccountName) } catch (error) { - console.log("GET ACCOUNT ERROR", error) + console.error(error) if (typeof error === "string") { - console.log(error) dispatch(errorActions.showError({ message: error, errorSource: ErrorSource.BACKEND })) } } @@ -94,18 +65,11 @@ export const Wallet: React.FC = () => { async function get_balances() { try { - console.log("==================================================") - // const addr = (currentAccount && currentAccount.account.address as { Component: string }).Component, - const addr = currentAccount?.account.address as any - - console.log("get balances acc store", currentAccount) - console.log("get balances acc store", currentAccount?.account.address) - console.log("get balances acc store addr", addr) - // setBalances(await invoke("get_balances", {})) - const resp = await provider.getAccountBalances(addr) - console.log("get balances resp", resp) + const accountAddress = substateIdToString(currentAccount?.account.address ?? null) + const resp = await provider.getAccountBalances(accountAddress) setBalances(resp.balances) } catch (error) { + console.error(error) if (typeof error === "string") { dispatch(errorActions.showError({ message: error, errorSource: ErrorSource.BACKEND })) } @@ -119,7 +83,7 @@ export const Wallet: React.FC = () => { - + {`Name: ${currentAccount?.account.name}`} {`${t("address", { diff --git a/src/helpers/address.ts b/src/helpers/address.ts index 13c7b5d..9485677 100644 --- a/src/helpers/address.ts +++ b/src/helpers/address.ts @@ -4,7 +4,7 @@ export function shortenSubstateAddress(input: string, startChars = 5, endChars = // Check if the input has the expected format if (parts.length < 2) { - return input // Return the original string if it doesn't match the expected format + return input } const prefix = parts[0] // SubstateId @@ -12,7 +12,7 @@ export function shortenSubstateAddress(input: string, startChars = 5, endChars = // Ensure the long string is long enough to shorten if (longString.length <= startChars + endChars) { - return input // Return the original string if it's too short to shorten + return input } const startPart = longString.substring(0, startChars) diff --git a/src/provider/TariUniverseProvider.ts b/src/provider/TariUniverseProvider.ts index 9b14bce..034270f 100644 --- a/src/provider/TariUniverseProvider.ts +++ b/src/provider/TariUniverseProvider.ts @@ -81,31 +81,17 @@ export class TariUniverseProvider implements TariProvider { } async runOne(method: TUProviderMethod, args: any[]): Promise { - console.log(">>> runOne", method, args) - const isAuth = this.client.isAuthenticated() - console.log(">>> runOne isAuth", isAuth) let res = (this[method] as (...args: any) => Promise)(...args) - console.log(">>> runOne", res) return res } public async createFreeTestCoins(accountName?: string, amount = 1_000_000, fee?: number): Promise { - //TODO tmp solution to debug rpc call problem - console.log(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ") - console.log("create coins - TARI UNIVERSE PROVIDER") - // const res = await accountsCreateFreeTestCoins({ - // account: (accountName && { Name: accountName }) || null, - // amount, - // max_fee: fee ?? null, - // key_id: null, - // }) const res = await this.client.createFreeTestCoins({ account: (accountName && { Name: accountName }) || null, amount, max_fee: fee ?? null, key_id: null, }) - console.log("create coins res", res) return { account_id: res.account.key_index, address: (res.account.address as { Component: string }).Component, @@ -120,8 +106,6 @@ export class TariUniverseProvider implements TariProvider { customAccessRules?: ComponentAccessRules, isDefault = true ): Promise { - console.log("create account") - const res = await this.client.accountsCreate({ account_name: accountName ?? null, custom_access_rules: customAccessRules ?? null, @@ -129,7 +113,6 @@ export class TariUniverseProvider implements TariProvider { key_id: null, max_fee: fee ?? null, }) - console.log("create account res", res) return { account_id: 0, address: (res.address as { Component: string }).Component, @@ -153,7 +136,6 @@ export class TariUniverseProvider implements TariProvider { account_id: account.key_index, address: account.address.Component, public_key, - // TODO resources: balances.map((b: any) => ({ type: b.resource_type, resource_address: b.resource_address, @@ -172,12 +154,12 @@ export class TariUniverseProvider implements TariProvider { } public async getAccountsList(limit = 0, offset = 10): Promise { - const l = await this.client.accountsList({ + // TODO https://github.com/tari-project/tari-universe/issues/141 + const res = await this.client.accountsList({ limit, offset, }) - console.log("get list", l) - return l + return res } public async getAccountsBalances( @@ -200,9 +182,6 @@ export class TariUniverseProvider implements TariProvider { } public async submitTransaction(req: SubmitTransactionRequest): Promise { - console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - console.log(" submit tx TU Provider", req) - const params = { transaction: { instructions: req.instructions as Instruction[], @@ -220,10 +199,8 @@ export class TariUniverseProvider implements TariProvider { detect_inputs: false, //TODO check if works for 'false' proof_ids: [], } as TransactionSubmitRequest - console.log("!!!!!!!!!!!!!!!!!!!!!!!!! submit tx TU Provider", params) const res = await this.client.submitTransaction(params) - return { transaction_id: res.transaction_id } } diff --git a/src/provider/ipc_transport.ts b/src/provider/ipc_transport.ts index cfceb82..c83dbf6 100644 --- a/src/provider/ipc_transport.ts +++ b/src/provider/ipc_transport.ts @@ -3,7 +3,6 @@ import { invoke } from "@tauri-apps/api/core" export class IPCRpcTransport implements transports.RpcTransport { async sendRequest(request: transports.RpcRequest, _: transports.RpcTransportOptions): Promise { - console.log("!!!!!!!!!!!!!!! IPC RPC send request", request) return await invoke("call_wallet", { method: request.method, params: JSON.stringify(request.params), diff --git a/src/store/account/account.action.ts b/src/store/account/account.action.ts index eac834d..2b1fbeb 100644 --- a/src/store/account/account.action.ts +++ b/src/store/account/account.action.ts @@ -50,21 +50,21 @@ export const setAccountAction = () => ({ dispatch(errorActions.showError({ message: "failed-to-find-provider", errorSource: ErrorSource.FRONTEND })) return } + + // if tapplet uses TU Provider it gets default account + // this is to make sure tapplet uses the account selected by the user await provider.client.accountsSetDefault({ account: { Name: action.payload.accountName, }, }) - const _account = await provider.client.accountsGet({ + const account = await provider.client.accountsGet({ name_or_address: { Name: action.payload.accountName }, }) - console.log("set action ", _account) - const list = await provider.client.accountsList({ limit: 0, offset: 10 }) - console.log("set action ", list) listenerApi.dispatch( accountActions.setAccountSuccess({ - account: _account, + account, }) ) } catch (error) { diff --git a/src/store/devTapplets/devTapplets.action.ts b/src/store/devTapplets/devTapplets.action.ts index 97cc11d..a7977b9 100644 --- a/src/store/devTapplets/devTapplets.action.ts +++ b/src/store/devTapplets/devTapplets.action.ts @@ -44,7 +44,6 @@ export const addDevTappletAction = () => ({ ) => { const endpoint = action.payload.endpoint try { - console.log("ADD DEV TAPP") await invoke("add_dev_tapplet", { endpoint }) listenerApi.dispatch(devTappletsActions.addDevTappletSuccess({})) listenerApi.dispatch(devTappletsActions.initializeRequest({})) diff --git a/src/store/provider/provider.action.ts b/src/store/provider/provider.action.ts index b478bd7..4a7f33f 100644 --- a/src/store/provider/provider.action.ts +++ b/src/store/provider/provider.action.ts @@ -67,7 +67,6 @@ export const initializeAction = () => ({ } const { methodName, args, id } = event.data - console.log("!!!!!! provider init action", methodName, args, id) const _method = methodName as TUProviderMethod const runSimulation = async () => { if (methodName !== "submitTransaction") { @@ -106,17 +105,13 @@ export const initializeAction = () => ({ const submit = async () => { try { const result = await provider.runOne(_method, args) - console.log(">>>>> submit result runOne", _method, result) if (event.source) { - console.log(">>>>> submit event source", event.source) event.source.postMessage({ id, result, type: "provider-call" }, { targetOrigin: event.origin }) - console.log(">>>>> submit event target", event.target) } } catch (error) { - const e = typeof error === "string" ? error : "send req error" + console.error(error) + const e = typeof error === "string" ? error : "Provider send request error" dispatch(errorActions.showError({ message: e, errorSource: ErrorSource.FRONTEND })) - - console.log(">>>>> submit runOne error", error) } } const cancel = async () => { diff --git a/src/store/simulation/simulation.action.ts b/src/store/simulation/simulation.action.ts index 16f3d77..92b6a61 100644 --- a/src/store/simulation/simulation.action.ts +++ b/src/store/simulation/simulation.action.ts @@ -24,7 +24,7 @@ export const runTransactionSimulationAction = () => ({ const balanceUpdates = await runSimulation() dispatch(simulationActions.runSimulationSuccess({ transactionId, balanceUpdates })) } catch (error) { - console.log("?????? tx sim error", error) + console.error(error) dispatch(simulationActions.runSimulationFailure({ transactionId, errorMsg: String(error) })) } },