Skip to content

Commit

Permalink
Adjust notification format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Tsymbal authored and tsmbl committed May 25, 2022
1 parent e93cbb6 commit b2dd409
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
51 changes: 27 additions & 24 deletions examples/quarry-events-example.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import { QuarryEventSubscription } from '../src/saber-wars-api/quarry-event-api';
import { getOwner, quarrySDK } from '../src/saber-wars-api/quarry-sdk-factory';
import { getTokenInfo } from '../src/saber-wars-api/token-info-api';
import { ClaimEvent, StakeEvent } from '@quarryprotocol/quarry-sdk';
import { toDecimals } from '../src/saber-wars-api/saber-wars-api';

const numberFormat = new Intl.NumberFormat('en-US');

async function main() {
const defaultSubscription = new QuarryEventSubscription(
quarrySDK.programs.Mine,
async (it) => {
const owner = await getOwner(it.data.authority);
switch (it.name) {
case 'StakeEvent': {
const stakeEvent = it as StakeEvent;
const optionalParams = await getTokenInfo(
stakeEvent.data.token.toBase58(),
);
console.log(
`Stake event from ${owner.toBase58()}, ${stakeEvent.data.amount.toNumber()}`,
);
break;
}
case 'ClaimEvent': {
const claimEvent = it as ClaimEvent;
const optionalParams = await getTokenInfo(
claimEvent.data.rewardsToken.toBase58(),
);
console.log(
`Claim event from ${owner.toBase58()}, ${claimEvent.data.amount.toNumber()}`,
);
break;
}
async (evt) => {
const resourceId = await getOwner(evt.data.authority);
if (
resourceId.toBase58() !== 'GNisgcTZZ2WS5PFAEkVUbFso3wNe22cjhmZiEjGcqeHD'
) {
return;
}
if (evt.name === 'StakeEvent') {
console.log(JSON.stringify(evt));
const tokenInfo = await getTokenInfo(evt.data.token);
console.log(JSON.stringify(tokenInfo));
console.log(
`Success! You staked ${numberFormat.format(
toDecimals(evt.data.amount, tokenInfo.decimals),
)} ${tokenInfo.symbol} to ${tokenInfo.name}`,
);
}
if (evt.name === 'ClaimEvent') {
const tokenInfo = await getTokenInfo(evt.data.stakedToken);
console.log(
`Success! You claimed ${numberFormat.format(
toDecimals(evt.data.amount, tokenInfo.decimals),
)} ${tokenInfo.symbol} from ${tokenInfo.name}`,
);
}
return Promise.resolve();
},
Expand Down
6 changes: 3 additions & 3 deletions src/monitor/saber-monitoring-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Time remaining in epoch: ${epochInfo.currentEpochRemainingTime.toFormat(
const tokenInfo = await getTokenInfo(evt.data.token);
quarryEvents.next({
data: {
message: `Confirmed stake of ${this.numberFormat.format(
message: `Success! You staked ${this.numberFormat.format(
toDecimals(evt.data.amount, tokenInfo.decimals),
)} ${tokenInfo.symbol} to ${tokenInfo.name}`,
},
Expand All @@ -124,9 +124,9 @@ Time remaining in epoch: ${epochInfo.currentEpochRemainingTime.toFormat(
const tokenInfo = await getTokenInfo(evt.data.rewardsToken);
quarryEvents.next({
data: {
message: `Confirmed reward claim of ${this.numberFormat.format(
message: `Success! You claimed ${this.numberFormat.format(
toDecimals(evt.data.amount, tokenInfo.decimals),
)} ${tokenInfo.symbol} in ${tokenInfo.name}`,
)} ${tokenInfo.symbol} from ${tokenInfo.name}`,
},
resourceId,
});
Expand Down

0 comments on commit b2dd409

Please sign in to comment.