Skip to content

Commit

Permalink
Merge pull request #34 from dsrvlabs/feature/add-wallet-strategy
Browse files Browse the repository at this point in the history
Feature/add wallet strategy
  • Loading branch information
altpd13 authored Aug 28, 2024
2 parents f5b19f2 + 4f7cae4 commit 2bffe09
Show file tree
Hide file tree
Showing 10 changed files with 677 additions and 698 deletions.
61 changes: 9 additions & 52 deletions src/components/injective/Compiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,14 @@ import { Alert, Button } from 'react-bootstrap';
import { FaSyncAlt } from 'react-icons/fa';
import AlertCloseButton from '../common/AlertCloseButton';
import { StoreCode } from './StoreCode';
import { Client } from '@remixproject/plugin';
import { Api } from '@remixproject/plugin-utils';
import { IRemixApi } from '@remixproject/plugin-api';
import { isEmptyObject } from '../../utils/ObjectUtil';
import { useWalletStore } from './WalletContextProvider';

interface InterfaceProps {
fileName: string;
setFileName: Dispatch<React.SetStateAction<string>>;
compileTarget: string;
wallet: string;
account: string;
providerInstance: any;
client: any;
reset: () => void;
providerNetwork: string;
}

const RCV_EVENT_LOG_PREFIX = `[==> EVENT_RCV]`;
Expand All @@ -54,19 +47,14 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
fileName,
setFileName,
client,
providerInstance,
compileTarget,
wallet,
account,
reset,
providerNetwork,
}) => {
const [iconSpin, setIconSpin] = useState<string>('');
const [wasm, setWasm] = useState<string>('');
const [checksum, setChecksum] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);
const [compileError, setCompileError] = useState<Nullable<string>>('');
const [txHash, setTxHash] = useState<string>('');
const [codeID, setCodeID] = useState<string>('');
const [timestamp, setTimestamp] = useState('');

