Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Nov 22, 2024
1 parent 93b2976 commit d7f0354
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/classes/mnemonicSigner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountData, DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing'
import { AminoSignResponse, StdSignDoc, OfflineAminoSigner } from '@cosmjs/amino'
import { AminoSignResponse, OfflineAminoSigner, StdSignDoc } from '@cosmjs/amino'
import { IMnemonicSigner, ISignDoc } from '@/interfaces'

export class MnemonicSigner implements IMnemonicSigner {
Expand Down
2 changes: 1 addition & 1 deletion src/classes/storageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ export class StorageHandler extends EncodingHandler implements IStorageHandler {
})
if (providerIps.length >= copies) {
const fakeResponse: IProviderUploadResponse = {
merkle: hexToBuffer(merkle),
merkle: hexToBuffer(merkle),
owner: this.jklAddress,
start: uploadHeight,
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/classes/IRnsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
IPageRequest,
IRegisterOptions,
IRemoveSubRnsOptions,
ISetNewPrimaryOptions,
ITransferOptions,
IUpdateOptions,
IWrappedEncodeObject,
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/classes/IWasmHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export interface IWasmHandler {
instantiateICA (
contractAddress: string,
connectionIdA: string,
connectionIdB: string
connectionIdB: string,
): Promise<DDeliverTxResponse>

reOpenChannel (
contractAddress: string,
connectionIdA: string,
connectionIdB: string
connectionIdB: string,
): Promise<DDeliverTxResponse>

getICAContractAddress (contractAddress: string): Promise<string>
Expand Down
136 changes: 68 additions & 68 deletions src/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,48 +252,48 @@ async function extractThumbnailFromVideo (file: File): Promise<string> {
const processor: Promise<string> = new Promise((resolve, reject) => {
const video = document.createElement('video')

video.src = URL.createObjectURL(file)
video.muted = true // Mute the video to prevent sound playing
video.playsInline = true

video.onloadedmetadata = () => {
const duration = video.duration
const randomTime = Math.random() * duration // Select a random time point in the video
video.currentTime = randomTime // Seek to the random time

video.onseeked = () => {
// Set the maximum dimension to 256
const maxSize = 256
let { videoWidth: width, videoHeight: height } = video

// Maintain aspect ratio when resizing
if (width > height) {
if (width > maxSize) {
height *= maxSize / width
width = maxSize
}
} else {
if (height > maxSize) {
width *= maxSize / height
height = maxSize
}
video.src = URL.createObjectURL(file)
video.muted = true // Mute the video to prevent sound playing
video.playsInline = true

video.onloadedmetadata = () => {
const duration = video.duration
const randomTime = Math.random() * duration // Select a random time point in the video
video.currentTime = randomTime // Seek to the random time

video.onseeked = () => {
// Set the maximum dimension to 256
const maxSize = 256
let { videoWidth: width, videoHeight: height } = video

// Maintain aspect ratio when resizing
if (width > height) {
if (width > maxSize) {
height *= maxSize / width
width = maxSize
}
} else {
if (height > maxSize) {
width *= maxSize / height
height = maxSize
}
}

const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')

// Set canvas dimensions to the resized dimensions
canvas.width = width
canvas.height = height
// Set canvas dimensions to the resized dimensions
canvas.width = width
canvas.height = height

// Draw the current video frame onto the resized canvas
ctx?.drawImage(video, 0, 0, width, height)
// Draw the current video frame onto the resized canvas
ctx?.drawImage(video, 0, 0, width, height)

// Convert the canvas to a WebP image
const base64String = canvas.toDataURL('image/webp', 0.25) // 25% compression
resolve(base64String)
}
// Convert the canvas to a WebP image
const base64String = canvas.toDataURL('image/webp', 0.25) // 25% compression
resolve(base64String)
}
}

video.onerror = reject
})
Expand All @@ -306,7 +306,7 @@ async function extractThumbnailFromVideo (file: File): Promise<string> {
}

/**
*
*
* @param {File} file
* @returns {Promise<string>}
*/
Expand All @@ -317,44 +317,44 @@ async function convertToWebP (file: File): Promise<string> {
const img = new Image()
img.src = event.target?.result as string

img.onload = () => {
const maxSize = 256
let { width, height } = img

// Calculate new dimensions while maintaining aspect ratio
if (width > height) {
if (width > maxSize) {
height *= maxSize / width
width = maxSize
}
} else {
if (height > maxSize) {
width *= maxSize / height
height = maxSize
}
img.onload = () => {
const maxSize = 256
let { width, height } = img

// Calculate new dimensions while maintaining aspect ratio
if (width > height) {
if (width > maxSize) {
height *= maxSize / width
width = maxSize
}
} else {
if (height > maxSize) {
width *= maxSize / height
height = maxSize
}
}

const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')

if (!ctx) {
return reject('Canvas context is unavailable')
}
if (!ctx) {
return reject('Canvas context is unavailable')
}

// Set canvas dimensions to the resized dimensions
canvas.width = width
canvas.height = height
// Set canvas dimensions to the resized dimensions
canvas.width = width
canvas.height = height

// Draw resized image onto the canvas
ctx.drawImage(img, 0, 0, width, height)
// Draw resized image onto the canvas
ctx.drawImage(img, 0, 0, width, height)

// Convert canvas to WebP format and get Base64 string
canvas.toDataURL('image/webp', 0.25) // 25% compression
const base64String = canvas.toDataURL('image/webp', 0.25)
// console.log(base64String)
resolve(base64String)
}
// Convert canvas to WebP format and get Base64 string
canvas.toDataURL('image/webp', 0.25) // 25% compression
const base64String = canvas.toDataURL('image/webp', 0.25)
// console.log(base64String)
resolve(base64String)
}
}

reader.onerror = reject
reader.readAsDataURL(file)
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ declare global {
interface Window extends KeplrWindow, LeapWindow {
mnemonicWallet?: MnemonicWallet
}

var mnemonicWallet: MnemonicWallet
}

0 comments on commit d7f0354

Please sign in to comment.