Merge pull request #10 from andrei0x309/dev/5

chore: changes for 1.4.4
This commit is contained in:
Andrei O. 2024-08-27 23:23:45 +03:00 committed by GitHub
commit 03ba0c8f14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 339 additions and 70 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## Manifest Version 1.4.4
- added QR scaner for easier sign in with farcaster
- added cyber network in the network templates
- style changes and changes to fracaster action screen
## Manifest Version 1.4.3
- changed sign in with farcaster to work with new type of QR code

View File

@ -20,6 +20,7 @@
"@ionic/vue-router": "^8.2.6",
"core-js": "^3.38.0",
"ethers": "^6.13.2",
"qr-scanner": "^1.4.2",
"vue": "^3.4.37",
"vue-router": "^4.4.3"
},

26
src/utils/QR.ts Normal file
View File

@ -0,0 +1,26 @@
import QrScanner from 'qr-scanner';
function base64ImageToBlob(str: string) {
const pos = str.indexOf(";base64,");
const type = str.substring(5, pos);
const b64 = str.substr(pos + 8);
const imageContent = atob(b64);
const buffer = new ArrayBuffer(imageContent.length);
const view = new Uint8Array(buffer);
for(var n = 0; n < imageContent.length; n++) {
view[n] = imageContent.charCodeAt(n);
}
const blob = new Blob([buffer], { type: type });
return blob;
}
export async function getQRCode(imageBase64: string) {
try {
const imageBlob = base64ImageToBlob(imageBase64);
return await QrScanner.scanImage(imageBlob)
} catch (e) {
console.error(e);
return null;
}
}

View File

