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

Update Ylide #1

Open
wants to merge 6 commits into
base: ylide-integration
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const ChooseEvmNetwork: FC = () => {
const [balances, setBalances] = useState<BlockchainBalances>({})
useEffect(() => {
;(async () => {
if (chooseEvmNetworkDialog.visible && account) {
if (account) {
setBalances(await getBalancesOf(account))
setLoading(false)
} else {
setBalances({})
setLoading(true)
}
})()
}, [account, chooseEvmNetworkDialog.visible, getBalancesOf])
}, [account, getBalancesOf])

return (
<Dialog
Expand Down
6 changes: 3 additions & 3 deletions UI/profile-board/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const defaultPosts: PostData[] = [
const uniqueFeedId = '0000000000000000000000000000000000000000000000000000000000000117' as Uint256 // ISME const

export function useFeedLoader(userAddress: string) {
const feedId = constructFeedId(userAddress, true, uniqueFeedId)
const feedId = constructFeedId(userAddress, true, false, uniqueFeedId)
const { walletAccount, decodeMessage } = useYlide()

return useCallback(
Expand Down Expand Up @@ -245,7 +245,7 @@ const NewPostForm: FC<{ onPost: () => void }> = ({ onPost }) => {
sendingAgentVersion: { major: 1, minor: 0, patch: 0 },
subject: cleanTitle,
content: YMF.fromPlainText(cleanContent),
attachments: [], // TODO?
attachments: [],
extraBytes: new Uint8Array(0),
extraJson: {},
})
Expand All @@ -267,7 +267,7 @@ const NewPostForm: FC<{ onPost: () => void }> = ({ onPost }) => {
.finally(() => {
setSending(false)
})
}, [cleanTitle, cleanContent, broadcastMessage, onPost])
}, [hasData, cleanTitle, cleanContent, broadcastMessage, onPost])

return (
<Form>
Expand Down
62 changes: 37 additions & 25 deletions domains/data/ylide/Wallet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {
AbstractWalletController,
IGenericAccount,
WalletAccount,
WalletControllerFactory,
Ylide,
YlideKeyStore,
YlideKeysRegistry,
} from '@ylide/sdk'
import { WalletEvent } from '@ylide/sdk'
import { PrivateKeyAvailabilityState, WalletEvent, YlideKeyVersion } from '@ylide/sdk'
import EventEmitter from 'eventemitter3'

export class Wallet extends EventEmitter {
Expand All @@ -15,12 +15,12 @@ export class Wallet extends EventEmitter {

private _isAvailable = false

currentWalletAccount: IGenericAccount | null = null
currentWalletAccount: WalletAccount | null = null
currentBlockchain = 'unknown'

constructor(
private readonly ylide: Ylide,
private readonly keystore: YlideKeyStore,
private readonly keysRegistry: YlideKeysRegistry,
factory: WalletControllerFactory,
controller: AbstractWalletController
) {
Expand Down Expand Up @@ -56,12 +56,12 @@ export class Wallet extends EventEmitter {
this.controller.off(WalletEvent.BLOCKCHAIN_CHANGED, this.handleBlockchainChanged)
}

handleAccountChanged = (newAccount: IGenericAccount) => {
handleAccountChanged = (newAccount: WalletAccount) => {
this.currentWalletAccount = newAccount
this.emit('accountUpdate', this.currentWalletAccount)
}

handleAccountLogin = (newAccount: IGenericAccount) => {
handleAccountLogin = (newAccount: WalletAccount) => {
this.currentWalletAccount = newAccount
this.emit('accountUpdate', this.currentWalletAccount)
}
Expand All @@ -83,36 +83,48 @@ export class Wallet extends EventEmitter {
return this._isAvailable
}

async constructLocalKeyV3(account: IGenericAccount) {
return await this.keystore.constructKeypairV3(
'New account connection',
async constructLocalKeyV3(account: WalletAccount) {
return await this.keysRegistry.instantiateNewPrivateKey(
this.factory.blockchainGroup,
this.factory.wallet,
account.address
account.address,
YlideKeyVersion.KEY_V3,
PrivateKeyAvailabilityState.AVAILABLE,
{
onPrivateKeyRequest: async (address, magicString) =>
await this.controller.signMagicString(account, magicString),
}
)
}

async constructLocalKeyV2(account: IGenericAccount, password: string) {
return await this.keystore.constructKeypairV2(
'New account connection',
async constructLocalKeyV2(account: WalletAccount, password: string) {
return await this.keysRegistry.instantiateNewPrivateKey(
this.factory.blockchainGroup,
this.factory.wallet,
account.address,
password
YlideKeyVersion.KEY_V2,
PrivateKeyAvailabilityState.AVAILABLE,
{
onPrivateKeyRequest: async (address, magicString) =>
await this.controller.signMagicString(account, magicString),
onYlidePasswordRequest: async (address) => password,
}
)
}

async constructLocalKeyV1(account: IGenericAccount, password: string) {
return await this.keystore.constructKeypairV1(
'New account connection',
async constructLocalKeyV1(account: WalletAccount, password: string) {
return await this.keysRegistry.instantiateNewPrivateKey(
this.factory.blockchainGroup,
this.factory.wallet,
account.address,
password
YlideKeyVersion.INSECURE_KEY_V1,
PrivateKeyAvailabilityState.AVAILABLE,
{
onPrivateKeyRequest: async (address, magicString) =>
await this.controller.signMagicString(account, magicString),
onYlidePasswordRequest: async (address) => password,
}
)
}

async readRemoteKeys(account: IGenericAccount) {
async readRemoteKeys(account: WalletAccount) {
const result = await this.ylide.core.getAddressKeys(account.address)

return {
Expand All @@ -121,11 +133,11 @@ export class Wallet extends EventEmitter {
}
}

async getCurrentAccount(): Promise<IGenericAccount | null> {
async getCurrentAccount(): Promise<WalletAccount | null> {
return this.controller.getAuthenticatedAccount()
}

async disconnectAccount(account: IGenericAccount) {
async disconnectAccount(account: WalletAccount) {
await this.controller.disconnectAccount(account)
}

Expand Down
20 changes: 11 additions & 9 deletions domains/data/ylide/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export enum ChatState {
LOADING,
}

export function useChat({ recipientName }: { recipientName?: string }) {
export function useChat({ recipientName }: { recipientName: string }) {
const { client } = useNFT3()
const { account } = useUser()
const { walletAccount, decodeMessage, forceAuth, isLoading, authState } = useYlide()
Expand All @@ -144,19 +144,21 @@ export function useChat({ recipientName }: { recipientName?: string }) {
limit: 1000,
})

const entries = enteriesRaw.map((entry) => ({
...entry,
msg: {
...entry.msg,
key: new Uint8Array(entry.msg.key),
},
}))
const entries = enteriesRaw
.map((entry) => ({
...entry,
msg: {
...entry.msg,
key: new Uint8Array(entry.msg.key),
},
}))
.reverse()

return await Promise.all(
entries
.filter((e) => e.type === 'message')
.map(async (entry) => {
const decoded = await decodeMessage(entry.id, entry.msg, walletAccount)
const decoded = await decodeMessage(entry.id, entry.msg, walletAccount!)

return {
id: entry.id,
Expand Down
Loading