Skip to content

Commit

Permalink
othent support
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jul 16, 2024
1 parent 16f5259 commit aa06d19
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 185 deletions.
5 changes: 4 additions & 1 deletion src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export const ASSETS = {
x,
};

export const AR_WALLETS = [{ type: WalletEnum.arConnect, logo: ASSETS.arconnect }];
export const AR_WALLETS = [
{ type: WalletEnum.arConnect, logo: ASSETS.arconnect },
{ type: WalletEnum.othent, logo: ASSETS.othent },
];

export const DOM = {
loader: 'loader',
Expand Down
167 changes: 0 additions & 167 deletions src/helpers/wallet.ts

This file was deleted.

29 changes: 14 additions & 15 deletions src/providers/ArweaveProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import { connect } from '@othent/kms';
import * as Othent from '@othent/kms';

import { getProfileByWalletAddress, readHandler } from 'api';

import { Modal } from 'components/molecules/Modal';
import { AO, AR_WALLETS, REDIRECTS, WALLET_PERMISSIONS } from 'helpers/config';
import { getARBalanceEndpoint } from 'helpers/endpoints';
import { ProfileHeaderType, WalletEnum } from 'helpers/types';
import Othent from 'helpers/wallet';
import { useLanguageProvider } from 'providers/LanguageProvider';

import * as S from './styles';
Expand Down Expand Up @@ -105,12 +106,6 @@ export function ArweaveProvider(props: ArweaveProviderProps) {
const [profile, setProfile] = React.useState<ProfileHeaderType | null>(null);
const [toggleProfileUpdate, setToggleProfileUpdate] = React.useState<boolean>(false);

React.useEffect(() => {
(async function () {
await handleWallet();
})();
}, []);

React.useEffect(() => {
handleWallet();

Expand Down Expand Up @@ -216,7 +211,7 @@ export function ArweaveProvider(props: ArweaveProviderProps) {
[AO.pixl]: { profileBalance: 0, walletBalance: 0 },
});
}
}, [walletAddress && profile, toggleTokenBalanceUpdate]);
}, [walletAddress, profile, toggleTokenBalanceUpdate]);

React.useEffect(() => {
if (profile && profile.id) {
Expand Down Expand Up @@ -287,20 +282,24 @@ export function ArweaveProvider(props: ArweaveProviderProps) {
}

async function handleOthent() {
Othent.init();
await window.arweaveWallet.connect(WALLET_PERMISSIONS as any);
setWallet(window.arweaveWallet);
setWalletAddress(Othent.getUserInfo().walletAddress);
setWalletType(WalletEnum.othent);
localStorage.setItem('walletType', WalletEnum.othent);
try {
const othentConnection = await connect();
const address = othentConnection.walletAddress;
setWallet(Othent);
setWalletAddress(address);
setWalletType(WalletEnum.othent);
localStorage.setItem('walletType', WalletEnum.othent);
} catch (e: any) {
console.error(e);
}
}

async function handleDisconnect() {
if (localStorage.getItem('walletType')) localStorage.removeItem('walletType');
await global.window?.arweaveWallet?.disconnect();
setWallet(null);
setWalletAddress(null);
setProfile(null);
if (localStorage.getItem('walletType')) localStorage.removeItem('walletType');
}

async function getARBalance(walletAddress: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const WalletListItem = styled.button`
`;

export const WalletLink = styled.div`
margin: 10px 0 20px 0;
margin: 5px 0 20px 0;
padding: 0 20px;
text-align: center;
a,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const MaxQty = styled.div`
`;

export const SalesWrapper = styled.div`
margin: 40px 0 20px 0;
margin: 0 0 20px 0;
> * {
&:not(:last-child) {
margin: 0 0 15px 0;
Expand Down

0 comments on commit aa06d19

Please sign in to comment.