Skip to content

Commit

Permalink
Move to provider temp: fix & rely on local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
schnetzlerjoe committed Sep 12, 2023
1 parent 8a371b7 commit 74af808
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/components/Transfer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
typeUrl: item.msg_type_url
};
});
let tx = await client.signAndBroadcast(fromAddress, messages, fees);
let tx = await window.cosmos.signAndBroadcast(fromAddress, messages, fees);
if (tx.code == 0) {
await addTransaction({address: fromAddress, chain: source, when: new Date().toDateString(), tx_hash: tx.transactionHash})
Expand Down
93 changes: 36 additions & 57 deletions packages/ui/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,68 +1,47 @@
<script lang="ts">
import { afterUpdate } from 'svelte';
import MainTitle from '../components/MainTitle.svelte';
import MainTitle from '../components/MainTitle.svelte';
import Step from '../components/Step.svelte';
import { isMetaMaskInstalled, initSnap, isSnapInstalled, installSnap } from '../utils/snap';
import { isMetaMaskInstalled, initSnap, isSnapInstalled, installSnap } from '../utils/snap';
import { state } from '../store/state';
import { goto } from '$app/navigation';
import { LOCAL_STORAGE_CHAINS, LOCAL_STORAGE_INIT } from '../utils/general';
import { chains } from '../store/chains';
let loading = true;
let isMetaMaskInstalledValue: boolean = false;
let isSnapInstalledValue: boolean = false;
let isSnapInitValue: boolean = false;
$: {
if (isMetaMaskInstalledValue && isSnapInitValue && isSnapInstalledValue) {
goto("/balances");
$state.connected = true;
}
}
const runInstallSnap = async () => {
await installSnap();
isSnapInstalledValue = true;
isSnapInitValue = false;
localStorage.setItem(LOCAL_STORAGE_INIT, "false") ;
}
const initializeSnap = async () => {
let chainsFromInit = await initSnap();
if (chainsFromInit) {
localStorage.setItem(LOCAL_STORAGE_CHAINS, JSON.stringify(chainsFromInit));
chains.set(chainsFromInit);
localStorage.setItem(LOCAL_STORAGE_INIT, "true")
}
isSnapInitValue = true;
$state.connected = true;
goto("/balances");
}
afterUpdate(async () => {
let isMetaMaskInstalledRaw = isMetaMaskInstalled()
if (isMetaMaskInstalledRaw === undefined) {
isMetaMaskInstalledValue = false;
} else {
isMetaMaskInstalledValue = isMetaMaskInstalledRaw;
}
let isSnapInstalledRaw = await isSnapInstalled()
if (isSnapInstalledRaw === undefined) {
isSnapInstalledValue = false;
} else {
isSnapInstalledValue = isSnapInstalledRaw;
}
let isSnapInitValueRaw = localStorage.getItem(LOCAL_STORAGE_INIT)
if (isSnapInitValueRaw === undefined) {
isSnapInitValue = false;
} else {
isSnapInitValue = isSnapInitValueRaw == "true" ? true : false;
}
loading = false;
})
let isMetaMaskInstalledValue = false;
let isSnapInstalledValue = false;
let isSnapInitValue = false;
$: if (isMetaMaskInstalledValue && isSnapInitValue && isSnapInstalledValue) {
$state.connected = true;
goto("/balances");
}
const initializeData = async () => {
isMetaMaskInstalledValue = isMetaMaskInstalled() ?? false;
isSnapInstalledValue = await isSnapInstalled() ?? false;
isSnapInitValue = (localStorage.getItem(LOCAL_STORAGE_INIT) === "true");
};
const runInstallSnap = async () => {
await installSnap();
isSnapInstalledValue = true;
isSnapInitValue = false;
};
const initializeSnap = async () => {
const chainsFromInit = await initSnap();
if (chainsFromInit) {
localStorage.setItem(LOCAL_STORAGE_CHAINS, JSON.stringify(chainsFromInit));
chains.set(chainsFromInit);
localStorage.setItem(LOCAL_STORAGE_INIT, "true");
isSnapInitValue = true;
$state.connected = true;
goto("/balances");
}
};
afterUpdate(initializeData);
</script>

<div class="x1-connect-metamask screen">
Expand Down

0 comments on commit 74af808

Please sign in to comment.