Skip to content
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
1 change: 1 addition & 0 deletions api/functions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/cla
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/claim_multiple_workflow')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/error')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/timeout')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/reward')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/transfer_asset_out')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/transfer_asset_in')));
walletHandlers.attach(Object.assign({ app: router }, require('../routes/auth/transfer_token_asset_in')));
Expand Down
49 changes: 49 additions & 0 deletions api/routes/auth/reward.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable no-console */
const SDK = require('@ocap/sdk');
const { fromAddress } = require('@ocap/wallet');
const { fromTokenToUnit } = require('@ocap/util');

const { wallet } = require('../../libs/auth');

const txCreators = {
TransferV2Tx: async ({ amount }) => ({
type: 'TransferV2Tx',
data: {
itx: {
to: wallet.address, // 设置为收款人的地址,比如发帖人的 did
value: fromTokenToUnit(amount, 18),
},
},
description: 'Transfer some token to application using delegation',
}),
};

module.exports = {
action: 'reward',

claims: {
signature: async ({ userPk, userDid, extraParams: { locale, amount } }) => {
const claim = await txCreators.TransferV2Tx({ userPk, userDid, locale, amount });
console.log(claim);
return claim;
},
},

onAuth: async ({ userDid, claims }) => {
const claim = claims.find(x => x.type === 'signature');

const tx = SDK.decodeTx(claim.origin);
logger.info('reward.auth.tx', tx);

tx.signature = claim.sig;
if (claim.delegator) {
tx.delegator = claim.delegator;
tx.from = claim.from;
}
const hash = await SDK.sendTransferV2Tx({ tx, wallet: fromAddress(userDid) });

// hash 就是交易凭据

return { hash, tx: claim.origin };
},
};
1 change: 0 additions & 1 deletion src/components/auth/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function GeneralAuthButton({ button, action, messages, timeout, e
responsive
action={action}
checkFn={api.get}
socketUrl={api.socketUrl}
onClose={() => setOpen(false)}
checkTimeout={timeout}
extraParams={extraParams}
Expand Down
12 changes: 12 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PlaygroundAction } from '@arcblock/did-playground';

import { UserContext } from '../context/user';
import Layout from '../components/layout';
import AuthButton from '../components/auth/general';

import getWebWalletUrl from '../libs/util';

Expand Down Expand Up @@ -80,6 +81,17 @@ export default function MiniPage() {
title={`Send 0.5 ${token.local.symbol}`}
webWalletUrl={webWalletUrl}
/>
<AuthButton
button="Reward 10 TBA"
action="reward"
extraParams={{ amount: '10' }}
messages={{
title: 'Reward with DID Wallet',
scan: 'Scan QR code to complete the purchase',
confirm: 'Confirm on your DID Wallet',
success: 'The purchase was successful, now you can launch your node',
}}
/>
</div>
</section>
</Main>
Expand Down