@ -3,6 +3,7 @@ import { FARCASTER_PARTIAL_KEY_ABI } from './abis'
import { ethers } from 'ethers'
import { getUrl } from './platform'
import { generateApiToken } from './warpcast-auth'
import { getQRCode } from './QR'
export interface TChannelTokenStatusResponse {
state: string;
nonce: string;
@ -25,6 +26,10 @@ const WARPCAST_BASE = 'https://client.warpcast.com/v2/'
const EP_SIGNIN = `${WARPCAST_BASE}sign-in-with-farcaster`
const FC_ID_REGISTRY_CONTRACT = '0x00000000fc6c5f01fc30151999387bb99a9f489b'
export const getLinkFromQR = async () => {
const data = await chrome.tabs.captureVisibleTab()
return await getQRCode(data)
}
const getChannelTokenStatus = async (channelToken: string) => {
const response = await fetch(`${TOKEN_STATUS_ENDPOINT}`, {
@ -159,6 +164,66 @@ export const getFidFromAddress = async (address: string) : Promise<number | null
return 0;
}
export const doSignInWithFarcasterQR = async () => {
const custodyAddress = (await getSelectedAddress())?.[0] || '';
const fid = custodyAddress && await getFidFromAddress(custodyAddress);
if (!fid) {
return -1;
}
const link = await getLinkFromQR();
if (!link) {
return -2;
}
const validateLinkDataResult = validateLinkData(link);
if (!validateLinkDataResult) {
return -3;
}
const { channelToken } = extractLinkData(link);
const extractResult = await extractResponseData(channelToken);
if (!extractResult) {
return -4;
}
const { siweUri, domain, nonce, notBefore, expirationTime } = extractResult
const message = constructWarpcastSWIEMsg({
siweUri,
domain,
nonce,
notBefore,
expirationTime,
fid,
custodyAddress
});
const genToken = await generateApiToken();
let authToken = '';
if (genToken.success) {
authToken = genToken.data;
}
if (!authToken) {
return -5;
}
const signature = await signMsg(message);
await signInWithFarcaster({
channelToken,
message,
signature,
authToken
});
return 1
}
export const doSignInWithFarcaster = async ({
link
}: {
@ -209,4 +274,3 @@ export const doSignInWithFarcaster = async ({
return 1
}

View File

@ -18,8 +18,8 @@
</ion-item>
<ion-item>
<ion-label style="opacity: 0.9; font-size: 0.85rem"
>These are experimental features RE from Warpcast might not work in all cases
and might break if WC makes changes.</ion-label
>These are experimental features might not work in all cases and might break
when warpcast/farcaster make changes.</ion-label
>
</ion-item>
<div
@ -45,21 +45,12 @@
</div>
<ion-item>
<ion-label style="opacity: 0.9; font-size: 0.85rem"
>Used for sign in with farcaster/warpcast QR you'll need to paste the deep link
in next screen</ion-label
>Used for sign in with farcaster/warpcast QR, by scanning QR on pasteing
link.</ion-label
></ion-item
>
<ion-item>
<ion-button
@click="swiwModal = true"
color="light"
style="
margin: auto;
transform: scale(1.2);
filter: hue-rotate(59deg) saturate(1.5) sepia(0.1);
"
>Sign in with farcaster</ion-button
>
<button @click="swiwModal = true" class="buttonFc">Sign in with farcaster</button>
</ion-item>
<ion-item>
<ion-label style="opacity: 0.9; font-size: 0.85rem"
@ -67,16 +58,7 @@
>
</ion-item>
<ion-item>
<ion-button
@click="promptForSignIn"
style="
margin: auto;
transform: scale(1.2);
filter: hue-rotate(59deg) saturate(1.5) sepia(0.1);
"
color="light"
>Login on Warpcast.com</ion-button
>
<button @click="promptForSignIn" class="buttonFc">Login on Warpcast.com</button>
</ion-item>
<ion-alert
@ -141,30 +123,50 @@
<ion-buttons slot="start">
<ion-button @click="swiwModal = false">Close</ion-button>
</ion-buttons>
<ion-title>Paste Link To Authorize</ion-title>
<ion-title>Authorize</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-item>
<ion-label
>Enter deep-link from Sign in with farcaster QR EX:
<span style="font-size: 0.8rem; opacity: 0.8">
https://warpcast.com/~/sign-in-with-farcaster?channelToken=4a8d3f27-....
</span></ion-label
><h2>Try to scan QR</h2>
<p style="font-size: 0.8rem">
(must be visible on current page)
</p></ion-label
>
</ion-item>
<ion-item>
<ion-button @click="swiwModal = false" color="light">Cancel</ion-button>
<ion-button @click="farcasterSWIWQRAuthorize">Authorize using QR</ion-button>
</ion-item>
<ion-item>
<ion-label
><h2>Alternative: paste link from QR</h2>
<p style="font-size: 0.8rem; opacity: 0.9">
similar to: https://warpcast.com/~/siwf?channelToken=AXLUD4S4
</p></ion-label
>
</ion-item>
<ion-item>
<ion-label>
<p>Account needs to own a fid</p>
<p>QR needs to be visible on the website you click authorize</p>
</ion-label>
</ion-item>
<ion-item>
<ion-textarea
style="overflow-y: scroll; width: 100%"
aria-label="Enter deep link from Sign in with farcaste QR"
:rows="10"
:cols="10"
:rows="4"
:cols="8"
v-model="deepLink"
></ion-textarea>
</ion-item>
<ion-item>
<ion-button @click="swiwModal = false" color="light">Cancel</ion-button>
<ion-button @click="farcasterSWIWAithorize">Authorize</ion-button>
<ion-button @click="farcasterSWIWAuthorize">Authorize using link</ion-button>
</ion-item>
</ion-content>
@ -224,6 +226,7 @@ import {
doSignInWithFarcaster,
validateLinkData,
getFidFromAddress,
doSignInWithFarcasterQR,
} from "@/utils/farcaster";
import { getAccounts, getSelectedAccount, unBlockLockout } from "@/utils/platform";
import { addWarpAuthToken, generateApiToken } from "@/utils/warpcast-auth";
@ -300,7 +303,7 @@ export default defineComponent({
loading.value = false;
};
const farcasterSWIWAithorize = async () => {
const farcasterSWIWAuthorize = async () => {
exitWallet.value = false;
if (!deepLink.value) {
alertMsg.value = "Please enter the deep link";
@ -309,7 +312,7 @@ export default defineComponent({
}
const linkData = validateLinkData(deepLink.value);
if (!linkData) {
alertMsg.value = "Invalid deep link";
alertMsg.value = "Invalid link pasted it does not contain a valid channel token";
alertOpen.value = true;
return;
}
@ -331,7 +334,54 @@ export default defineComponent({
link: deepLink.value,
});
console.log("result", result);
if (result === -1) {
alertMsg.value =
"Selected account does not own a FID please select an account that owns a FID";
alertOpen.value = true;
swloading.value = false;
return;
} else if (result === -2) {
alertMsg.value = "Auth token generation failed";
alertOpen.value = true;
swloading.value = false;
return;
} else if (result === -3) {
alertMsg.value =
"Error could read chanel token from data, make sure you have copied the correct link";
alertOpen.value = true;
swloading.value = false;
return;
} else {
alertHeader.value = "OK";
alertMsg.value =
"Request sent successfully, if QR is still open, you will be signed in";
alertOpen.value = true;
swloading.value = false;
exitWallet.value = true;
}
} catch (e) {
alertMsg.value = String(e);
alertOpen.value = true;
}
swloading.value = false;
};
const farcasterSWIWQRAuthorize = async () => {
exitWallet.value = false;
if ((selectedAccount.value.pk ?? "").length !== 66) {
const modalResult = await openModal();
if (modalResult) {
unBlockLockout();
loading.value = true;
} else {
onCancel();
}
} else {
unBlockLockout();
}
swloading.value = true;
try {
const result = await doSignInWithFarcasterQR();
if (result === -1) {
alertMsg.value =
@ -340,20 +390,31 @@ export default defineComponent({
swloading.value = false;
return;
} else if (result === -2) {
alertMsg.value = "Optimism RCP is not available";
alertMsg.value =
"Failed to read QR data, be sure QR is visible on, if is not working try using link";
alertOpen.value = true;
swloading.value = false;
return;
} else if (result === -3) {
alertMsg.value =
"Error could not get signer params from farcaster relay, try again";
"QR does not contain a valid channel token, make sure you are scanning a sign in with farcaster QR";
alertOpen.value = true;
swloading.value = false;
return;
} else if (result === -4) {
alertMsg.value = "Failed to extract sign params from QR";
alertOpen.value = true;
swloading.value = false;
return;
} else if (result === -5) {
alertMsg.value = "Auth token generation failed";
alertOpen.value = true;
swloading.value = false;
return;
} else {
alertHeader.value = "OK";
alertMsg.value =
"Request sent successfully, if QR is still open, you should be signed in";
"Request sent successfully, if QR is still open, you will be signed in";
alertOpen.value = true;
swloading.value = false;
exitWallet.value = true;
@ -481,14 +542,113 @@ export default defineComponent({
toastState,
deepLink,
swiwModal,
farcasterSWIWAithorize,
farcasterSWIWAuthorize,
swloading,
promptForSignIn,
warpcastLoading,
window,
exitWallet,
alertHeader,
farcasterSWIWQRAuthorize,
};
},
});
</script>
<style scoped>
.buttonFc {
position: relative;
padding: 10px 22px;
border-radius: 6px;
border: none;
color: #fff;
cursor: pointer;
background-color: #7d2ae8;
transition: all 0.2s ease;
text-transform: uppercase;
margin-left: auto;
margin-right: auto;
margin-top: 1rem;
margin-bottom: 1rem;
}
.buttonFc:active {
transform: scale(0.96);
}
.buttonFc:before,
.buttonFc:after {
position: absolute;
content: "";
width: 150%;
left: 50%;
height: 100%;
transform: translateX(-50%);
z-index: -1000;
background-repeat: no-repeat;
}
.buttonFc:hover:before {
top: -70%;
background-image: radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, transparent 20%, #7d2ae8 20%, transparent 30%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, transparent 10%, #7d2ae8 15%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%);
background-size: 10% 10%, 20% 20%, 15% 15%, 20% 20%, 18% 18%, 10% 10%, 15% 15%, 10% 10%,
18% 18%;
background-position: 50% 120%;
animation: greentopBubbles 1.1s ease;
}
@keyframes greentopBubbles {
0% {
background-position: 5% 90%, 10% 90%, 10% 90%, 15% 90%, 25% 90%, 25% 90%, 40% 90%,
55% 90%, 70% 90%;
}
50% {
background-position: 0% 80%, 0% 20%, 10% 40%, 20% 0%, 30% 30%, 22% 50%, 50% 50%,
65% 20%, 90% 30%;
}
100% {
background-position: 0% 70%, 0% 10%, 10% 30%, 20% -10%, 30% 20%, 22% 40%, 50% 40%,
65% 10%, 90% 20%;
background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
}
}
.buttonFc:hover::after {
bottom: -70%;
background-image: radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, transparent 10%, #7d2ae8 15%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%),
radial-gradient(circle, #7d2ae8 20%, transparent 20%);
background-size: 15% 15%, 20% 20%, 18% 18%, 20% 20%, 15% 15%, 20% 20%, 18% 18%;
background-position: 50% 0%;
animation: greenbottomBubbles 0.6s ease;
}
@keyframes greenbottomBubbles {
0% {
background-position: 10% -10%, 30% 10%, 55% -10%, 70% -10%, 85% -10%, 70% -10%, 70% 0%;
}
50% {
background-position: 0% 80%, 20% 80%, 45% 60%, 60% 100%, 75% 70%, 95% 60%, 105% 0%;
}
100% {
background-position: 0% 90%, 20% 90%, 45% 70%, 60% 110%, 75% 80%, 95% 70%, 110% 10%;
background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
}
}
</style>

View File

@ -1145,6 +1145,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469"
integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==
"@types/offscreencanvas@^2019.6.4":
version "2019.7.3"
resolved "https://registry.npmjs.org/@types/offscreencanvas/-/offscreencanvas-2019.7.3.tgz#90267db13f64d6e9ccb5ae3eac92786a7c77a516"
integrity sha512-ieXiYmgSRXUDeOntE1InxjWyvEelZGP63M+cGuquuRLuIKKT1osnkXjxev9B7d1nXSug5vpunx+gNlbVxMlC9A==
"@types/readdir-glob@*":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/readdir-glob/-/readdir-glob-1.1.1.tgz#27ac2db283e6aa3d110b14ff9da44fcd1a5c38b1"
@ -4054,6 +4059,13 @@ q@^1.0.1:
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==
qr-scanner@^1.4.2:
version "1.4.2"
resolved "https://registry.npmjs.org/qr-scanner/-/qr-scanner-1.4.2.tgz#bc4fb88022a8c9be95c49527a1c8fb8724b47dc4"
integrity sha512-kV1yQUe2FENvn59tMZW6mOVfpq9mGxGf8l6+EGaXUOd4RBOLg7tRC83OrirM5AtDvZRpdjdlXURsHreAOSPOUw==
dependencies:
"@types/offscreencanvas" "^2019.6.4"
queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"