Expand All @@ -76,42 +64,17 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({

const [uploadCodeChecked, setUploadCodeChecked] = useState(true);

const { injectiveAddress, chainId } = useWalletStore();

useEffect(() => {
init();
}, [compileTarget]);

const exists = async () => {
try {
const artifacts = await client.fileManager.readdir('browser/' + compileTarget + '/artifacts');
if (isEmptyObject(artifacts)) throw new Error('artifacts directory does not exists');
await setSchemaObj();
await client.terminal.log({
type: 'error',
value:
"If you want to run a new compilation, delete the 'artifacts' and 'schema' directory and click the Compile button again.",
});
const filesName = Object.keys(artifacts || {});
await Promise.all(
filesName.map(async (f) => {
if (getExtensionOfFilename(f) === '.wasm') {
const wasmFile = await client?.fileManager.readFile('browser/' + f);
setWasm(wasmFile || '');
setFileName(f);
}
}),
);
return true;
} catch {
return false;
}
};

const init = () => {
setWasm('');
setChecksum('');
setFileName('');
setCodeID('');
setTxHash('');
setSchemaExec({});
setSchemaInit({});
setSchemaQuery({});
Expand Down Expand Up @@ -204,11 +167,11 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
setIconSpin('fa-spin');
setCompileError('');

const address = account;
const address = injectiveAddress;
const timestamp = Date.now().toString();
setTimestamp(timestamp);

let realChainId = providerNetwork;
let realChainId = chainId;

const isSrcZipUploadSuccess = await FileUtil.uploadSrcZip({
chainName: CHAIN_NAME.injective,
Expand Down Expand Up @@ -324,7 +287,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
params: {
chainName: CHAIN_NAME.injective,
chainId: realChainId,
account: account,
account: injectiveAddress,
timestamp: timestamp,
},
responseType: 'arraybuffer',
Expand Down Expand Up @@ -412,7 +375,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
fileKey: S3Path.outKey(
CHAIN_NAME.injective,
realChainId,
account,
injectiveAddress,
timestamp,
BUILD_FILE_TYPE.rs,
),
Expand All @@ -430,7 +393,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
params: {
chainName: CHAIN_NAME.injective,
chainId: realChainId,
account: account,
account: injectiveAddress,
timestamp: timestamp,
},
responseType: 'arraybuffer',
Expand Down Expand Up @@ -650,7 +613,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
</div>
<Button
variant="primary"
disabled={account === '' || loading || !compileTarget}
disabled={injectiveAddress === '' || loading || !compileTarget}
onClick={readCode}
className="btn btn-primary btn-block d-block w-100 text-break remixui_disabled mb-1 mt-3"
>
Expand All @@ -676,23 +639,17 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
)}
{wasm && !loading ? (
<StoreCode
providerInstance={providerInstance}
wallet={wallet}
compileTarget={compileTarget}
client={client}
wasm={wasm}
setWasm={setWasm}
checksum={checksum}
txHash={txHash}
setTxHash={setTxHash}
codeID={codeID}
setCodeID={setCodeID}
schemaInit={schemaInit}
schemaExec={schemaExec}
schemaQuery={schemaQuery}
account={account}
timestamp={timestamp}
providerNetwork={providerNetwork}
/>
) : (
<>
Expand Down
109 changes: 58 additions & 51 deletions src/components/injective/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,74 @@ import { Project } from './Project';
import { ListGroup } from 'react-bootstrap';

import Keplr from '../../assets/Keplr-Big.svg';
import MetaMask from '../../assets/MetaMask.png';
import WalletContextProvider, { useWalletStore } from './WalletContextProvider';
import MetaMaskConnect from './MetaMaskConnect';

interface InterfaceProps {
client: any;
}

export const Connect: React.FunctionComponent<InterfaceProps> = ({ client }) => {
const [dapp, setDapp] = useState<any>();
const [keplr, setKeplr] = useState<any>();
const [wallet, setWallet] = useState('');
const [account, setAccount] = useState('');
const [walletRpcProvider, setWalletRpcProvider] = useState<any>();
const [activeWallet, setActiveWallet] = useState('');
const [active, setActive] = useState(false);
const [providerNetwork, setProviderNetwork] = useState<string>('injective-888');
return (
<div>
<ListGroup>
<ListGroup.Item
as="li"
action
active={activeWallet === 'Keplr'}
onClick={() => {
try {
setActiveWallet('Keplr');
setActive(true);
} catch (error) {
console.error('Keplr connection error:', error);
alert('Error, Check your Keplr Wallet');
}
}}
>
<img src={Keplr} style={{ width: '25px', marginRight: '10px' }} alt="Keplr logo" />
<b>Connect to Keplr</b>
</ListGroup.Item>
</ListGroup>
<hr />
<WalletContextProvider>
<div>
{activeWallet === 'Keplr' ? (
<>
<KeplrConnect
active={active}
account={account}
setAccount={setAccount}
walletRpcProvider={walletRpcProvider}
setWalletRpcProvider={setWalletRpcProvider}
setKeplr={setKeplr}
client={client}
setActive={setActive}
setProviderNetwork={setProviderNetwork}
/>
<Project
providerInstance={keplr}
wallet={'Keplr'}
account={account}
client={client}
providerNetwork={providerNetwork}
/>
</>
) : (
false
)}
<ListGroup>
<ListGroup.Item
as="li"
action
active={activeWallet === 'Keplr'}
onClick={() => {
try {
setActiveWallet('Keplr');
setActive(true);
} catch (error) {
console.error('Keplr connection error:', error);
alert('Error, Check your Keplr Wallet');
}
}}
>
<img src={Keplr} style={{ width: '25px', marginRight: '10px' }} alt="Keplr logo" />
<b>Connect to Keplr</b>
</ListGroup.Item>
{/* <ListGroup.Item
as="li"
action
active={activeWallet === 'MetaMask'}
onClick={() => {
try {
setActiveWallet('MetaMask');
setActive(true);
} catch (error) {
console.error('MetaMask connection error:', error);
alert('Error, Check your MetaMask Wallet');
}
}}
>
<img src={MetaMask} style={{ width: '25px', marginRight: '10px' }} alt="Keplr logo" />
<b>Connect to MetaMask</b>
</ListGroup.Item> */}
</ListGroup>
<hr />
<div>
{activeWallet === 'Keplr' ? (
<>
<KeplrConnect />
<Project client={client} />
</>
) : activeWallet === 'MetaMask' ? (
<>
<MetaMaskConnect />
<Project client={client} />
</>
) : (
false
)}
</div>
</div>
</div>
</WalletContextProvider>
);
};
Loading

0 comments on commit 2bffe09

Please sign in to comment.