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

session proxies #100

Merged
merged 11 commits into from
Dec 12, 2024
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
77 changes: 70 additions & 7 deletions components/overlays/ChooseWalletOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,37 @@
</option>
</select>
</div>
<div v-if="accountStore.hasInjector" class="mt-10">
<p class="text-sm text-gray-400 wrap-text">
your currently selected account is {{ accountStore.getAddress }}
</p>
<div
v-if="accountStore.sessionProxyForRole(SessionProxyRole.ReadBalance)"
class="mt-10"
>
<button
@click="changeSessionAuthorization"
class="incognitee-bg btn btn_gradient rounded-md px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-400"
>
Change Session Key Authorization
</button>
</div>
</div>
<div
v-if="accountStore.hasInjector && showTrustedGetterHint"
v-if="
accountStore.hasInjector &&
showTrustedGetterHint &&
selectedExtensionAccountIsNew
"
class="mt-10"
>
<p>
<p class="text-sm text-gray-400">
please allow this app to read your balance by signing the upcoming
request in your extension
</p>
<p>this window will close once a balance could be fetched</p>
<p class="mt-5 text-sm text-gray-400">
this window will close once a balance could be fetched
</p>
</div>
</div>
</OverlayDialog>
Expand All @@ -94,15 +116,35 @@
import {
connectExtension,
extensionAccounts,
injectorForAddress,
} from "~/lib/signerExtensionUtils";
import OverlayDialog from "~/components/overlays/OverlayDialog.vue";
import { defineProps, computed, ref, watch } from "vue";
import { computed, defineProps, ref, watch } from "vue";
import { useAccount } from "~/store/account.ts";
import { encodeAddress } from "@polkadot/util-crypto";
import { SessionProxyRole } from "~/lib/sessionProxyStorage";

const accountStore = useAccount();
const currentExtensionAccount = ref("");
const selectedExtensionAccount = ref("");

const selectedExtensionAccountIsNew = computed(() => {
try {
const selectedAddressEncoded = encodeAddress(
selectedExtensionAccount.value,
accountStore.getSs58Format,
);
console.log(
"comparing",
currentExtensionAccount.value,
" to ",
selectedAddressEncoded,
);
return selectedAddressEncoded !== currentExtensionAccount.value;
} catch (e) {
return false;
}
});

const props = defineProps({
createTestingAccount: {
type: Function,
Expand All @@ -124,7 +166,23 @@ const props = defineProps({
type: Boolean,
required: false,
},
changeSessionAuthorization: {
type: Function,
required: false,
},
});

watch(
() => props.show,
(show) => {
if (show) {
console.log("current extension account: ", accountStore.getAddress);
currentExtensionAccount.value = accountStore.getAddress;
//selectedExtensionAccount.value = "";
}
},
);

const hasCreateTestingAccountFn = computed(
() => typeof props.createTestingAccount === "function",
);
Expand All @@ -139,10 +197,15 @@ const closeProxy = () => {
};

watch(selectedExtensionAccount, async (selectedAddress) => {
if (selectedAddress) {
if (selectedAddress && selectedExtensionAccountIsNew.value) {
props.onExtensionAccountChange(selectedAddress);
}
});
</script>

<style scoped></style>
<style scoped>
.wrap-text {
white-space: normal;
word-wrap: break-word;
}
</style>
Loading
Loading