Skip to content

Commit

Permalink
add mainnet contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Oct 7, 2024
1 parent 67f4e0d commit 200c1b7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 104 deletions.
68 changes: 7 additions & 61 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions front/src/const/assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Asset } from '@massalabs/react-ui-kit/src/lib/token/models/AssetModel';

// buildnet
export const supportedTokens: Asset[] = [
{
name: 'tDAI.s',
Expand Down Expand Up @@ -30,6 +31,28 @@ export const supportedTokens: Asset[] = [
},
];

// mainnet
// export const supportedTokens: Asset[] = [
// {
// name: 'DAI.e',
// address: 'AS1ZGF1upwp9kPRvDKLxFAKRebgg7b3RWDnhgV7VvdZkZsUL7Nuv',
// symbol: 'DAI.e',
// decimals: 18,
// balance: 0n,
// allowance: 0n,
// chainId: 0,
// },
// {
// name: 'Wrapped MASSA',
// address: 'AS12U4TZfNK7qoLyEERBBRDMu8nm5MKoRzPXDXans4v9wdATZedz9',
// symbol: 'WMAS',
// decimals: 9,
// balance: 0n,
// allowance: 0n,
// chainId: 0,
// },
// ];

export const MasToken = {
name: 'MAS',
address: '',
Expand Down
16 changes: 0 additions & 16 deletions front/src/const/config.ts

This file was deleted.

5 changes: 4 additions & 1 deletion front/src/const/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const schedulerAddress =
'AS12JgXCCSobErQuKfetLmZa1oJFwNHLfRed2uCVf9nuFWMPKx4t';
// buildnet
'AS1FmYN5nqeUzNycSZFBYdcno4tFCgNfPfMwhPCxCZLgFJy4YMUp';
//mainnet
//'AS1WHog6myEJg1qydeopye6VSaC4yKKhZEjPhEGAgWYMPNLsKfLf';
6 changes: 3 additions & 3 deletions front/src/store/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface SchedulerStoreState {
value: bigint | string | Asset | boolean,
) => void;

getBySpender: (spender: string) => Promise<Schedule[] | void>;
getBySpender: (spender: string) => Promise<Schedule[]>;
getByRecipient: (recipient: string) => Promise<void>;
eventPollerStop: () => void;
setEventPollerStop: (stop: () => void) => void;
Expand Down Expand Up @@ -72,11 +72,11 @@ export const useSchedulerStore = create<SchedulerStoreState>((set, get) => ({
scheduleInfo: { ...state.scheduleInfo, [key]: value },
})),

getBySpender: async (spender: string) => {
getBySpender: async (spender: string): Promise<Schedule[]> => {
const { connectedAccount } = useAccountStore.getState();
if (!connectedAccount) {
console.error('You must be connected to an account');
return;
return [];
}

const res = await connectedAccount.readSC({
Expand Down
44 changes: 22 additions & 22 deletions front/src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { formatAmount, toast, useAccountStore } from '@massalabs/react-ui-kit';
import { useTokenStore } from './token';
import { useSchedulerStore } from './scheduler';
import { config } from '@/const/config';
import { CHAIN_ID, EventPoller, Provider } from '@massalabs/massa-web3';

const chainId = CHAIN_ID.Buildnet.toString();
import { EventPoller, Provider } from '@massalabs/massa-web3';
import { schedulerAddress } from '../const/contracts';
import { Schedule } from '../serializable/Schedule';

export async function initApp() {
const { connectedAccount } = useAccountStore.getState();
Expand All @@ -25,7 +24,7 @@ export const initSchedules = async (connectedAccount: Provider) => {
useSchedulerStore
.getState()
// Todo fix chain id never initialized in ui-kit
.setSchedulerAddress(config[chainId].SchedulerContract);
.setSchedulerAddress(schedulerAddress);
useSchedulerStore.getState().getBySpender(connectedAccount.address);
};

Expand All @@ -50,26 +49,27 @@ export const initPollEvent = async (connectedAccount: Provider) => {
smartContractAddress: schedulerAddress,
start: lastSlot,
},
async (data) => {
for (const event of data) {
const match = event.data.match(/Transfer:([^]+)/);
if (match) {
const schedules = await getBySpender(connectedAccount.address);
if (schedules) {
const info = event.data.split(',');
const id = info[0].split(':')[1];
const schedule = schedules.find((s) => s.id === BigInt(id));
if (schedule) {
toast.success(
`Transfer: ${schedule.recipient} received ${
formatAmount(schedule.amount).preview
} MAS`,
);
refreshBalances();
(data) => {
getBySpender(connectedAccount.address).then((schedules: Schedule[]) => {
if (schedules?.length) {
for (const event of data) {
const match = event.data?.match(/Transfer:([^]+)/);
if (match) {
const info = event.data.split(',');
const id = info[0].split(':')[1];
const schedule = schedules.find((s) => s.id === BigInt(id));
if (schedule) {
toast.success(
`Transfer: ${schedule.recipient} received ${
formatAmount(schedule.amount).preview
} MAS`,
);
refreshBalances();
}
}
}
}
}
});
},
);

Expand Down
1 change: 0 additions & 1 deletion smart-contract/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
PRIVATE_KEY=
RECIPIENT_ADDRESS=

0 comments on commit 200c1b7

Please sign in to comment.